Skip to content
Merged
Changes from 3 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
34 changes: 14 additions & 20 deletions crates/trie/sparse/src/trie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -969,24 +969,6 @@ impl SparseTrieInterface for SerialSparseTrie {
full_path: &Nibbles,
expected_value: Option<&Vec<u8>>,
) -> Result<LeafLookup, LeafLookupError> {
// Helper function to check if a value matches the expected value
fn check_value_match(
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 just add an #[inline] attribute here? It doesn't clone the value unless the error is returned anyway, as @mediocregopher said.

actual_value: &Vec<u8>,
expected_value: Option<&Vec<u8>>,
path: &Nibbles,
) -> Result<(), LeafLookupError> {
if let Some(expected) = expected_value &&
actual_value != expected
{
return Err(LeafLookupError::ValueMismatch {
path: *path,
expected: Some(expected.clone()),
actual: actual_value.clone(),
});
}
Ok(())
}

let mut current = Nibbles::default(); // Start at the root

// Inclusion proof
Expand All @@ -996,7 +978,13 @@ impl SparseTrieInterface for SerialSparseTrie {
// be in the `values` map.
if let Some(actual_value) = self.values.get(full_path) {
// We found the leaf, check if the value matches (if expected value was provided)
check_value_match(actual_value, expected_value, full_path)?;
if expected_value.is_some_and(|expected| actual_value != expected) {
return Err(LeafLookupError::ValueMismatch {
path: *full_path,
expected: expected_value.cloned(),
actual: actual_value.clone(),
});
}
return Ok(LeafLookup::Exists);
}

Expand All @@ -1023,7 +1011,13 @@ impl SparseTrieInterface for SerialSparseTrie {
if &current == full_path {
// This should have been handled by our initial values map check
if let Some(value) = self.values.get(full_path) {
check_value_match(value, expected_value, full_path)?;
if expected_value.is_some_and(|expected| value != expected) {
return Err(LeafLookupError::ValueMismatch {
path: *full_path,
expected: expected_value.cloned(),
actual: value.clone(),
});
}
return Ok(LeafLookup::Exists);
}
}
Expand Down
Loading