Skip to content

Commit

Permalink
test: fix pathdb unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
VM committed Sep 10, 2024
1 parent eae46f7 commit 94a0c19
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions triedb/pathdb/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ type Database struct {
readOnly bool // Flag if database is opened in read only mode
waitSync bool // Flag if database is deactivated due to initial state sync
fastRecovery bool // Flag if recover nodebufferlist
first bool // Flag if recover nodebufferlist
isGenesis bool // Flag if in genesis state
bufferSize int // Memory allowance (in bytes) for caching dirty nodes
config *Config // Configuration for database
diskdb ethdb.Database // Persistent storage for matured trie nodes
Expand Down Expand Up @@ -183,7 +183,7 @@ func New(diskdb ethdb.Database, config *Config) *Database {
// ancient store. Otherwise, all the relevant functionalities are disabled.
if ancient, err := diskdb.AncientDatadir(); err == nil && ancient != "" && !db.readOnly {
db.fastRecovery = checkAncientAndNodeBuffer(ancient, config.TrieNodeBufferType)
db.first = checkFirst(ancient)
db.isGenesis = checkGenesis(ancient)
freezer, err := rawdb.NewStateFreezer(ancient, false, db.fastRecovery)
if err != nil {
log.Crit("Failed to open state history freezer", "err", err)
Expand Down
12 changes: 6 additions & 6 deletions triedb/pathdb/journal.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,15 +269,15 @@ func (db *Database) loadLayers() layer {
)

if (errors.Is(err, errMissJournal) || errors.Is(err, errUnmatchedJournal)) && db.fastRecovery &&
db.config.TrieNodeBufferType == NodeBufferList && !db.first {
db.config.TrieNodeBufferType == NodeBufferList && !db.isGenesis {
start := time.Now()
if db.freezer == nil {
log.Crit("Use unopened freezer db to recover node buffer list")
}
log.Info("Recover node buffer list from ancient db")

nb, err = NewTrieNodeBuffer(db.diskdb, db.config.TrieNodeBufferType, db.bufferSize, nil, 0,
db.config.ProposeBlockInterval, db.config.NotifyKeep, db.freezer, db.fastRecovery, db.first)
db.config.ProposeBlockInterval, db.config.NotifyKeep, db.freezer, db.fastRecovery, db.isGenesis)
if err != nil {
log.Error("Failed to new trie node buffer for recovery", "error", err)
} else {
Expand All @@ -289,7 +289,7 @@ func (db *Database) loadLayers() layer {
if nb == nil || err != nil {
// 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.first)
db.config.ProposeBlockInterval, db.config.NotifyKeep, nil, false, db.isGenesis)
if err != nil {
log.Crit("Failed to new trie node buffer", "error", err)
return nil
Expand Down Expand Up @@ -676,8 +676,8 @@ func flattenTrieNodes(jn []journalNodes) map[common.Hash]map[string]*trienode.No
}

func checkAncientAndNodeBuffer(ancient string, nodeBufferType NodeBufferType) bool {
if !common.FileExist(filepath.Join(ancient, rawdb.StateFreezerName)) {
return true
if ok := checkGenesis(ancient); ok {
return ok
}

if rawdb.DetectTrieNodesFile(ancient) {
Expand All @@ -694,7 +694,7 @@ func checkAncientAndNodeBuffer(ancient string, nodeBufferType NodeBufferType) bo
return false
}

func checkFirst(ancient string) bool {
func checkGenesis(ancient string) bool {
if !common.FileExist(filepath.Join(ancient, rawdb.StateFreezerName)) {
return true
}
Expand Down
6 changes: 3 additions & 3 deletions triedb/pathdb/nodebufferlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ func (nf *nodebufferlist) flush(db ethdb.KeyValueStore, clean *fastcache.Cache,
if !nf.isGenesis {
nf.traverseReverse(commitFunc)
} else {
nf.forceFlush()
nf.flushGenesis()
}

persistID := nf.persistID + nf.base.layers
Expand Down Expand Up @@ -662,8 +662,8 @@ func (nf *nodebufferlist) traverseReverse(cb func(*multiDifflayer) bool) {
return
}

// forceFlush is used for init genesis
func (nf *nodebufferlist) forceFlush() {
// flushGenesis is used for flush genesis trie node
func (nf *nodebufferlist) flushGenesis() {
commitFunc := func(buffer *multiDifflayer) bool {
err := nf.base.commit(buffer.root, buffer.id, buffer.block, buffer.layers, buffer.nodes)
if err != nil {
Expand Down

0 comments on commit 94a0c19

Please sign in to comment.