mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 15:16:43 +00:00
core: handle corner case in report
This commit is contained in:
parent
54244fe263
commit
e9e5ab1fd8
2 changed files with 18 additions and 1 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue