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"
@ -50,14 +49,14 @@ type DumpCollector interface {
// DumpAccount represents an account in the state. // DumpAccount represents an account in the state.
type DumpAccount struct { type DumpAccount struct {
Balance string `json:"balance"` Balance string `json:"balance"`
Nonce uint64 `json:"nonce"` Nonce uint64 `json:"nonce"`
Root hexutil.Bytes `json:"root"` Root hexutil.Bytes `json:"root"`
CodeHash hexutil.Bytes `json:"codeHash"` CodeHash hexutil.Bytes `json:"codeHash"`
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
@ -93,14 +92,14 @@ type iterativeDump struct {
// OnAccount implements DumpCollector interface // OnAccount implements DumpCollector interface
func (d iterativeDump) OnAccount(addr *common.Address, account DumpAccount) { func (d iterativeDump) OnAccount(addr *common.Address, account DumpAccount) {
dumpAccount := &DumpAccount{ dumpAccount := &DumpAccount{
Balance: account.Balance, Balance: account.Balance,
Nonce: account.Nonce, Nonce: account.Nonce,
Root: account.Root, Root: account.Root,
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)
} }
@ -140,19 +139,16 @@ func (s *StateDB) DumpToCollector(c DumpCollector, conf *DumpConfig) (nextKey []
} }
var ( var (
account = DumpAccount{ account = DumpAccount{
Balance: data.Balance.String(), Balance: data.Balance.String(),
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 {