From 0833f3625ded6e54b3f679ab337e4d186fbc6f21 Mon Sep 17 00:00:00 2001 From: Atsushi Ishibashi Date: Thu, 3 May 2018 17:50:24 +0900 Subject: [PATCH] core/state: memory efficient, add AddPreimage test --- core/state/statedb.go | 2 +- core/state/statedb_test.go | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/core/state/statedb.go b/core/state/statedb.go index a952027d6d..b4aa7306b7 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -466,7 +466,7 @@ func (self *StateDB) Copy() *StateDB { refund: self.refund, logs: make(map[common.Hash][]*types.Log, len(self.logs)), logSize: self.logSize, - preimages: make(map[common.Hash][]byte), + preimages: make(map[common.Hash][]byte, len(self.preimages)), journal: newJournal(), } // Copy the dirty states, logs, and preimages diff --git a/core/state/statedb_test.go b/core/state/statedb_test.go index 420ca745cc..35bc4b945a 100644 --- a/core/state/statedb_test.go +++ b/core/state/statedb_test.go @@ -277,6 +277,15 @@ func newTestAction(addr common.Address, r *rand.Rand) testAction { }, args: make([]int64, 1), }, + { + 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