diff --git a/core/txindexer.go b/core/txindexer.go index e237d18691..20bb7fbe5c 100644 --- a/core/txindexer.go +++ b/core/txindexer.go @@ -250,6 +250,14 @@ func (indexer *txIndexer) loop(chain *BlockChain) { // report returns the tx indexing progress. func (indexer *txIndexer) report(head uint64) TxIndexProgress { + // Special case if the head is even below the cutoff, + // nothing to index. + if head < indexer.cutoff { + return TxIndexProgress{ + Indexed: 0, + Remaining: 0, + } + } // Compute how many blocks are supposed to be indexed total := indexer.limit if indexer.limit == 0 || total > head { @@ -259,7 +267,7 @@ func (indexer *txIndexer) report(head uint64) TxIndexProgress { if total > length { total = length } - // Compute how many block have been indexed + // Compute how many blocks have been indexed var indexed uint64 tail := rawdb.ReadTxIndexTail(indexer.db) if tail != nil { diff --git a/core/txindexer_test.go b/core/txindexer_test.go index 4a34563f11..7a5688241f 100644 --- a/core/txindexer_test.go +++ b/core/txindexer_test.go @@ -416,6 +416,15 @@ func TestTxIndexerReport(t *testing.T) { expIndexed: 62, expRemaining: 1, }, + { + // head = 128, limit = 64, cutoff = 256 => index: [66, 128] + head: chainHead, + limit: 0, + cutoff: 256, + tail: nil, + expIndexed: 0, + expRemaining: 0, + }, } for _, c := range cases { db, _ := rawdb.NewDatabaseWithFreezer(rawdb.NewMemoryDatabase(), "", "", false)