mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-20 11:46:44 +00:00
core/state: avoid empty codehash allocs and needless storage trie opens
This commit is contained in:
parent
c2595381bf
commit
8aa18640a0
1 changed files with 16 additions and 13 deletions
|
|
@ -131,26 +131,29 @@ func (it *nodeIterator) step() error {
|
||||||
address := common.BytesToAddress(preimage)
|
address := common.BytesToAddress(preimage)
|
||||||
|
|
||||||
// Traverse the storage slots belong to the account
|
// Traverse the storage slots belong to the account
|
||||||
dataTrie, err := it.state.db.OpenStorageTrie(it.state.originalRoot, address, account.Root, it.tr)
|
if it.state.db.TrieDB().IsVerkle() || account.Root != types.EmptyRootHash {
|
||||||
if err != nil {
|
dataTrie, err := it.state.db.OpenStorageTrie(it.state.originalRoot, address, account.Root, it.tr)
|
||||||
return err
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
it.dataIt, err = dataTrie.NodeIterator(nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !it.dataIt.Next(true) {
|
||||||
|
it.dataIt = nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
it.dataIt, err = dataTrie.NodeIterator(nil)
|
if !bytes.Equal(account.CodeHash, types.EmptyCodeHash[:]) {
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if !it.dataIt.Next(true) {
|
|
||||||
it.dataIt = nil
|
|
||||||
}
|
|
||||||
if !bytes.Equal(account.CodeHash, types.EmptyCodeHash.Bytes()) {
|
|
||||||
it.codeHash = common.BytesToHash(account.CodeHash)
|
it.codeHash = common.BytesToHash(account.CodeHash)
|
||||||
it.code, err = it.state.reader.Code(address, common.BytesToHash(account.CodeHash))
|
code, err := it.state.reader.Code(address, it.codeHash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("code %x: %v", account.CodeHash, err)
|
return fmt.Errorf("code %x: %v", account.CodeHash, err)
|
||||||
}
|
}
|
||||||
if len(it.code) == 0 {
|
if len(code) == 0 {
|
||||||
return fmt.Errorf("code is not found: %x", account.CodeHash)
|
return fmt.Errorf("code is not found: %x", account.CodeHash)
|
||||||
}
|
}
|
||||||
|
it.code = code
|
||||||
}
|
}
|
||||||
it.accountHash = it.stateIt.Parent()
|
it.accountHash = it.stateIt.Parent()
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue