-
Notifications
You must be signed in to change notification settings - Fork 20.2k
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, triedb: remove destruct flag in state snapshot #30752
base: master
Are you sure you want to change the base?
Conversation
8e83eb4
to
851dd99
Compare
7dac760
to
8975e24
Compare
8975e24
to
2534628
Compare
core/state/snapshot/snapshot.go
Outdated
@@ -528,9 +528,6 @@ func diffToDisk(bottom *diffLayer) *diskLayer { | |||
base.genAbort <- abort | |||
stats = <-abort | |||
} | |||
// Put the deletion in the batch writer, flush all updates in the final step. | |||
rawdb.DeleteSnapshotRoot(batch) |
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.
This step is no longer needed, the flat state changes will always be flushed atomically.
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.
Doesn't hurt to leave in, though. Then we're free to maybe flush the batch if we need to, in some non-mainnet case
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.
I would prefer to remove it. As in pathdb, we MUST flush the content in a single batch, including the trie nodes and the flat states, so no reason to keep the tricks.
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.
LGTM, I reviewed most of these changes already, as they are part of https://github.com/ethereum/go-ethereum/pull/30643/commits. I added some clarifying questions there. I would be good with merging this once these questions have been answered
@@ -33,6 +35,7 @@ type contractCode struct { | |||
type accountDelete struct { | |||
address common.Address // address is the unique account identifier | |||
origin []byte // origin is the original value of account data in slim-RLP encoding. | |||
storages map[common.Hash][]byte // storages stores mutated slots, the value should be nil. |
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.
What do you mean by "should be nil"? Do you mean that it's a programming error otherwise, or that something abnormal, like destruct+resurrect occurred?
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.
nil represents deletion.
As the entire account is deleted, all the correpsonding storage slots should also be removed, with the value as nil
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.
This looks good to me
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.
LGTM
This pull request removes the destruct flag from the state snapshot to simplify the code.
Previously, this flag indicated that an account was removed during a state transition, making all associated storage slots inaccessible. Because storage deletion can involve a large number of slots, the actual deletion is deferred until the end of the process, where it is handled in batches.
With the deprecation of self-destruct in the Cancun fork, storage deletions are no longer expected. Historically, the largest storage deletion event in Ethereum was around 15 megabytes—manageable in memory.
In this pull request, the single destruct flag is replaced by a set of deletion markers for individual storage slots. Each deleted storage slot will now appear in the Storage set with a nil value.
This change will simplify a lot logics, such as storage accessing, storage flushing, storage iteration and so on.