From bcd5792ca4637198b05aa74f39c0a0f4af3b536c Mon Sep 17 00:00:00 2001 From: Gary Rong Date: Tue, 26 Sep 2023 18:13:41 +0800 Subject: [PATCH] eth, trie: address comments --- eth/downloader/downloader.go | 4 +++- trie/triedb/pathdb/database.go | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go index 180988f521..453a29aa8d 100644 --- a/eth/downloader/downloader.go +++ b/eth/downloader/downloader.go @@ -403,7 +403,9 @@ func (d *Downloader) synchronise(id string, hash common.Hash, td, ttd *big.Int, // subsequent state reads, explicitly disable the trie database and state // syncer is responsible to address and correct any state missing. if d.blockchain.TrieDB().Scheme() == rawdb.PathScheme { - d.blockchain.TrieDB().Deactivate() + if err := d.blockchain.TrieDB().Deactivate(); err != nil { + return err + } } // Snap sync uses the snapshot namespace to store potentially flaky data until // sync completely heals and finishes. Pause snapshot maintenance in the mean- diff --git a/trie/triedb/pathdb/database.go b/trie/triedb/pathdb/database.go index 1dfe084827..720d5fb083 100644 --- a/trie/triedb/pathdb/database.go +++ b/trie/triedb/pathdb/database.go @@ -182,7 +182,9 @@ func New(diskdb ethdb.Database, config *Config) *Database { } // Disable database in case node is still in the initial state sync stage. if rawdb.ReadSnapSyncStatusFlag(diskdb) == rawdb.StateSyncRunning && !db.readOnly { - db.Deactivate() + if err := db.Deactivate(); err != nil { + log.Crit("Failed to disable database", "err", err) // impossible to happen + } } log.Warn("Path-based state scheme is an experimental feature") return db @@ -252,6 +254,7 @@ func (db *Database) Deactivate() error { } // Prevent duplicated disable operation. if db.waitSync { + log.Error("Reject duplicated disable operation") return nil } db.waitSync = true @@ -279,7 +282,7 @@ func (db *Database) Activate(root common.Hash) error { root = types.TrieRootHash(root) _, stored := rawdb.ReadAccountTrieNode(db.diskdb, nil) if stored != root { - return fmt.Errorf("state is mismatched, stored: %x, target: %x", stored, root) + return fmt.Errorf("state root mismatch: stored %x, synced %x", stored, root) } // Drop the stale state journal in persistent database and // reset the persistent state id back to zero.