Skip to content

Commit ff9a868

Browse files
karalabefjl
authored andcommitted
core/state: revert metro suicide map addition (#15024)
1 parent 20b818d commit ff9a868

4 files changed

Lines changed: 28 additions & 49 deletions

File tree

‎core/state/journal.go‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,6 @@ func (ch suicideChange) undo(s *StateDB) {
9191
if obj != nil {
9292
obj.suicided = ch.prev
9393
obj.setBalance(ch.prevbalance)
94-
// if the object wasn't suicided before, remove
95-
// it from the list of destructed objects as well.
96-
if !obj.suicided {
97-
delete(s.stateObjectsDestructed, *ch.account)
98-
}
9994
}
10095
}
10196

‎core/state/statedb.go‎

Lines changed: 27 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -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
//

‎core/state_processor.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func ApplyTransaction(config *params.ChainConfig, bc *BlockChain, author *common
106106
// Update the state with pending changes
107107
var root []byte
108108
if config.IsMetropolis(header.Number) {
109-
statedb.Finalise()
109+
statedb.Finalise(true)
110110
} else {
111111
root = statedb.IntermediateRoot(config.IsEIP158(header.Number)).Bytes()
112112
}

‎tests/block_test.go‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ func TestBlockchain(t *testing.T) {
3737

3838
// Still failing tests
3939
bt.skipLoad(`^bcWalletTest.*_Byzantium$`)
40-
bt.skipLoad(`^bcStateTests/suicideCoinbase.json.*_Byzantium$`)
4140

4241
bt.walk(t, blockTestDir, func(t *testing.T, name string, test *BlockTest) {
4342
if err := bt.checkFailure(t, name, test.Run()); err != nil {

0 commit comments

Comments
 (0)