From 32873d1c15c4a84ad53c66fbc4d335ade39fa3eb Mon Sep 17 00:00:00 2001 From: ucwong Date: Fri, 6 Feb 2026 21:43:44 +0800 Subject: [PATCH] check pruning tail in HasBody and HasReceipts --- core/rawdb/accessors_chain.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/core/rawdb/accessors_chain.go b/core/rawdb/accessors_chain.go index 125c043139..5c4f3d3f18 100644 --- a/core/rawdb/accessors_chain.go +++ b/core/rawdb/accessors_chain.go @@ -513,7 +513,13 @@ func WriteBodyRLP(db ctxcdb.KeyValueWriter, hash common.Hash, number uint64, rlp // HasBody verifies the existence of a block body corresponding to the hash. func HasBody(db ctxcdb.Reader, hash common.Hash, number uint64) bool { if isCanon(db, number, hash) { - return true + // Block is in ancient store, but bodies can be pruned. + // Check if the block number is above the pruning tail. + tail, _ := db.Tail() + if number >= tail { + return true + } + return false } if has, err := db.Has(blockBodyKey(number, hash)); !has || err != nil { return false @@ -603,7 +609,13 @@ func DeleteTd(db ctxcdb.KeyValueWriter, hash common.Hash, number uint64) { // to a block. func HasReceipts(db ctxcdb.Reader, hash common.Hash, number uint64) bool { if isCanon(db, number, hash) { - return true + // Block is in ancient store, but receipts can be pruned. + // Check if the block number is above the pruning tail. + tail, _ := db.Tail() + if number >= tail { + return true + } + return false } if has, err := db.Has(blockReceiptsKey(number, hash)); !has || err != nil { return false