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: clear out cached state data when reset occurs #27376

Merged
merged 3 commits into from
Jun 5, 2023

Conversation

rjl493456442
Copy link
Member

It's a following PR based on #27339

Before byzantium fork, state root will be computed for each transaction. Specifically,
IntermediateRoot will be called at the end of transaction processing. Inside of it,
account/storage data will be cached if snapshot is available.

However, whenever account reset occurs, these cached state data should be cleared
out, otherwise we have no way to distinguish whether these data belongs to the
original one or the new one.

This PR fixes it by handling destruction at CreateAccount function.

Comment on lines 645 to 652
if s.snapAccounts != nil {
account = s.snapAccounts[prev.addrHash]
delete(s.snapAccounts, prev.addrHash)
}
if s.snapStorage != nil {
storage = s.snapStorage[prev.addrHash]
delete(s.snapStorage, prev.addrHash)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

These storages are otherwise only manipulated at transaction boundaries: finalize and commit. It does not seem correct to me to modify them on the fly like this, in the middle of a transaction.

What I most of all want to ensure that we avoid: changing the evm semantics in a way which fixes a theoretical corner-case but causes a break in something which can be triggered in practice.

Copy link
Member Author

Choose a reason for hiding this comment

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

snapAccount, snapStorage are essentially equivalent with stateObjectsDestruct.

  • snapAccount, snapStorage cache the state data
  • stateObjectsDestruct caches the destruction event

Because in the case of ResetAccount, the original one is replaced with the new one,
it's the only correct place to manipulate these three maps, otherwise the destruction
event will be lost.

We can run a full sync to ensure nothing is broken.

@holiman
Copy link
Contributor

holiman commented May 31, 2023

@karalabe PTAL

core/state/statedb.go Outdated Show resolved Hide resolved
@karalabe karalabe added this to the 1.12.1 milestone Jun 5, 2023
Copy link
Member

@karalabe karalabe left a comment

Choose a reason for hiding this comment

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

SGTM

Copy link
Member

@karalabe karalabe left a comment

Choose a reason for hiding this comment

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

SGTM

@karalabe karalabe merged commit 380fb4e into ethereum:master Jun 5, 2023
devopsbo3 pushed a commit to HorizenOfficial/go-ethereum that referenced this pull request Nov 10, 2023
…7376)

* core/state: remove cached snap data if reset occurs

* core/state: address comment from peter

* core/state: skip revert in case data is nil
devopsbo3 added a commit to HorizenOfficial/go-ethereum that referenced this pull request Nov 10, 2023
devopsbo3 added a commit to HorizenOfficial/go-ethereum that referenced this pull request Nov 10, 2023
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants