Skip to content

Commit 0379c92

Browse files
committed
core/state: modify how self-destruct journalling works
The self-destruct journalling is a bit strange: we allow the 'selfdestruct' operation to be journalled several times. This makes it so that we also are forced to store whether the account was already destructed. What we can do instead, is to only journal the first destruction, and after that only journal balance-changes, but not journal the selfdestruct itself. This simplifies the journalling, so that internals about state management does not leak into the journal-API.
1 parent 1925ff7 commit 0379c92

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

core/state/journal.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,8 @@ func (j *journal) JournalCreate(addr common.Address) {
144144
j.append(createObjectChange{account: &addr})
145145
}
146146

147-
func (j *journal) JournalDestruct(addr common.Address, previouslyDestructed bool, prevBalance *uint256.Int) {
148-
j.append(selfDestructChange{
149-
account: &addr,
150-
prev: previouslyDestructed,
151-
prevbalance: prevBalance.Clone(),
152-
})
147+
func (j *journal) JournalDestruct(addr common.Address) {
148+
j.append(selfDestructChange{account: &addr})
153149
}
154150

155151
func (j *journal) JournalSetState(addr common.Address, key, prev common.Hash) {
@@ -241,9 +237,7 @@ type (
241237
prevStorageOrigin map[common.Hash][]byte
242238
}
243239
selfDestructChange struct {
244-
account *common.Address
245-
prev bool // whether account had already self-destructed
246-
prevbalance *uint256.Int
240+
account *common.Address
247241
}
248242

249243
// Changes to individual accounts.
@@ -326,8 +320,7 @@ func (ch resetObjectChange) dirtied() *common.Address {
326320
func (ch selfDestructChange) revert(s *StateDB) {
327321
obj := s.getStateObject(*ch.account)
328322
if obj != nil {
329-
obj.selfDestructed = ch.prev
330-
obj.setBalance(ch.prevbalance)
323+
obj.selfDestructed = false
331324
}
332325
}
333326

core/state/statedb.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -439,9 +439,17 @@ func (s *StateDB) SelfDestruct(addr common.Address) {
439439
if stateObject == nil {
440440
return
441441
}
442-
s.journal.JournalDestruct(addr, stateObject.selfDestructed, stateObject.Balance())
443-
stateObject.markSelfdestructed()
444-
stateObject.data.Balance = new(uint256.Int)
442+
// Regardless of whether it is already destructed or not, we do have to
443+
// journal the balance-change, if we set it to zero here.
444+
if !stateObject.Balance().IsZero() {
445+
stateObject.SetBalance(new(uint256.Int))
446+
}
447+
// If it is already marked as self-destructed, we do not need to add it
448+
// for journalling a second time.
449+
if !stateObject.selfDestructed {
450+
s.journal.JournalDestruct(addr)
451+
stateObject.markSelfdestructed()
452+
}
445453
}
446454

447455
func (s *StateDB) Selfdestruct6780(addr common.Address) {

0 commit comments

Comments
 (0)