diff --git a/core/state/state_sizer.go b/core/state/state_sizer.go index 2066c94845d3..1cc88505bab3 100644 --- a/core/state/state_sizer.go +++ b/core/state/state_sizer.go @@ -218,7 +218,7 @@ func calSizeStats(update *stateUpdate) (SizeStats, error) { // this deviation is negligible and acceptable for measurement purposes. for _, code := range update.codes { stats.ContractCodes += 1 - stats.ContractCodeBytes += codeKeySize + int64(len(code.blob)) + stats.ContractCodeBytes += codeKeySize + int64(len(code)) } return stats, nil } diff --git a/core/state/statedb.go b/core/state/statedb.go index 364bc4085035..a546eed6162f 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -1324,8 +1324,8 @@ func (s *StateDB) commitAndFlush(block uint64, deleteEmptyObjects bool, noStorag // Commit dirty contract code if any exists if db := s.db.TrieDB().Disk(); db != nil && len(ret.codes) > 0 { batch := db.NewBatch() - for _, code := range ret.codes { - rawdb.WriteCode(batch, code.hash, code.blob) + for hash, code := range ret.codes { + rawdb.WriteCode(batch, hash, code) } if err := batch.Write(); err != nil { return nil, err diff --git a/core/state/stateupdate.go b/core/state/stateupdate.go index a62e2b2d2dfc..a5b400db768c 100644 --- a/core/state/stateupdate.go +++ b/core/state/stateupdate.go @@ -82,8 +82,8 @@ type stateUpdate struct { storagesOrigin map[common.Address]map[common.Hash][]byte rawStorageKey bool - codes map[common.Address]contractCode // codes contains the set of dirty codes - nodes *trienode.MergedNodeSet // Aggregated dirty nodes caused by state changes + codes map[common.Hash][]byte // codes contains the set of dirty codes + nodes *trienode.MergedNodeSet // Aggregated dirty nodes caused by state changes } // empty returns a flag indicating the state transition is empty or not. @@ -99,11 +99,11 @@ func (sc *stateUpdate) empty() bool { // the hash of the slot key for constructing state update object. func newStateUpdate(rawStorageKey bool, originRoot common.Hash, root common.Hash, blockNumber uint64, deletes map[common.Hash]*accountDelete, updates map[common.Hash]*accountUpdate, nodes *trienode.MergedNodeSet) *stateUpdate { var ( - accounts = make(map[common.Hash][]byte) - accountsOrigin = make(map[common.Address][]byte) + accounts = make(map[common.Hash][]byte, len(updates)+len(deletes)) + accountsOrigin = make(map[common.Address][]byte, len(updates)+len(deletes)) storages = make(map[common.Hash]map[common.Hash][]byte) storagesOrigin = make(map[common.Address]map[common.Hash][]byte) - codes = make(map[common.Address]contractCode) + codes = make(map[common.Hash][]byte) ) // Since some accounts might be destroyed and recreated within the same // block, deletions must be aggregated first. @@ -125,7 +125,7 @@ func newStateUpdate(rawStorageKey bool, originRoot common.Hash, root common.Hash // Aggregate dirty contract codes if they are available. addr := op.address if op.code != nil { - codes[addr] = *op.code + codes[op.code.hash] = op.code.blob } accounts[addrHash] = op.data