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"
"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"
@ -153,25 +154,28 @@ func (s *StateDB) DumpToCollector(c DumpCollector, conf *DumpConfig) (nextKey []
if err := rlp.DecodeBytes(it.Value, &data); err != nil { if err := rlp.DecodeBytes(it.Value, &data); err != nil {
panic(err) panic(err)
} }
account := DumpAccount{ var (
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, SecureKey: it.Key,
} }
var (
addrBytes = s.trie.GetKey(it.Key)
addr = common.BytesToAddress(addrBytes)
address *common.Address 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 { if addrBytes == nil {
// Preimage missing
missingPreimages++ missingPreimages++
if conf.OnlyWithAddresses { if conf.OnlyWithAddresses {
continue continue
} }
} else { } else {
addr = common.BytesToAddress(addrBytes)
address = &addr address = &addr
} }
obj := newObject(s, addr, &data) 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 // import pre accounts & construct test genesis block & state root
var ( var (
db = rawdb.NewMemoryDatabase() db = rawdb.NewMemoryDatabase()
tconf = &trie.Config{} tconf = &trie.Config{
Preimages: true,
}
) )
if scheme == rawdb.PathScheme { if scheme == rawdb.PathScheme {
tconf.PathDB = pathdb.Defaults tconf.PathDB = pathdb.Defaults