Skip to content

chore(trie): Implement clear trie changeset methods#18730

Merged
mediocregopher merged 13 commits into18460-trie-changesetsfrom
mediocregopher/clear-trie-changesets
Oct 1, 2025
Merged

chore(trie): Implement clear trie changeset methods#18730
mediocregopher merged 13 commits into18460-trie-changesetsfrom
mediocregopher/clear-trie-changesets

Conversation

@mediocregopher
Copy link
Member

These methods will be used in various places when it's necessary to delete changeset data. This includes pruning, unwinding, and also when populating the data during pipeline sync in certain cases.

A new type BlockNumberHashedAddressRange is implemented for convenience.

These methods will be used in various places when it's necessary to
delete changeset data. This includes pruning, unwinding, and also when
populating the data during pipeline sync in certain cases.

A new type BlockNumberHashedAddressRange is implemented for convenience.
@mediocregopher mediocregopher marked this pull request as ready for review September 26, 2025 10:36

fn clear_trie_changesets_range(
&self,
range: impl RangeBounds<BlockNumber>,
Copy link
Member

@shekhirin shekhirin Sep 26, 2025

Choose a reason for hiding this comment

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

something we might want to consider immediately now is that if we move trie changesets to static files, we would not be able to provide a range, it will just be "truncate N from the end". Maybe we should change it to be a truncate?

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed to clear_trie_changesets_from.

I'm not sure it's going to make sense to have these in static files tho, at least in their current state. Without an accompanying index the data isn't very useful beyond reverting a relatively small amount of blocks, so storing in static files would have us keep way more than we could use for no benefit.

Copy link
Member

Choose a reason for hiding this comment

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

yeah, the indices would live in the DB same as for account/storage history, but the changesets themselves in static files. This can improve storage and perf of querying actual trie changesets.

Copy link
Member

@Rjected Rjected left a comment

Choose a reason for hiding this comment

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

unless we use the BlockNumberHashedAddressRange somewhere else, thinking we can make this simpler

Comment on lines +2404 to +2406
let range: BlockNumberHashedAddressRange = (from..).into();
let mut cursor = tx.cursor_dup_write::<tables::StoragesTrieChangeSets>()?;
let mut walker = cursor.walk_range(range)?;
Copy link
Member

Choose a reason for hiding this comment

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

so this is the only place we really use BlockNumberHashedAddressRange? maybe we could just remove the struct and do

        let range: RangeFrom<BlockNumberHashedAddress> = (from, B256::ZERO).into()..;

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, the range type made more sense when the clear method actually accepted a range, removed.

@yongkangc yongkangc self-requested a review September 30, 2025 08:03
@mattsse mattsse added the C-perf A change motivated by improving speed, memory usage or disk footprint label Sep 30, 2025
Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

lgtm, one pedantic doc suggestion

}

{
let range: RangeFrom<BlockNumberHashedAddress> = (from, B256::ZERO).into()..;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I see, this would be the first (num, hash) pair for BlockNumberHashedAddress

@github-project-automation github-project-automation bot moved this from Backlog to In Progress in Reth Tracker Sep 30, 2025
Copy link
Member

@Rjected Rjected 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 like the tests

@mediocregopher mediocregopher merged commit 56bb9e1 into 18460-trie-changesets Oct 1, 2025
33 checks passed
@mediocregopher mediocregopher deleted the mediocregopher/clear-trie-changesets branch October 1, 2025 10:03
@github-project-automation github-project-automation bot moved this from In Progress to Done in Reth Tracker Oct 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-perf A change motivated by improving speed, memory usage or disk footprint

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants