-
Notifications
You must be signed in to change notification settings - Fork 20.4k
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
Conversation
core/state/statedb.go
Outdated
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) | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 datastateObjectsDestruct
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.
@karalabe PTAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SGTM
…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
…hereum#27376)" This reverts commit f60b50e.
…hereum#27376)" This reverts commit f60b50e.
journal.go: in resetObjectChange - add account in resetObjectChange (ref ethereum/go-ethereum#27339) - add prevAccount and prevStorage (ref ethereum/go-ethereum#27376) - add prevAccountOrigin and prevStorageOrigin to track changes state_object.go: add origin for tracking the original StateAccount before change statedb.go: - add accountsOrigin and storagesOrigin, same functions as above - stateObjectsDestruct now track the previous state before destruct - add functions for handle destructing old states
journal.go: in resetObjectChange - add account in resetObjectChange (ref ethereum/go-ethereum#27339) - add prevAccount and prevStorage (ref ethereum/go-ethereum#27376) - add prevAccountOrigin and prevStorageOrigin to track changes state_object.go: add origin for tracking the original StateAccount before change statedb.go: - add accountsOrigin and storagesOrigin, same functions as above - stateObjectsDestruct now track the previous state before destruct - add functions for handle destructing old states
journal.go: in resetObjectChange - add account in resetObjectChange (ref ethereum/go-ethereum#27339) - add prevAccount and prevStorage (ref ethereum/go-ethereum#27376) - add prevAccountOrigin and prevStorageOrigin to track changes state_object.go: add origin for tracking the original StateAccount before change statedb.go: - add accountsOrigin and storagesOrigin, same functions as above - stateObjectsDestruct now track the previous state before destruct - add functions for handle destructing old states
* trie: triestate/Set to track changes * core/state: track state changes journal.go: in resetObjectChange - add account in resetObjectChange (ref ethereum/go-ethereum#27339) - add prevAccount and prevStorage (ref ethereum/go-ethereum#27376) - add prevAccountOrigin and prevStorageOrigin to track changes state_object.go: add origin for tracking the original StateAccount before change statedb.go: - add accountsOrigin and storagesOrigin, same functions as above - stateObjectsDestruct now track the previous state before destruct - add functions for handle destructing old states * all: apply changes to tests
* trie: triestate/Set to track changes * core/state: track state changes journal.go: in resetObjectChange - add account in resetObjectChange (ref ethereum/go-ethereum#27339) - add prevAccount and prevStorage (ref ethereum/go-ethereum#27376) - add prevAccountOrigin and prevStorageOrigin to track changes state_object.go: add origin for tracking the original StateAccount before change statedb.go: - add accountsOrigin and storagesOrigin, same functions as above - stateObjectsDestruct now track the previous state before destruct - add functions for handle destructing old states * all: apply changes to tests
* trie: triestate/Set to track changes * core/state: track state changes journal.go: in resetObjectChange - add account in resetObjectChange (ref ethereum/go-ethereum#27339) - add prevAccount and prevStorage (ref ethereum/go-ethereum#27376) - add prevAccountOrigin and prevStorageOrigin to track changes state_object.go: add origin for tracking the original StateAccount before change statedb.go: - add accountsOrigin and storagesOrigin, same functions as above - stateObjectsDestruct now track the previous state before destruct - add functions for handle destructing old states * all: apply changes to tests
* trie: triestate/Set to track changes * core/state: track state changes journal.go: in resetObjectChange - add account in resetObjectChange (ref ethereum/go-ethereum#27339) - add prevAccount and prevStorage (ref ethereum/go-ethereum#27376) - add prevAccountOrigin and prevStorageOrigin to track changes state_object.go: add origin for tracking the original StateAccount before change statedb.go: - add accountsOrigin and storagesOrigin, same functions as above - stateObjectsDestruct now track the previous state before destruct - add functions for handle destructing old states * all: apply changes to tests
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.