core/state: enable lookup of preimages from disk during dump operation

This commit is contained in:
Martin Holst Swende 2023-11-10 09:37:38 +01:00
parent 7df4ebd5ec
commit bebe04b56b
No known key found for this signature in database
GPG key ID: 683B438C05A5DDF0
2 changed files with 17 additions and 11 deletions

View file

@ -23,6 +23,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"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/log"
"github.com/ethereum/go-ethereum/rlp"
@ -153,25 +154,28 @@ func (s *StateDB) DumpToCollector(c DumpCollector, conf *DumpConfig) (nextKey []
if err := rlp.DecodeBytes(it.Value, &data); err != nil {
panic(err)
}
account := DumpAccount{
Balance: data.Balance.String(),
Nonce: data.Nonce,
Root: data.Root[:],
CodeHash: data.CodeHash,
SecureKey: it.Key,
}
var (
addrBytes = s.trie.GetKey(it.Key)
addr = common.BytesToAddress(addrBytes)
account = DumpAccount{
Balance: data.Balance.String(),
Nonce: data.Nonce,
Root: data.Root[:],
CodeHash: data.CodeHash,
SecureKey: it.Key,
}
address *common.Address
addr common.Address
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 {
// Preimage missing
missingPreimages++
if conf.OnlyWithAddresses {
continue
}
} else {
addr = common.BytesToAddress(addrBytes)
address = &addr
}
obj := newObject(s, addr, &data)

View file

@ -116,7 +116,9 @@ func (t *BlockTest) Run(snapshotter bool, scheme string, tracer vm.EVMLogger, po
// import pre accounts & construct test genesis block & state root
var (
db = rawdb.NewMemoryDatabase()
tconf = &trie.Config{}
tconf = &trie.Config{
Preimages: true,
}
)
if scheme == rawdb.PathScheme {
tconf.PathDB = pathdb.Defaults