Skip to content

Commit

Permalink
refactor(debug): simplify trie updates comparison logic
Browse files Browse the repository at this point in the history
- Removing redundant match patterns and nested code blocks
- Improving warning messages to show the number of mismatched entries
  • Loading branch information
bendanzhentan committed Dec 23, 2024
1 parent 6e14010 commit 32f9e79
Showing 1 changed file with 14 additions and 24 deletions.
38 changes: 14 additions & 24 deletions bin/reth/src/commands/debug_cmd/in_memory_merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,33 +203,23 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
// Compare updates
let mut in_mem_mismatched = Vec::new();
let mut incremental_mismatched = Vec::new();
let mut in_mem_updates_iter = in_memory_updates.account_nodes_ref().iter().peekable();
let mut incremental_updates_iter =
incremental_trie_updates.account_nodes_ref().iter().peekable();

while in_mem_updates_iter.peek().is_some() || incremental_updates_iter.peek().is_some() {
match (in_mem_updates_iter.next(), incremental_updates_iter.next()) {
(Some(in_mem), Some(incr)) => {
similar_asserts::assert_eq!(in_mem.0, incr.0, "Nibbles don't match");
if in_mem.1 != incr.1 &&
in_mem.0.len() > self.skip_node_depth.unwrap_or_default()
{
in_mem_mismatched.push(in_mem);
incremental_mismatched.push(incr);
}
}
(Some(in_mem), None) => {
warn!(target: "reth::cli", next = ?in_mem, "In-memory trie updates have more entries");
}
(None, Some(incr)) => {
tracing::warn!(target: "reth::cli", next = ?incr, "Incremental trie updates have more entries");
}
(None, None) => {
tracing::info!(target: "reth::cli", "Exhausted all trie updates entries");
}
let in_mem_updates_iter = in_memory_updates.account_nodes_ref().iter();
let incremental_updates_iter = incremental_trie_updates.account_nodes_ref().iter();

for (in_mem, incr) in in_mem_updates_iter.zip(incremental_updates_iter) {
similar_asserts::assert_eq!(in_mem.0, incr.0, "Nibbles don't match");
if in_mem.1 != incr.1 && in_mem.0.len() > self.skip_node_depth.unwrap_or_default() {
in_mem_mismatched.push(in_mem);
incremental_mismatched.push(incr);
}
}

if !in_mem_mismatched.is_empty() {
warn!(target: "reth::cli", "In-memory trie updates have {} more entries", in_mem_mismatched.len());
} else if !incremental_mismatched.is_empty() {
warn!(target: "reth::cli", "Incremental trie updates have {} more entries", incremental_mismatched.len());
}

similar_asserts::assert_eq!(
incremental_mismatched,
in_mem_mismatched,
Expand Down

0 comments on commit 32f9e79

Please sign in to comment.