Skip to content

Commit 8a00e6d

Browse files
committed
core/rawdb: fix the transaction indexer
1 parent 498458b commit 8a00e6d

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

core/rawdb/chain_iterator.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,13 @@ func indexTransactions(db ethdb.Database, from uint64, to uint64, interrupt chan
243243
}
244244
}
245245
}
246-
// If there exists uncommitted data, flush them.
247-
if batch.ValueSize() > 0 {
248-
WriteTxIndexTail(batch, lastNum) // Also write the tail there
249-
if err := batch.Write(); err != nil {
250-
log.Crit("Failed writing batch to db", "error", err)
251-
return
252-
}
246+
// Flush the new indexing tail and the last committed data. It can also happen
247+
// that the last batch is empty because nothing to index, but the tail has to
248+
// be flushed anyway.
249+
WriteTxIndexTail(batch, lastNum)
250+
if err := batch.Write(); err != nil {
251+
log.Crit("Failed writing batch to db", "error", err)
252+
return
253253
}
254254
select {
255255
case <-interrupt:
@@ -334,13 +334,13 @@ func unindexTransactions(db ethdb.Database, from uint64, to uint64, interrupt ch
334334
}
335335
}
336336
}
337-
// Commit the last batch if there exists uncommitted data
338-
if batch.ValueSize() > 0 {
339-
WriteTxIndexTail(batch, nextNum)
340-
if err := batch.Write(); err != nil {
341-
log.Crit("Failed writing batch to db", "error", err)
342-
return
343-
}
337+
// Flush the new indexing tail and the last committed data. It can also happen
338+
// that the last batch is empty because nothing to unindex, but the tail has to
339+
// be flushed anyway.
340+
WriteTxIndexTail(batch, nextNum)
341+
if err := batch.Write(); err != nil {
342+
log.Crit("Failed writing batch to db", "error", err)
343+
return
344344
}
345345
select {
346346
case <-interrupt:

0 commit comments

Comments
 (0)