diff --git a/core/state/statedb.go b/core/state/statedb.go index ee7ae7020a..f3d0478482 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -1553,81 +1553,6 @@ func (s *StateDB) Commit(failPostCommitFunc func(), postCommitFuncs ...func() er return root, diffLayer, nil } -// GenerateDiffLayer generates block's DiffLayer after executing the block's txs. -// Attention, the DiffLayer returned include no Receipts, whose accounts' storage root -// is empty, whose BlockHash and Number field is empty, should further process by caller. -func (s *StateDB) GenerateDiffLayer() *types.DiffLayer { - if s.snap == nil { - return nil - } - - for addr := range s.stateObjectsPending { - if obj := s.stateObjects[addr]; !obj.deleted { - // The snapshot storage map for the object - var storage map[string][]byte - obj.finalise(false) - for key, value := range obj.pendingStorage { - // Skip noop changes, persist actual changes - if value == obj.originStorage[key] { - continue - } - obj.originStorage[key] = value - - var v []byte - if (value != common.Hash{}) { - // Encoding []byte cannot fail, ok to ignore the error. - v, _ = rlp.EncodeToBytes(common.TrimLeftZeroes(value[:])) - } - - obj.db.snapMux.Lock() - if storage == nil { - // Retrieve the old storage map, if available, create a new one otherwise - if storage = obj.db.snapStorage[obj.address]; storage == nil { - storage = make(map[string][]byte) - obj.db.snapStorage[obj.address] = storage - } - } - storage[string(key[:])] = v // v will be nil if value is 0x00 - obj.db.snapMux.Unlock() - } - - if !obj.deleted { - s.snapMux.Lock() - // The storage root hasn't been intermediate, pass empty storage root here. - s.snapAccounts[obj.address] = snapshot.SlimAccountRLP(obj.data.Nonce, obj.data.Balance, common.Hash{}, obj.data.CodeHash) - s.snapMux.Unlock() - } - } - } - - var diffLayer = &types.DiffLayer{} - for addr := range s.stateObjectsDirty { - if obj := s.stateObjects[addr]; !obj.deleted { - if obj.code != nil && obj.dirtyCode { - diffLayer.Codes = append(diffLayer.Codes, types.DiffCode{ - Hash: common.BytesToHash(obj.CodeHash()), - Code: obj.code, - }) - } - } - } - - diffLayer.Destructs, diffLayer.Accounts, diffLayer.Storages = s.SnapToDiffLayer() - sort.SliceStable(diffLayer.Codes, func(i, j int) bool { - return diffLayer.Codes[i].Hash.Hex() < diffLayer.Codes[j].Hash.Hex() - }) - sort.SliceStable(diffLayer.Destructs, func(i, j int) bool { - return diffLayer.Destructs[i].Hex() < (diffLayer.Destructs[j].Hex()) - }) - sort.SliceStable(diffLayer.Accounts, func(i, j int) bool { - return diffLayer.Accounts[i].Account.Hex() < diffLayer.Accounts[j].Account.Hex() - }) - sort.SliceStable(diffLayer.Storages, func(i, j int) bool { - return diffLayer.Storages[i].Account.Hex() < diffLayer.Storages[j].Account.Hex() - }) - return diffLayer -} - func (s *StateDB) DiffLayerToSnap(diffLayer *types.DiffLayer) (map[common.Address]struct{}, map[common.Address][]byte, map[common.Address]map[string][]byte, error) { snapDestructs := make(map[common.Address]struct{}) snapAccounts := make(map[common.Address][]byte)