core/state: avoid empty codehash allocs and needless storage trie opens

This commit is contained in:
Forostovec 2026-01-26 13:09:52 +02:00 committed by GitHub
parent c2595381bf
commit 8aa18640a0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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