core/state: memory efficient, add AddPreimage test #16663 (#1182)

This commit is contained in:
Daniel Liu 2025-07-02 14:53:00 +08:00 committed by GitHub
parent b4f4b95634
commit 9affb6a582
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 4 deletions

View file

@ -19,6 +19,7 @@ package state
import (
"fmt"
"maps"
"math/big"
"sort"
"time"
@ -637,7 +638,7 @@ func (s *StateDB) Copy() *StateDB {
refund: s.refund,
logs: make(map[common.Hash][]*types.Log, len(s.logs)),
logSize: s.logSize,
preimages: make(map[common.Hash][]byte),
preimages: maps.Clone(s.preimages),
journal: newJournal(),
}
// Copy the dirty states, logs, and preimages
@ -683,9 +684,6 @@ func (s *StateDB) Copy() *StateDB {
state.logs[hash] = cpy
}
for hash, preimage := range s.preimages {
state.preimages[hash] = preimage
}
// Do we need to copy the access list? In practice: No. At the start of a
// transaction, the access list is empty. In practice, we only ever copy state
// _between_ transactions/blocks, never in the middle of a transaction.

View file

@ -305,6 +305,15 @@ func newTestAction(addr common.Address, r *rand.Rand) testAction {
},
args: make([]int64, 2),
},
{
name: "AddPreimage",
fn: func(a testAction, s *StateDB) {
preimage := []byte{1}
hash := common.BytesToHash(preimage)
s.AddPreimage(hash, preimage)
},
args: make([]int64, 1),
},
}
action := actions[r.Intn(len(actions))]
var nameargs []string