Skip to content

Commit d645b8f

Browse files
committed
core/state: reintroduce creation fix, track in state journal
1 parent f39cd6d commit d645b8f

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

core/state/journal.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ type (
9090
account *common.Address
9191
}
9292
resetObjectChange struct {
93-
prev *stateObject
93+
prev *stateObject
94+
prevdestruct bool
9495
}
9596
suicideChange struct {
9697
account *common.Address
@@ -142,6 +143,9 @@ func (ch createObjectChange) dirtied() *common.Address {
142143

143144
func (ch resetObjectChange) revert(s *StateDB) {
144145
s.setStateObject(ch.prev)
146+
if !ch.prevdestruct && s.snap != nil {
147+
delete(s.snapDestructs, ch.prev.addrHash)
148+
}
145149
}
146150

147151
func (ch resetObjectChange) dirtied() *common.Address {

core/state/statedb.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -569,12 +569,19 @@ func (s *StateDB) GetOrNewStateObject(addr common.Address) *stateObject {
569569
func (s *StateDB) createObject(addr common.Address) (newobj, prev *stateObject) {
570570
prev = s.getDeletedStateObject(addr) // Note, prev might have been deleted, we need that!
571571

572+
var prevdestruct bool
573+
if s.snap != nil && prev != nil {
574+
_, prevdestruct = s.snapDestructs[prev.addrHash]
575+
if !prevdestruct {
576+
s.snapDestructs[prev.addrHash] = struct{}{}
577+
}
578+
}
572579
newobj = newObject(s, addr, Account{})
573580
newobj.setNonce(0) // sets the object to dirty
574581
if prev == nil {
575582
s.journal.append(createObjectChange{account: &addr})
576583
} else {
577-
s.journal.append(resetObjectChange{prev: prev})
584+
s.journal.append(resetObjectChange{prev: prev, prevdestruct: prevdestruct})
578585
}
579586
s.setStateObject(newobj)
580587
return newobj, prev
@@ -595,12 +602,6 @@ func (s *StateDB) CreateAccount(addr common.Address) {
595602
if prev != nil {
596603
newObj.setBalance(prev.data.Balance)
597604
}
598-
// This has been removed. A Create action may be cancelled, if the initcode
599-
// exits with error. In that case, we would need to clean up the snapDestructs,
600-
// Better to not put it there in the first place, if we can get away with it.
601-
//if s.snap != nil && prev != nil {
602-
// s.snapDestructs[prev.addrHash] = struct{}{}
603-
//}
604605
}
605606

606607
func (db *StateDB) ForEachStorage(addr common.Address, cb func(key, value common.Hash) bool) error {

0 commit comments

Comments
 (0)