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

Creating sub-tries now never hashes leaves #76

Merged
merged 2 commits into from
Mar 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions mpt_trie/src/trie_subsets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ fn mark_nodes_that_are_needed<N: PartialTrie>(
return Err(SubsetTrieError::UnexpectedKey(
*curr_nibbles,
format!("{:?}", trie),
))
));
}
true => {
trie.info.touched = true;
Expand Down Expand Up @@ -316,10 +316,7 @@ fn mark_nodes_that_are_needed<N: PartialTrie>(
}
}
TrackedNodeIntern::Leaf => {
let (k, _) = trie.info.get_leaf_nibbles_and_value_expected();
if k == curr_nibbles {
trie.info.touched = true;
}
trie.info.touched = true;
}
}

Expand Down Expand Up @@ -719,14 +716,14 @@ mod tests {
}

#[test]
fn sub_trie_for_non_existent_key_that_hits_branch_leaf_hashes_out_leaf() {
fn sub_trie_for_non_existent_key_that_hits_branch_leaf_does_not_hash_out_leaf() {
common_setup();

let trie = create_trie_with_large_entry_nodes(&[0x1234, 0x1234589, 0x12346]);
let partial_trie = create_trie_subset(&trie, [0x1234567]).unwrap();

// Note that `0x1234589` gets hashed at the branch slot at `0x12345`.
assert_nodes_are_hash_nodes(&partial_trie, [0x12345, 0x12346]);
assert_nodes_are_hash_nodes(&partial_trie, Vec::<Nibbles>::default());
}

#[test]
Expand Down