@@ -46,9 +46,8 @@ type StateDB struct {
4646 trie Trie
4747
4848 // This map holds 'live' objects, which will get modified while processing a state transition.
49- stateObjects map [common.Address ]* stateObject
50- stateObjectsDirty map [common.Address ]struct {}
51- stateObjectsDestructed map [common.Address ]struct {}
49+ stateObjects map [common.Address ]* stateObject
50+ stateObjectsDirty map [common.Address ]struct {}
5251
5352 // DB error.
5453 // State objects are used by the consensus core and VM which are
@@ -83,14 +82,13 @@ func New(root common.Hash, db Database) (*StateDB, error) {
8382 return nil , err
8483 }
8584 return & StateDB {
86- db : db ,
87- trie : tr ,
88- stateObjects : make (map [common.Address ]* stateObject ),
89- stateObjectsDirty : make (map [common.Address ]struct {}),
90- stateObjectsDestructed : make (map [common.Address ]struct {}),
91- refund : new (big.Int ),
92- logs : make (map [common.Hash ][]* types.Log ),
93- preimages : make (map [common.Hash ][]byte ),
85+ db : db ,
86+ trie : tr ,
87+ stateObjects : make (map [common.Address ]* stateObject ),
88+ stateObjectsDirty : make (map [common.Address ]struct {}),
89+ refund : new (big.Int ),
90+ logs : make (map [common.Hash ][]* types.Log ),
91+ preimages : make (map [common.Hash ][]byte ),
9492 }, nil
9593}
9694
@@ -115,7 +113,6 @@ func (self *StateDB) Reset(root common.Hash) error {
115113 self .trie = tr
116114 self .stateObjects = make (map [common.Address ]* stateObject )
117115 self .stateObjectsDirty = make (map [common.Address ]struct {})
118- self .stateObjectsDestructed = make (map [common.Address ]struct {})
119116 self .thash = common.Hash {}
120117 self .bhash = common.Hash {}
121118 self .txIndex = 0
@@ -323,7 +320,6 @@ func (self *StateDB) Suicide(addr common.Address) bool {
323320 })
324321 stateObject .markSuicided ()
325322 stateObject .data .Balance = new (big.Int )
326- self .stateObjectsDestructed [addr ] = struct {}{}
327323
328324 return true
329325}
@@ -456,23 +452,19 @@ func (self *StateDB) Copy() *StateDB {
456452
457453 // Copy all the basic fields, initialize the memory ones
458454 state := & StateDB {
459- db : self .db ,
460- trie : self .trie ,
461- stateObjects : make (map [common.Address ]* stateObject , len (self .stateObjectsDirty )),
462- stateObjectsDirty : make (map [common.Address ]struct {}, len (self .stateObjectsDirty )),
463- stateObjectsDestructed : make (map [common.Address ]struct {}, len (self .stateObjectsDestructed )),
464- refund : new (big.Int ).Set (self .refund ),
465- logs : make (map [common.Hash ][]* types.Log , len (self .logs )),
466- logSize : self .logSize ,
467- preimages : make (map [common.Hash ][]byte ),
455+ db : self .db ,
456+ trie : self .trie ,
457+ stateObjects : make (map [common.Address ]* stateObject , len (self .stateObjectsDirty )),
458+ stateObjectsDirty : make (map [common.Address ]struct {}, len (self .stateObjectsDirty )),
459+ refund : new (big.Int ).Set (self .refund ),
460+ logs : make (map [common.Hash ][]* types.Log , len (self .logs )),
461+ logSize : self .logSize ,
462+ preimages : make (map [common.Hash ][]byte ),
468463 }
469464 // Copy the dirty states, logs, and preimages
470465 for addr := range self .stateObjectsDirty {
471466 state .stateObjects [addr ] = self .stateObjects [addr ].deepCopy (state , state .MarkStateObjectDirty )
472467 state .stateObjectsDirty [addr ] = struct {}{}
473- if self .stateObjects [addr ].suicided {
474- state .stateObjectsDestructed [addr ] = struct {}{}
475- }
476468 }
477469 for hash , logs := range self .logs {
478470 state .logs [hash ] = make ([]* types.Log , len (logs ))
@@ -520,10 +512,9 @@ func (self *StateDB) GetRefund() *big.Int {
520512 return self .refund
521513}
522514
523- // IntermediateRoot computes the current root hash of the state trie.
524- // It is called in between transactions to get the root hash that
525- // goes into transaction receipts.
526- func (s * StateDB ) IntermediateRoot (deleteEmptyObjects bool ) common.Hash {
515+ // Finalise finalises the state by removing the self destructed objects
516+ // and clears the journal as well as the refunds.
517+ func (s * StateDB ) Finalise (deleteEmptyObjects bool ) {
527518 for addr := range s .stateObjectsDirty {
528519 stateObject := s .stateObjects [addr ]
529520 if stateObject .suicided || (deleteEmptyObjects && stateObject .empty ()) {
@@ -535,6 +526,13 @@ func (s *StateDB) IntermediateRoot(deleteEmptyObjects bool) common.Hash {
535526 }
536527 // Invalidate journal because reverting across transactions is not allowed.
537528 s .clearJournalAndRefund ()
529+ }
530+
531+ // IntermediateRoot computes the current root hash of the state trie.
532+ // It is called in between transactions to get the root hash that
533+ // goes into transaction receipts.
534+ func (s * StateDB ) IntermediateRoot (deleteEmptyObjects bool ) common.Hash {
535+ s .Finalise (deleteEmptyObjects )
538536 return s .trie .Hash ()
539537}
540538
@@ -546,19 +544,6 @@ func (self *StateDB) Prepare(thash, bhash common.Hash, ti int) {
546544 self .txIndex = ti
547545}
548546
549- // Finalise finalises the state by removing the self destructed objects
550- // in the current stateObjectsDestructed buffer and clears the journal
551- // as well as the refunds.
552- //
553- // Please note that Finalise is used by EIP#98 and is used instead of
554- // IntermediateRoot.
555- func (s * StateDB ) Finalise () {
556- for addr := range s .stateObjectsDestructed {
557- s .deleteStateObject (s .stateObjects [addr ])
558- }
559- s .clearJournalAndRefund ()
560- }
561-
562547// DeleteSuicides flags the suicided objects for deletion so that it
563548// won't be referenced again when called / queried up on.
564549//
0 commit comments