Skip to content

Commit f223dcd

Browse files
committed
readd method to open storage trie without having addrHash preimage
1 parent b1622e6 commit f223dcd

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

core/state/database.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ type Database interface {
4646
// OpenStorageTrie opens the storage trie of an account.
4747
OpenStorageTrie(stateRoot common.Hash, address common.Address, root common.Hash) (Trie, error)
4848

49+
// OpenStorageTrieWithAddrHash opens the storage trie of an account
50+
OpenStorageTrieWithAddrHash(stateRoot common.Hash, addrHash common.Hash, root common.Hash) (Trie, error)
51+
4952
// CopyTrie returns an independent copy of the given trie.
5053
CopyTrie(Trie) Trie
5154

@@ -188,6 +191,16 @@ func (db *cachingDB) OpenStorageTrie(stateRoot common.Hash, address common.Addre
188191
return tr, nil
189192
}
190193

194+
// OpenStorageTrieWithAddrHash opens the storage trie of an account.
195+
// arbitrum: the method is readded to not require address which is not available in pruner dumpRawTrieDescendants
196+
func (db *cachingDB) OpenStorageTrieWithAddrHash(stateRoot common.Hash, addrHash common.Hash, root common.Hash) (Trie, error) {
197+
tr, err := trie.NewStateTrie(trie.StorageTrieID(stateRoot, addrHash, root), db.triedb)
198+
if err != nil {
199+
return nil, err
200+
}
201+
return tr, nil
202+
}
203+
191204
// CopyTrie returns an independent copy of the given trie.
192205
func (db *cachingDB) CopyTrie(t Trie) Trie {
193206
switch t := t.(type) {

core/state/pruner/pruner.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -381,14 +381,7 @@ func dumpRawTrieDescendants(db ethdb.Database, root common.Hash, output *stateBl
381381
output.Put(data.CodeHash, nil)
382382
}
383383
if data.Root != (common.Hash{}) {
384-
// Lookup the preimage of account hash
385-
preimage := tr.GetKey(accountIt.LeafKey())
386-
if preimage == nil {
387-
return errors.New("account address is not available")
388-
}
389-
address := common.BytesToAddress(preimage)
390-
391-
storageTr, err := sdb.OpenStorageTrie(key, address, data.Root)
384+
storageTr, err := sdb.OpenStorageTrieWithAddrHash(key, common.BytesToHash(accountIt.LeafKey()), data.Root)
392385
if err != nil {
393386
return err
394387
}

light/trie.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ func (db *odrDatabase) OpenStorageTrie(stateRoot common.Hash, address common.Add
5959
return &odrTrie{db: db, id: StorageTrieID(db.id, address, root)}, nil
6060
}
6161

62+
func (db *odrDatabase) OpenStorageTrieWithAddrHash(stateRoot common.Hash, addrHash common.Hash, root common.Hash) (state.Trie, error) {
63+
return nil, errors.New("OpenStorageTrieWithAddrHash is not implemented for odrDatabase")
64+
}
65+
6266
func (db *odrDatabase) CopyTrie(t state.Trie) state.Trie {
6367
switch t := t.(type) {
6468
case *odrTrie:

0 commit comments

Comments
 (0)