From 3bef2944a02c56ec812646af883792240fb68f9c Mon Sep 17 00:00:00 2001 From: Gary Rong Date: Tue, 13 May 2025 15:23:30 +0800 Subject: [PATCH] triedb/pathdb: reject state iteration if pathdb is disabled --- triedb/pathdb/database.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/triedb/pathdb/database.go b/triedb/pathdb/database.go index 83df04e264..c206460315 100644 --- a/triedb/pathdb/database.go +++ b/triedb/pathdb/database.go @@ -675,6 +675,12 @@ func (db *Database) waitGeneration() { // AccountIterator creates a new account iterator for the specified root hash and // seeks to a starting account hash. func (db *Database) AccountIterator(root common.Hash, seek common.Hash) (AccountIterator, error) { + db.lock.RLock() + wait := db.waitSync + db.lock.RUnlock() + if wait { + return nil, errDatabaseWaitSync + } if gen := db.tree.bottom().generator; gen != nil && !gen.completed() { return nil, errNotConstructed } @@ -684,6 +690,12 @@ func (db *Database) AccountIterator(root common.Hash, seek common.Hash) (Account // StorageIterator creates a new storage iterator for the specified root hash and // account. The iterator will be moved to the specific start position. func (db *Database) StorageIterator(root common.Hash, account common.Hash, seek common.Hash) (StorageIterator, error) { + db.lock.RLock() + wait := db.waitSync + db.lock.RUnlock() + if wait { + return nil, errDatabaseWaitSync + } if gen := db.tree.bottom().generator; gen != nil && !gen.completed() { return nil, errNotConstructed }