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

refactor(trie): trie node iterators #5048

Merged
merged 4 commits into from
Oct 18, 2023
Merged

refactor(trie): trie node iterators #5048

merged 4 commits into from
Oct 18, 2023

Conversation

rkrasiuk
Copy link
Member

@rkrasiuk rkrasiuk commented Oct 17, 2023

Description

Refactor common iteration steps into AccountNodeIter and StorageNodeIter iterators, get rid of redundant generics.

Summary

🤖 Generated by Copilot at b424fb4

This pull request refactors the state root and storage root calculation logic in the reth crate, using new iterator-based abstractions and moving some types and functions to the primitives crate. It also simplifies the code, fixes a bug in the proof generation, and adds a new dependency on the auto_impl crate. The affected files are mostly in the trie crate, but also in the stages and primitives crates.

@rkrasiuk rkrasiuk added C-debt Refactor of code section that is hard to understand or maintain A-trie Related to Merkle Patricia Trie implementation labels Oct 17, 2023
Comment on lines +20 to 22
// TODO: remove in the next breaking release.
/// The last walker key processed.
pub last_walker_key: Vec<u8>,
Copy link
Member Author

Choose a reason for hiding this comment

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

Nothing i can do here atm without breaking the format, will open a separate PR for this

crates/trie/src/lib.rs Outdated Show resolved Hide resolved
crates/trie/src/trie.rs Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Oct 17, 2023

Codecov Report

Merging #5048 (b83dc81) into main (d67730b) will decrease coverage by 0.03%.
Report is 1 commits behind head on main.
The diff coverage is 95.18%.

Impacted file tree graph

Files Coverage Δ
crates/stages/src/stages/merkle.rs 82.52% <ø> (+0.19%) ⬆️
crates/trie/src/progress.rs 0.00% <ø> (ø)
crates/trie/src/proof.rs 99.70% <100.00%> (+0.25%) ⬆️
crates/trie/src/trie.rs 96.49% <100.00%> (+<0.01%) ⬆️
crates/trie/src/trie_cursor/account_cursor.rs 98.21% <100.00%> (ø)
crates/trie/src/trie_cursor/mod.rs 100.00% <100.00%> (ø)
crates/trie/src/trie_cursor/storage_cursor.rs 97.87% <100.00%> (ø)
crates/trie/src/updates.rs 88.60% <ø> (-1.27%) ⬇️
crates/trie/src/walker.rs 96.15% <100.00%> (-0.12%) ⬇️
crates/trie/src/node_iter.rs 94.73% <94.73%> (ø)
... and 1 more

... and 9 files with indirect coverage changes

Flag Coverage Δ
integration-tests 17.00% <0.00%> (-0.02%) ⬇️
unit-tests 62.39% <95.18%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
reth binary 30.85% <ø> (ø)
blockchain tree 80.82% <ø> (ø)
pipeline 88.38% <ø> (+0.01%) ⬆️
storage (db) 74.41% <ø> (ø)
trie 94.96% <97.93%> (-0.05%) ⬇️
txpool 55.33% <ø> (-0.45%) ⬇️
networking 78.17% <ø> (-0.03%) ⬇️
rpc 58.28% <ø> (+0.02%) ⬆️
consensus 63.01% <ø> (ø)
revm 28.69% <ø> (ø)
payload builder 7.95% <ø> (ø)
primitives 86.39% <0.00%> (-0.05%) ⬇️

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.

this looks like a simple refactor that makes the Walker type nicer.

I think we have enough coverage for that, since this mostly moved things around?

#[derive(Debug)]
pub struct TrieWalker<'a, K, C> {
pub struct TrieWalker<C> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this looks indeed simpler

@rkrasiuk
Copy link
Member Author

@mattsse the main refactor is creating these iterators https://github.com/paradigmxyz/reth/blob/7a080f7a3d2941feed5cb074ee529374ae983af2/crates/trie/src/node_iter.rs
TrieWalker just happened to be simplified in the process

@rkrasiuk
Copy link
Member Author

tested on sepolia ✔️

@rkrasiuk rkrasiuk added this pull request to the merge queue Oct 18, 2023
Merged via the queue into main with commit 4b1a0ce Oct 18, 2023
24 checks passed
@rkrasiuk rkrasiuk deleted the rkrasiuk/trie-node-iter branch October 18, 2023 11:24
mattsse pushed a commit that referenced this pull request Nov 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-trie Related to Merkle Patricia Trie implementation C-debt Refactor of code section that is hard to understand or maintain
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants