mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 14:46:42 +00:00
Merge pull request #1411 from maticnetwork/manav/indexer-graceful-shutdown
core/rawdb: prevent ungraceful shutdown in tx indexing
This commit is contained in:
parent
a15366359e
commit
3a3e619d4c
1 changed files with 16 additions and 4 deletions
|
|
@ -92,6 +92,16 @@ func InitDatabaseFromFreezer(db ethdb.Database) {
|
||||||
log.Info("Initialized database from freezer", "blocks", frozen, "elapsed", common.PrettyDuration(time.Since(start)))
|
log.Info("Initialized database from freezer", "blocks", frozen, "elapsed", common.PrettyDuration(time.Since(start)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// adjustRangeForBor updates the range to index transactions if the ancient data was pruned before. This is
|
||||||
|
// to avoid indexing/unindexing data which is already pruned (i.e. before the `offset` block number).
|
||||||
|
func adjustRangeForBor(db ethdb.Database, from uint64) uint64 {
|
||||||
|
if offset := db.AncientOffSet(); offset > from {
|
||||||
|
from = offset
|
||||||
|
}
|
||||||
|
|
||||||
|
return from
|
||||||
|
}
|
||||||
|
|
||||||
type blockTxHashes struct {
|
type blockTxHashes struct {
|
||||||
number uint64
|
number uint64
|
||||||
hashes []common.Hash
|
hashes []common.Hash
|
||||||
|
|
@ -108,10 +118,6 @@ func iterateTransactions(db ethdb.Database, from uint64, to uint64, reverse bool
|
||||||
rlp rlp.RawValue
|
rlp rlp.RawValue
|
||||||
}
|
}
|
||||||
|
|
||||||
if offset := db.AncientOffSet(); offset > from {
|
|
||||||
from = offset
|
|
||||||
}
|
|
||||||
|
|
||||||
if to <= from {
|
if to <= from {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -206,6 +212,9 @@ func iterateTransactions(db ethdb.Database, from uint64, to uint64, reverse bool
|
||||||
// There is a passed channel, the whole procedure will be interrupted if any
|
// There is a passed channel, the whole procedure will be interrupted if any
|
||||||
// signal received.
|
// signal received.
|
||||||
func indexTransactions(db ethdb.Database, from uint64, to uint64, interrupt chan struct{}, hook func(uint64) bool, report bool) {
|
func indexTransactions(db ethdb.Database, from uint64, to uint64, interrupt chan struct{}, hook func(uint64) bool, report bool) {
|
||||||
|
// Adjust range if needed
|
||||||
|
from = adjustRangeForBor(db, from)
|
||||||
|
|
||||||
// short circuit for invalid range
|
// short circuit for invalid range
|
||||||
if from >= to {
|
if from >= to {
|
||||||
return
|
return
|
||||||
|
|
@ -309,6 +318,9 @@ func indexTransactionsForTesting(db ethdb.Database, from uint64, to uint64, inte
|
||||||
// There is a passed channel, the whole procedure will be interrupted if any
|
// There is a passed channel, the whole procedure will be interrupted if any
|
||||||
// signal received.
|
// signal received.
|
||||||
func unindexTransactions(db ethdb.Database, from uint64, to uint64, interrupt chan struct{}, hook func(uint64) bool, report bool) {
|
func unindexTransactions(db ethdb.Database, from uint64, to uint64, interrupt chan struct{}, hook func(uint64) bool, report bool) {
|
||||||
|
// Adjust range if needed
|
||||||
|
from = adjustRangeForBor(db, from)
|
||||||
|
|
||||||
// short circuit for invalid range
|
// short circuit for invalid range
|
||||||
if from >= to {
|
if from >= to {
|
||||||
return
|
return
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue