Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core/state: mark account as dirty when resetObject occurs #27339

Merged
merged 1 commit into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion core/state/journal.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ type (
account *common.Address
}
resetObjectChange struct {
account *common.Address
prev *stateObject
prevdestruct bool
}
Expand Down Expand Up @@ -162,7 +163,7 @@ func (ch resetObjectChange) revert(s *StateDB) {
}

func (ch resetObjectChange) dirtied() *common.Address {
return nil
return ch.account
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The address field here is not needed because resetObjectChange already contains the stateObject.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For future readers: the semantics behind dirtied() is, that it it supposed to spit out which, if any, address was made dirty by the change. And dirty means that it affects the state trie, so needs to update the stateroot.

For example, the refundChange do not mark something dirty, because it only affects the runtime but has no persistent effect on the state. Same with accessListAddAccountChange,addPreimageChange, addLogChange and transientStorageChange

}

func (ch suicideChange) revert(s *StateDB) {
Expand Down
14 changes: 5 additions & 9 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,19 +623,15 @@ func (s *StateDB) GetOrNewStateObject(addr common.Address) *stateObject {
// the given address, it is overwritten and returned as the second return value.
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 prev != nil {
_, prevdestruct = s.stateObjectsDestruct[prev.address]
if !prevdestruct {
s.stateObjectsDestruct[prev.address] = struct{}{}
}
}
newobj = newObject(s, addr, types.StateAccount{})
if prev == nil {
s.journal.append(createObjectChange{account: &addr})
} else {
s.journal.append(resetObjectChange{prev: prev, prevdestruct: prevdestruct})
_, prevdestruct := s.stateObjectsDestruct[prev.address]
if !prevdestruct {
s.stateObjectsDestruct[prev.address] = struct{}{}
}
s.journal.append(resetObjectChange{account: &addr, prev: prev, prevdestruct: prevdestruct})
}
s.setStateObject(newobj)
if prev != nil && !prev.deleted {
Expand Down