Skip to content

Commit 81801cc

Browse files
atsushi-ishibashiholiman
authored andcommitted
core/state: more memory efficient preimage allocation (#16663)
1 parent c57166c commit 81801cc

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

‎core/state/statedb.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ func (self *StateDB) Copy() *StateDB {
502502
refund: self.refund,
503503
logs: make(map[common.Hash][]*types.Log, len(self.logs)),
504504
logSize: self.logSize,
505-
preimages: make(map[common.Hash][]byte),
505+
preimages: make(map[common.Hash][]byte, len(self.preimages)),
506506
journal: newJournal(),
507507
}
508508
// Copy the dirty states, logs, and preimages

‎core/state/statedb_test.go‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,15 @@ func newTestAction(addr common.Address, r *rand.Rand) testAction {
276276
},
277277
args: make([]int64, 1),
278278
},
279+
{
280+
name: "AddPreimage",
281+
fn: func(a testAction, s *StateDB) {
282+
preimage := []byte{1}
283+
hash := common.BytesToHash(preimage)
284+
s.AddPreimage(hash, preimage)
285+
},
286+
args: make([]int64, 1),
287+
},
279288
}
280289
action := actions[r.Intn(len(actions))]
281290
var nameargs []string

0 commit comments

Comments
 (0)