diff --git a/core/state/database.go b/core/state/database.go index 72fa215730..86a32b1459 100644 --- a/core/state/database.go +++ b/core/state/database.go @@ -46,6 +46,9 @@ type Database interface { // OpenStorageTrie opens the storage trie of an account. OpenStorageTrie(stateRoot common.Hash, address common.Address, root common.Hash) (Trie, error) + // OpenStorageTrieWithAddrHash opens the storage trie of an account + OpenStorageTrieWithAddrHash(stateRoot common.Hash, addrHash common.Hash, root common.Hash) (Trie, error) + // CopyTrie returns an independent copy of the given trie. CopyTrie(Trie) Trie @@ -188,6 +191,16 @@ func (db *cachingDB) OpenStorageTrie(stateRoot common.Hash, address common.Addre return tr, nil } +// OpenStorageTrieWithAddrHash opens the storage trie of an account. +// arbitrum: the method is readded to not require address which is not available in pruner dumpRawTrieDescendants +func (db *cachingDB) OpenStorageTrieWithAddrHash(stateRoot common.Hash, addrHash common.Hash, root common.Hash) (Trie, error) { + tr, err := trie.NewStateTrie(trie.StorageTrieID(stateRoot, addrHash, root), db.triedb) + if err != nil { + return nil, err + } + return tr, nil +} + // CopyTrie returns an independent copy of the given trie. func (db *cachingDB) CopyTrie(t Trie) Trie { switch t := t.(type) { diff --git a/core/state/pruner/pruner.go b/core/state/pruner/pruner.go index 0845c0ec50..5c92dc0c89 100644 --- a/core/state/pruner/pruner.go +++ b/core/state/pruner/pruner.go @@ -381,14 +381,7 @@ func dumpRawTrieDescendants(db ethdb.Database, root common.Hash, output *stateBl output.Put(data.CodeHash, nil) } if data.Root != (common.Hash{}) { - // Lookup the preimage of account hash - preimage := tr.GetKey(accountIt.LeafKey()) - if preimage == nil { - return errors.New("account address is not available") - } - address := common.BytesToAddress(preimage) - - storageTr, err := sdb.OpenStorageTrie(key, address, data.Root) + storageTr, err := sdb.OpenStorageTrieWithAddrHash(key, common.BytesToHash(accountIt.LeafKey()), data.Root) if err != nil { return err } diff --git a/light/trie.go b/light/trie.go index 4967cc74e5..3820b386b4 100644 --- a/light/trie.go +++ b/light/trie.go @@ -59,6 +59,10 @@ func (db *odrDatabase) OpenStorageTrie(stateRoot common.Hash, address common.Add return &odrTrie{db: db, id: StorageTrieID(db.id, address, root)}, nil } +func (db *odrDatabase) OpenStorageTrieWithAddrHash(stateRoot common.Hash, addrHash common.Hash, root common.Hash) (state.Trie, error) { + return nil, errors.New("OpenStorageTrieWithAddrHash is not implemented for odrDatabase") +} + func (db *odrDatabase) CopyTrie(t state.Trie) state.Trie { switch t := t.(type) { case *odrTrie: