From b45acadd341573d194ea3653ed495a323ac6affb Mon Sep 17 00:00:00 2001 From: yysung Date: Wed, 15 Oct 2025 11:21:07 +0800 Subject: [PATCH] core: adjust txindexer cutoff for ancient pruning --- core/txindexer.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/core/txindexer.go b/core/txindexer.go index 76fc511de7..e38c5b3822 100644 --- a/core/txindexer.go +++ b/core/txindexer.go @@ -69,6 +69,10 @@ type txIndexer struct { // newTxIndexer initializes the transaction indexer. func newTxIndexer(limit uint64, chain *BlockChain) *txIndexer { cutoff, _ := chain.HistoryPruningCutoff() + // If the database has a higher cutoff (due to ancient pruning), adjust the cutoff accordingly. + if dbTail, err := chain.db.Tail(); err == nil { + cutoff = max(cutoff, dbTail) + } indexer := &txIndexer{ limit: limit, cutoff: cutoff, @@ -315,7 +319,12 @@ func (indexer *txIndexer) report(head uint64, tail *uint64) TxIndexProgress { if indexer.limit == 0 || total > head { total = head + 1 // genesis included } - length := head - indexer.cutoff + 1 // all available chain for indexing + cutoff := indexer.cutoff + // If the database has a higher cutoff (due to ancient pruning), adjust the cutoff accordingly. + if dbTail, err := indexer.db.Tail(); err == nil { + cutoff = max(cutoff, dbTail) + } + length := head - cutoff + 1 // all available chain for indexing if total > length { total = length }