Skip to content

Commit

Permalink
fix: collect only n diff points
Browse files Browse the repository at this point in the history
  • Loading branch information
atanmarko committed Oct 4, 2024
1 parent efadbde commit 916d298
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion mpt_trie/src/debug_tools/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::fmt::{self, Debug};
use std::{fmt::Display, ops::Deref};

use ethereum_types::H256;
use log::warn;

use crate::utils::{get_segment_from_node_and_key_piece, TriePath};
use crate::{
Expand All @@ -18,6 +19,8 @@ use crate::{
utils::TrieNodeType,
};

const MAX_DIFF_POINTS_TO_COLLECT: usize = 10;

/// Get the key piece from the given node if applicable. Note that
/// [branch][`Node::Branch`]s have no [`Nibble`] directly associated with them.
fn get_key_piece_from_node<T: PartialTrie>(n: &Node<T>) -> Nibbles {
Expand Down Expand Up @@ -170,13 +173,26 @@ fn find_all_diff_points_between_tries(

find_all_diff_points_between_tries_rec(&state, &mut longest_states);

longest_states
let diff_points = longest_states
.into_iter()
.filter_map(|longest_state| {
longest_state
.longest_key_node_diff
.or(longest_state.longest_key_hash_diff)
})
.collect::<Vec<DiffPoint>>();

if diff_points.len() > MAX_DIFF_POINTS_TO_COLLECT {
warn!(
"More than {} diff points found, only collecting the first {}.",
diff_points.len(),
MAX_DIFF_POINTS_TO_COLLECT
);
}

diff_points
.into_iter()
.take(MAX_DIFF_POINTS_TO_COLLECT)
.collect()
}

Expand Down

0 comments on commit 916d298

Please sign in to comment.