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

chore: display more information on assertions #40

Merged
merged 2 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
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: 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
Loading