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

Merged
merged 6 commits into from
Nov 22, 2024

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.


SIDE EFFECT:

When the node upgrades from the legacy version, the existing snapshot journal will be discarded due to a version mismatch.
Details:

  • The snapshot journal with the incorrect version will be discarded (required=1, got=0).
  • The entire state snapshot will be rebuilt because the [in-memory] layers are lost.

Unfortunately, this is unavoidable and must be clearly highlighted in the release notes.

@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

@holiman
Copy link
Contributor

holiman commented Nov 22, 2024

Bench-run is at 17.6M. I'm fine with merging this now, we can always revert it if the run croaks

@holiman holiman added this to the 1.14.13 milestone Nov 22, 2024
@rjl493456442 rjl493456442 merged commit 6485d5e into ethereum:master Nov 22, 2024
3 checks passed
@holiman
Copy link
Contributor

holiman commented Nov 25, 2024

Bench-run at 21.1M today, so it finished fine!

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