core/state: address review concerns

This commit is contained in:
Martin Holst Swende 2023-11-28 09:37:42 +01:00
parent 7331a12077
commit 016678e120
No known key found for this signature in database
GPG key ID: 683B438C05A5DDF0

View file

@ -23,7 +23,6 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
@ -57,7 +56,7 @@ type DumpAccount struct {
Code hexutil.Bytes `json:"code,omitempty"` Code hexutil.Bytes `json:"code,omitempty"`
Storage map[common.Hash]string `json:"storage,omitempty"` Storage map[common.Hash]string `json:"storage,omitempty"`
Address *common.Address `json:"address,omitempty"` // Address only present in iterative (line-by-line) mode Address *common.Address `json:"address,omitempty"` // Address only present in iterative (line-by-line) mode
SecureKey hexutil.Bytes `json:"key,omitempty"` // If we don't have address, we can output the key AddressHash hexutil.Bytes `json:"key,omitempty"` // If we don't have address, we can output the key
} }
@ -78,7 +77,7 @@ func (d *Dump) OnRoot(root common.Hash) {
// OnAccount implements DumpCollector interface // OnAccount implements DumpCollector interface
func (d *Dump) OnAccount(addr *common.Address, account DumpAccount) { func (d *Dump) OnAccount(addr *common.Address, account DumpAccount) {
if addr == nil { if addr == nil {
d.Accounts[fmt.Sprintf("pre(%s)", account.SecureKey)] = account d.Accounts[fmt.Sprintf("pre(%s)", account.AddressHash)] = account
} }
if addr != nil { if addr != nil {
d.Accounts[(*addr).String()] = account d.Accounts[(*addr).String()] = account
@ -99,7 +98,7 @@ func (d iterativeDump) OnAccount(addr *common.Address, account DumpAccount) {
CodeHash: account.CodeHash, CodeHash: account.CodeHash,
Code: account.Code, Code: account.Code,
Storage: account.Storage, Storage: account.Storage,
SecureKey: account.SecureKey, AddressHash: account.AddressHash,
Address: addr, Address: addr,
} }
d.Encode(dumpAccount) d.Encode(dumpAccount)
@ -144,15 +143,12 @@ func (s *StateDB) DumpToCollector(c DumpCollector, conf *DumpConfig) (nextKey []
Nonce: data.Nonce, Nonce: data.Nonce,
Root: data.Root[:], Root: data.Root[:],
CodeHash: data.CodeHash, CodeHash: data.CodeHash,
SecureKey: it.Key, AddressHash: it.Key,
} }
address *common.Address address *common.Address
addr common.Address addr common.Address
addrBytes = s.trie.GetKey(it.Key) addrBytes = s.trie.GetKey(it.Key)
) )
if addrBytes == nil { // Preimage not present in memory. Check database.
addrBytes = rawdb.ReadPreimage(s.Database().DiskDB(), common.BytesToHash(it.Key))
}
if addrBytes == nil { if addrBytes == nil {
missingPreimages++ missingPreimages++
if conf.OnlyWithAddresses { if conf.OnlyWithAddresses {