Skip to content

Commit

Permalink
readd method to open storage trie without having addrHash preimage
Browse files Browse the repository at this point in the history
  • Loading branch information
magicxyyz committed Dec 6, 2023
1 parent b1622e6 commit f223dcd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
13 changes: 13 additions & 0 deletions core/state/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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) {
Expand Down
9 changes: 1 addition & 8 deletions core/state/pruner/pruner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 4 additions & 0 deletions light/trie.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit f223dcd

Please sign in to comment.