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

Optimize destroying an account with no storage in snapshot diffToDisk #399

Merged
merged 6 commits into from
Jan 23, 2025

Conversation

PlasmaPower
Copy link
Collaborator

To do this, we get the account info from the disk layer and check if its storage root was empty before trying to iterate over its storage to delete it.

@PlasmaPower PlasmaPower requested a review from tsahee January 22, 2025 22:51
@cla-bot cla-bot bot added the s CLA signed label Jan 22, 2025
tsahee
tsahee previously approved these changes Jan 23, 2025
Copy link
Collaborator

@tsahee tsahee left a comment

Choose a reason for hiding this comment

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

code LGTM but made suggestions around documenting/naming

// Skip any account not covered yet by the snapshot
if base.genMarker != nil && bytes.Compare(hash[:], base.genMarker) > 0 {
if errors.Is(err, ErrNotCoveredYet) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Though it makes sense, I'd keep the code here unchanged, to minimise diff.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think there's merge conflict concern here because this code seems to be unchanged upstream until it's removed in ethereum/go-ethereum#30752

rawdb.DeleteAccountSnapshot(batch, hash)
base.cache.Set(hash[:], nil)

if err == nil && (oldAccount == nil || oldAccount.Root == nil) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

For the sake of a minimal understandable diff, I'd put here the call to base.account.
Also, either handle err != nil in some way or comment why you don't need to.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've added a warning if err != nil and a comment explaining that it falls through to iterating over and removing storage in case there is any

@@ -76,30 +76,28 @@ func (dl *diskLayer) Stale() bool {

// Account directly retrieves the account associated with a particular hash in
// the snapshot slim data format.
func (dl *diskLayer) Account(hash common.Hash) (*types.SlimAccount, error) {
data, err := dl.AccountRLP(hash)
func (dl *diskLayer) account(hash common.Hash, ignoreStale bool) (*types.SlimAccount, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

thinking alternative names.. not sure they are better, but what do you think about "evenIfStale" ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sounds good to me, renamed

Copy link
Collaborator

@tsahee tsahee left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@joshuacolvin0 joshuacolvin0 left a comment

Choose a reason for hiding this comment

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

LGTM

@tsahee tsahee enabled auto-merge January 23, 2025 23:38
@tsahee tsahee merged commit 5a7010a into master Jan 23, 2025
7 checks passed
@tsahee tsahee deleted the opt-destroy-no-storage branch January 23, 2025 23:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants