From f5a7321bef65d71921b2342704ab9ba6d7d0181d Mon Sep 17 00:00:00 2001 From: Guillaume Ballet <3272758+gballet@users.noreply.github.com> Date: Thu, 10 Aug 2023 13:44:28 +0200 Subject: [PATCH] fix: open an empty storage trie after transition --- core/state/database.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/core/state/database.go b/core/state/database.go index df3365dc25..c6ebbd1fba 100644 --- a/core/state/database.go +++ b/core/state/database.go @@ -362,8 +362,23 @@ func (db *cachingDB) openStorageMPTrie(stateRoot common.Hash, address common.Add // OpenStorageTrie opens the storage trie of an account func (db *cachingDB) OpenStorageTrie(stateRoot common.Hash, address common.Address, root common.Hash, self Trie) (Trie, error) { - mpt, err := db.openStorageMPTrie(stateRoot, address, root, nil) - if db.started && err == nil { + if db.ended { + mpt, err := db.openStorageMPTrie(common.Hash{}, address, common.Hash{}, self) + if err != nil { + return nil, err + } + // Return a "storage trie" that is an adapter between the storge MPT + // and the unique verkle tree. + switch self := self.(type) { + case *trie.VerkleTrie: + return trie.NewTransitionTree(mpt.(*trie.StateTrie), self, true), nil + case *trie.TransitionTrie: + return trie.NewTransitionTree(mpt.(*trie.StateTrie), self.Overlay(), true), nil + default: + panic("unexpected trie type") + } + } + if db.started { // Return a "storage trie" that is an adapter between the storge MPT // and the unique verkle tree. switch self := self.(type) { @@ -375,6 +390,7 @@ func (db *cachingDB) OpenStorageTrie(stateRoot common.Hash, address common.Addre panic("unexpected trie type") } } + mpt, err := db.openStorageMPTrie(stateRoot, address, root, nil) return mpt, err }