Skip to content

Commit

Permalink
chore: display more information on assertions (#40)
Browse files Browse the repository at this point in the history
* chore: display more information on assertions

* clippy
  • Loading branch information
rkrasiuk authored Sep 23, 2024
1 parent 0be764d commit b286769
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
11 changes: 8 additions & 3 deletions src/hash_builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl HashBuilder {

/// Adds a new leaf element and its value to the trie hash builder.
pub fn add_leaf(&mut self, key: Nibbles, value: &[u8]) {
assert!(key > self.key);
assert!(key > self.key, "add_leaf key {:?} self.key {:?}", key, self.key);
if !self.key.is_empty() {
self.update(&key);
}
Expand All @@ -122,7 +122,12 @@ impl HashBuilder {

/// Adds a new branch element and its hash to the trie hash builder.
pub fn add_branch(&mut self, key: Nibbles, value: B256, stored_in_database: bool) {
assert!(key > self.key || (self.key.is_empty() && key.is_empty()));
assert!(
key > self.key || (self.key.is_empty() && key.is_empty()),
"add_branch key {:?} self.key {:?}",
key,
self.key
);
if !self.key.is_empty() {
self.update(&key);
} else if key.is_empty() {
Expand Down Expand Up @@ -188,7 +193,7 @@ impl HashBuilder {

let common_prefix_len = succeeding.common_prefix_length(current.as_slice());
let len = cmp::max(preceding_len, common_prefix_len);
assert!(len < current.len());
assert!(len < current.len(), "len {} current.len {}", len, current.len());

trace!(
target: "trie::hash_builder",
Expand Down
12 changes: 9 additions & 3 deletions src/nodes/branch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl Decodable for BranchNode {
if !bytes.is_empty() {
return Err(alloy_rlp::Error::Custom("branch values not supported"));
}
debug_assert!(bytes.is_empty());
debug_assert!(bytes.is_empty(), "bytes {}", alloy_primitives::hex::encode(bytes));

Ok(Self { stack, state_mask })
}
Expand Down Expand Up @@ -265,8 +265,14 @@ impl BranchNodeCompact {
) -> Self {
let (state_mask, tree_mask, hash_mask) =
(state_mask.into(), tree_mask.into(), hash_mask.into());
assert!(tree_mask.is_subset_of(state_mask));
assert!(hash_mask.is_subset_of(state_mask));
assert!(
tree_mask.is_subset_of(state_mask),
"state mask: {state_mask:?} tree mask: {tree_mask:?}"
);
assert!(
hash_mask.is_subset_of(state_mask),
"state_mask {state_mask:?} hash_mask: {hash_mask:?}"
);
assert_eq!(hash_mask.count_ones() as usize, hashes.len());
Self { state_mask, tree_mask, hash_mask, hashes, root_hash }
}
Expand Down

0 comments on commit b286769

Please sign in to comment.