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, triedb: remove destruct flag in state snapshot #30752

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

rjl493456442
Copy link
Member

@rjl493456442 rjl493456442 commented Nov 13, 2024

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.

@rjl493456442
Copy link
Member Author

@holiman @karalabe This pull request is ready, please take a look.

@@ -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)
Copy link
Member Author

@rjl493456442 rjl493456442 Nov 18, 2024

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.

Copy link
Contributor

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

Copy link
Member Author

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.

@holiman
Copy link
Contributor

holiman commented Nov 19, 2024

Screenshot 2024-11-19 at 09-52-30 Single Geth - Grafana

The fullsync with this PR has reached 14.3M now. Once it reaches 17.1M (Cancun), we can consider it done, because after that there are no more destructs. EDIT: The cancun fork was activated at block 19.2M (19426589 )

Copy link
Member

@MariusVanDerWijden MariusVanDerWijden left a 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

core/state/statedb.go Outdated Show resolved Hide resolved
@@ -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.
Copy link
Contributor

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?

Copy link
Member Author

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

Copy link
Contributor

@holiman holiman left a 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

Copy link
Member

@MariusVanDerWijden MariusVanDerWijden left a comment

Choose a reason for hiding this comment

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

LGTM

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.

4 participants