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

feat(trie): sparse trie #11741

Merged
merged 5 commits into from
Oct 15, 2024
Merged

feat(trie): sparse trie #11741

merged 5 commits into from
Oct 15, 2024

Conversation

rkrasiuk
Copy link
Member

Description

Initial sketch of SparseTrie and StateSparseTrie representing partially loaded Ethereum state trie.

@rkrasiuk rkrasiuk added C-enhancement New feature or request A-trie Related to Merkle Patricia Trie implementation labels Oct 15, 2024
@rkrasiuk rkrasiuk force-pushed the rkrasiuk/sparse-trie-impl branch 2 times, most recently from ad10200 to 476073e Compare October 15, 2024 09:58
Copy link
Collaborator

@shekhirin shekhirin 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 didn't notice any problems with the logic. Only questions and nits on comments and code organization.

crates/trie/sparse/src/state.rs Outdated Show resolved Hide resolved
crates/trie/sparse/src/state.rs Outdated Show resolved Hide resolved
crates/trie/sparse/src/state.rs Show resolved Hide resolved
crates/trie/sparse/src/state.rs Outdated Show resolved Hide resolved
crates/trie/sparse/src/state.rs Outdated Show resolved Hide resolved
crates/trie/sparse/src/trie.rs Show resolved Hide resolved
}

fn reveal_node_or_hash(&mut self, path: Nibbles, child: &[u8]) -> alloy_rlp::Result<()> {
if child.len() == B256::len_bytes() + 1 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we add a comment here that if the length is 33 bytes, then it's an RLP-encoded string, and we need to skip the first byte that is the length of the string

crates/trie/sparse/src/trie.rs Outdated Show resolved Hide resolved
crates/trie/sparse/src/trie.rs Outdated Show resolved Hide resolved
Comment on lines +258 to +272
if root_rlp.len() == B256::len_bytes() + 1 {
B256::from_slice(&root_rlp[1..])
} else {
Copy link
Collaborator

Choose a reason for hiding this comment

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

do you think it worths moving this to a separate function in alloy-trie? this happens often and it's not straight away obvious why is it needed

Copy link
Member Author

Choose a reason for hiding this comment

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

@rkrasiuk rkrasiuk added this pull request to the merge queue Oct 15, 2024
Merged via the queue into main with commit a235f72 Oct 15, 2024
40 checks passed
@rkrasiuk rkrasiuk deleted the rkrasiuk/sparse-trie-impl branch October 15, 2024 14:09
reymom pushed a commit to reymom/reth that referenced this pull request Oct 15, 2024
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-enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants