Skip to content

Commit

Permalink
fix: recover node buffer list trie nodes for graceful kill
Browse files Browse the repository at this point in the history
  • Loading branch information
VM committed Nov 16, 2024
1 parent 1f47c88 commit ed46c9a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 19 deletions.
6 changes: 5 additions & 1 deletion core/blockchain_snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ func (snaptest *wipeCrashSnapshotTest) test(t *testing.T) {
SnapshotLimit: 0,
StateScheme: snaptest.scheme,
}
config.UseBase = true
newchain, err := NewBlockChain(snaptest.db, config, snaptest.gspec, nil, snaptest.engine, vm.Config{}, nil, nil)
if err != nil {
t.Fatalf("Failed to recreate chain: %v", err)
Expand All @@ -412,6 +413,7 @@ func (snaptest *wipeCrashSnapshotTest) test(t *testing.T) {
SnapshotWait: false, // Don't wait rebuild
StateScheme: snaptest.scheme,
}
config.UseBase = true
tmp, err := NewBlockChain(snaptest.db, config, snaptest.gspec, nil, snaptest.engine, vm.Config{}, nil, nil)
if err != nil {
t.Fatalf("Failed to recreate chain: %v", err)
Expand All @@ -421,7 +423,9 @@ func (snaptest *wipeCrashSnapshotTest) test(t *testing.T) {
tmp.triedb.Close()
tmp.stopWithoutSaving()

newchain, err = NewBlockChain(snaptest.db, DefaultCacheConfigWithScheme(snaptest.scheme), snaptest.gspec, nil, snaptest.engine, vm.Config{}, nil, nil)
cacheConfig := DefaultCacheConfigWithScheme(snaptest.scheme)
cacheConfig.UseBase = true
newchain, err = NewBlockChain(snaptest.db, cacheConfig, snaptest.gspec, nil, snaptest.engine, vm.Config{}, nil, nil)
if err != nil {
t.Fatalf("Failed to recreate chain: %v", err)
}
Expand Down
1 change: 0 additions & 1 deletion triedb/pathdb/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ func New(diskdb ethdb.Database, config *Config) *Database {
diskdb: diskdb,
useBase: config.UseBase,
}
fmt.Println("useBase", db.useBase)

// Open the freezer for state history if the passed database contains an
// ancient store. Otherwise, all the relevant functionalities are disabled.
Expand Down
7 changes: 0 additions & 7 deletions triedb/pathdb/journal.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,6 @@ func (db *Database) loadLayers() layer {
if err == nil {
return head
}
fmt.Println("load layers error: ", err)
log.Error("print load journal error", "error", err)
// journal is not matched(or missing) with the persistent state, discard
// it. Display log for discarding journal, but try to avoid showing
// useless information when the db is created from scratch.
Expand All @@ -270,10 +268,8 @@ func (db *Database) loadLayers() layer {
stateID = rawdb.ReadPersistentStateID(db.diskdb)
)

fmt.Println("use base1111: ", db.useBase)
if (errors.Is(err, errMissJournal) || errors.Is(err, errUnmatchedJournal)) && db.fastRecovery &&
db.config.TrieNodeBufferType == NodeBufferList && !db.useBase {
fmt.Println("3j3erj321")
start := time.Now()
log.Info("Recover node buffer list from ancient db")

Expand All @@ -288,7 +284,6 @@ func (db *Database) loadLayers() layer {
}
}
if nb == nil || err != nil {
fmt.Println("r23k9321k9")
// Return single layer with persistent state.
nb, err = NewTrieNodeBuffer(db.diskdb, db.config.TrieNodeBufferType, db.bufferSize, nil, 0,
db.config.ProposeBlockInterval, db.config.NotifyKeep, nil, false, db.useBase)
Expand Down Expand Up @@ -373,9 +368,7 @@ func (db *Database) loadDiskLayer(r *rlp.Stream, journalTypeForReader JournalTyp
return nil, err
}

fmt.Println("111")
if db.config.TrieNodeBufferType == NodeBufferList && !db.useBase {
fmt.Println("222")
recoveredRoot, recoveredStateID, _ := nb.getLatestStatus()
if recoveredRoot != root && recoveredStateID != id {
log.Error("unequal state root and state id")
Expand Down
13 changes: 3 additions & 10 deletions triedb/pathdb/nodebufferlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,13 @@ func newNodeBufferList(
dlInMd = wpBlocks
}

if nodes == nil {
nodes = make(map[common.Hash]map[string]*trienode.Node)
}

nf := &nodebufferlist{
db: db,
wpBlocks: wpBlocks,
rsevMdNum: rsevMdNum,
dlInMd: dlInMd,
limit: limit,
base: newMultiDifflayer(limit, 0, common.Hash{}, nodes, 0),
base: newMultiDifflayer(limit, 0, common.Hash{}, make(map[common.Hash]map[string]*trienode.Node), 0),
persistID: rawdb.ReadPersistentStateID(db),
stopCh: make(chan struct{}),
waitStopCh: make(chan struct{}),
Expand All @@ -129,7 +125,6 @@ func newNodeBufferList(

fmt.Println("useBase, fastRecovery", useBase, fastRecovery)
if !useBase && fastRecovery {
fmt.Println("ndnuenu")
if freezer == nil {
log.Crit("Use unopened freezer db to recover node buffer list")
}
Expand All @@ -139,7 +134,6 @@ func newNodeBufferList(
return nil, err
}
} else {
fmt.Println("ndiednie")
ele := newMultiDifflayer(limit, 0, common.Hash{}, make(map[common.Hash]map[string]*trienode.Node), 0)
nf.head = ele
nf.tail = ele
Expand Down Expand Up @@ -167,7 +161,6 @@ func (nf *nodebufferlist) recoverNodeBufferList(freezer *rawdb.ResettableFreezer
log.Error("Failed to get freezer tail", "error", err)
return err
}
fmt.Println()
log.Info("Ancient db meta info", "persistent_state_id", nf.persistID, "head_state_id", head,
"tail_state_id", tail, "waiting_recover_num", head-nf.persistID)

Expand Down Expand Up @@ -844,8 +837,8 @@ func (nf *nodebufferlist) proposedBlockReader(blockRoot common.Hash) (layer, err
func (nf *nodebufferlist) report() {
context := []interface{}{
"number", nf.block, "count", nf.count, "layers", nf.layers,
"stateid", nf.stateId, "persist", nf.persistID, "size", common.StorageSize(nf.size),
"basesize", common.StorageSize(nf.base.size), "baselayers", nf.base.layers,
"state_id", nf.stateId, "persist", nf.persistID, "size", common.StorageSize(nf.size),
"base_size", common.StorageSize(nf.base.size), "base_layers", nf.base.layers,
}
log.Info("node buffer list info", context...)
}
Expand Down

0 comments on commit ed46c9a

Please sign in to comment.