From f223dcd25de4b942c5c32738cb47a132cee5f83c Mon Sep 17 00:00:00 2001 From: Maciej Kulawik Date: Wed, 6 Dec 2023 14:10:05 +0000 Subject: [PATCH 1/2] readd method to open storage trie without having addrHash preimage --- core/state/database.go | 13 +++++++++++++ core/state/pruner/pruner.go | 9 +-------- light/trie.go | 4 ++++ 3 files changed, 18 insertions(+), 8 deletions(-) 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: From 1e2855b24d6555c8cfaf471bd9e2c3d19ab5c32c Mon Sep 17 00:00:00 2001 From: Maciej Kulawik Date: Thu, 14 Dec 2023 23:38:16 +0000 Subject: [PATCH 2/2] fix dumpRawTrieDescendants --- core/state/database.go | 13 ------------- core/state/pruner/pruner.go | 2 +- light/trie.go | 4 ---- 3 files changed, 1 insertion(+), 18 deletions(-) diff --git a/core/state/database.go b/core/state/database.go index 86a32b1459..72fa215730 100644 --- a/core/state/database.go +++ b/core/state/database.go @@ -46,9 +46,6 @@ 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 @@ -191,16 +188,6 @@ 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 5c92dc0c89..1e959bd13d 100644 --- a/core/state/pruner/pruner.go +++ b/core/state/pruner/pruner.go @@ -381,7 +381,7 @@ func dumpRawTrieDescendants(db ethdb.Database, root common.Hash, output *stateBl output.Put(data.CodeHash, nil) } if data.Root != (common.Hash{}) { - storageTr, err := sdb.OpenStorageTrieWithAddrHash(key, common.BytesToHash(accountIt.LeafKey()), data.Root) + storageTr, err := trie.NewStateTrie(trie.StorageTrieID(root, key, data.Root), sdb.TrieDB()) if err != nil { return err } diff --git a/light/trie.go b/light/trie.go index 3820b386b4..4967cc74e5 100644 --- a/light/trie.go +++ b/light/trie.go @@ -59,10 +59,6 @@ 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: