Skip to content

Commit

Permalink
core/state: reintroduce creation fix, track in state journal
Browse files Browse the repository at this point in the history
  • Loading branch information
karalabe committed Mar 16, 2020
1 parent f39cd6d commit d645b8f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
6 changes: 5 additions & 1 deletion core/state/journal.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ type (
account *common.Address
}
resetObjectChange struct {
prev *stateObject
prev *stateObject
prevdestruct bool
}
suicideChange struct {
account *common.Address
Expand Down Expand Up @@ -142,6 +143,9 @@ func (ch createObjectChange) dirtied() *common.Address {

func (ch resetObjectChange) revert(s *StateDB) {
s.setStateObject(ch.prev)
if !ch.prevdestruct && s.snap != nil {
delete(s.snapDestructs, ch.prev.addrHash)
}
}

func (ch resetObjectChange) dirtied() *common.Address {
Expand Down
15 changes: 8 additions & 7 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,12 +569,19 @@ func (s *StateDB) GetOrNewStateObject(addr common.Address) *stateObject {
func (s *StateDB) createObject(addr common.Address) (newobj, prev *stateObject) {
prev = s.getDeletedStateObject(addr) // Note, prev might have been deleted, we need that!

var prevdestruct bool
if s.snap != nil && prev != nil {
_, prevdestruct = s.snapDestructs[prev.addrHash]
if !prevdestruct {
s.snapDestructs[prev.addrHash] = struct{}{}
}
}
newobj = newObject(s, addr, Account{})
newobj.setNonce(0) // sets the object to dirty
if prev == nil {
s.journal.append(createObjectChange{account: &addr})
} else {
s.journal.append(resetObjectChange{prev: prev})
s.journal.append(resetObjectChange{prev: prev, prevdestruct: prevdestruct})
}
s.setStateObject(newobj)
return newobj, prev
Expand All @@ -595,12 +602,6 @@ func (s *StateDB) CreateAccount(addr common.Address) {
if prev != nil {
newObj.setBalance(prev.data.Balance)
}
// This has been removed. A Create action may be cancelled, if the initcode
// exits with error. In that case, we would need to clean up the snapDestructs,
// Better to not put it there in the first place, if we can get away with it.
//if s.snap != nil && prev != nil {
// s.snapDestructs[prev.addrHash] = struct{}{}
//}
}

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

0 comments on commit d645b8f

Please sign in to comment.