diff --git a/mpt_trie/src/debug_tools/diff.rs b/mpt_trie/src/debug_tools/diff.rs index b2ba6dd8e..c6a8458db 100644 --- a/mpt_trie/src/debug_tools/diff.rs +++ b/mpt_trie/src/debug_tools/diff.rs @@ -41,7 +41,7 @@ use crate::{ /// [branch][`Node::Branch`]s have no [`Nibble`] directly associated with them. fn get_key_piece_from_node(n: &Node) -> Nibbles { match n { - Node::Empty | Node::Hash(_) | Node::Branch { .. } => Nibbles::empty(), + Node::Empty | Node::Hash(_) | Node::Branch { .. } => Nibbles::default(), Node::Extension { nibbles, child: _ } | Node::Leaf { nibbles, value: _ } => *nibbles, } } @@ -187,7 +187,7 @@ fn find_latest_diff_point_between_tries( a: &HashedPartialTrie, b: &HashedPartialTrie, ) -> Option { - let state = DepthDiffPerCallState::new(a, b, Nibbles::empty(), 0); + let state = DepthDiffPerCallState::new(a, b, Nibbles::default(), 0); let mut longest_state = DepthNodeDiffState::default(); find_latest_diff_point_between_tries_rec(&state, &mut longest_state); @@ -327,7 +327,7 @@ fn find_latest_diff_point_between_tries_rec( create_diff_detection_state_based_from_hashes( a_hash, b_hash, - &state.new_from_parent(state.a, state.b, &Nibbles::empty()), + &state.new_from_parent(state.a, state.b, &Nibbles::default()), depth_state, ) } @@ -461,7 +461,7 @@ mod tests { let expected = DiffPoint { depth: 0, path: TriePath(vec![]), - key: Nibbles::empty(), + key: Nibbles::default(), a_info: expected_a, b_info: expected_b, }; diff --git a/mpt_trie/src/debug_tools/query.rs b/mpt_trie/src/debug_tools/query.rs index 402784523..753900262 100644 --- a/mpt_trie/src/debug_tools/query.rs +++ b/mpt_trie/src/debug_tools/query.rs @@ -23,7 +23,7 @@ fn get_key_piece_from_node_pulling_from_key_for_branches( curr_key: &Nibbles, ) -> Nibbles { match n { - Node::Empty | Node::Hash(_) => Nibbles::empty(), + Node::Empty | Node::Hash(_) => Nibbles::default(), Node::Branch { .. } => curr_key.get_next_nibbles(1), Node::Extension { nibbles, child: _ } | Node::Leaf { nibbles, value: _ } => *nibbles, } diff --git a/mpt_trie/src/nibbles.rs b/mpt_trie/src/nibbles.rs index bbb08bb22..86d69670e 100644 --- a/mpt_trie/src/nibbles.rs +++ b/mpt_trie/src/nibbles.rs @@ -327,7 +327,7 @@ impl Debug for Nibbles { /// cleaner to instead call [`Nibbles::empty`] explicitly. impl Default for Nibbles { fn default() -> Self { - Self::empty() + Self::new() } } @@ -367,7 +367,7 @@ impl Nibbles { /// /// Note that mean that the key size is `0` and does not mean that the key /// contains the `0` [`Nibble`]. - pub fn empty() -> Self { + pub fn new() -> Self { Self { count: 0, packed: NibblesIntern::default(), @@ -1145,7 +1145,7 @@ mod tests { #[test] fn push_nibble_front_works() { - test_and_assert_nib_push_func(Nibbles::empty(), 0x1, |n| n.push_nibble_front(0x1)); + test_and_assert_nib_push_func(Nibbles::default(), 0x1, |n| n.push_nibble_front(0x1)); test_and_assert_nib_push_func(0x1, 0x21, |n| n.push_nibble_front(0x2)); test_and_assert_nib_push_func( Nibbles::from_str(ZERO_NIBS_63).unwrap(), @@ -1156,7 +1156,7 @@ mod tests { #[test] fn push_nibble_back_works() { - test_and_assert_nib_push_func(Nibbles::empty(), 0x1, |n| n.push_nibble_back(0x1)); + test_and_assert_nib_push_func(Nibbles::default(), 0x1, |n| n.push_nibble_back(0x1)); test_and_assert_nib_push_func(0x1, 0x12, |n| n.push_nibble_back(0x2)); test_and_assert_nib_push_func( Nibbles::from_str(ZERO_NIBS_63).unwrap(), @@ -1167,7 +1167,7 @@ mod tests { #[test] fn push_nibbles_front_works() { - test_and_assert_nib_push_func(Nibbles::empty(), 0x1234, |n| { + test_and_assert_nib_push_func(Nibbles::default(), 0x1234, |n| { n.push_nibbles_front(&0x1234.into()) }); test_and_assert_nib_push_func(0x1234, 0x5671234, |n| n.push_nibbles_front(&0x567.into())); @@ -1180,7 +1180,7 @@ mod tests { #[test] fn push_nibbles_back_works() { - test_and_assert_nib_push_func(Nibbles::empty(), 0x1234, |n| { + test_and_assert_nib_push_func(Nibbles::default(), 0x1234, |n| { n.push_nibbles_back(&0x1234.into()) }); test_and_assert_nib_push_func(0x1234, 0x1234567, |n| n.push_nibbles_back(&0x567.into())); @@ -1206,13 +1206,13 @@ mod tests { fn get_next_nibbles_works() -> Result<(), StrToNibblesError> { let n: Nibbles = 0x1234.into(); - assert_eq!(n.get_next_nibbles(0), Nibbles::empty()); + assert_eq!(n.get_next_nibbles(0), Nibbles::default()); assert_eq!(n.get_next_nibbles(1), Nibbles::from(0x1)); assert_eq!(n.get_next_nibbles(2), Nibbles::from(0x12)); assert_eq!(n.get_next_nibbles(3), Nibbles::from(0x123)); assert_eq!(n.get_next_nibbles(4), Nibbles::from(0x1234)); - assert_eq!(Nibbles::from(0x0).get_next_nibbles(0), Nibbles::empty()); + assert_eq!(Nibbles::from(0x0).get_next_nibbles(0), Nibbles::default()); let n = Nibbles::from_str( "0x3ab76c381c0f8ea617ea96780ffd1e165c754b28a41a95922f9f70682c581353", diff --git a/mpt_trie/src/special_query.rs b/mpt_trie/src/special_query.rs index c0dbb4453..c133a6091 100644 --- a/mpt_trie/src/special_query.rs +++ b/mpt_trie/src/special_query.rs @@ -157,13 +157,13 @@ mod test { TrieSegment::Branch(2), TrieSegment::Extension(Nibbles::from_str("0x00").unwrap()), TrieSegment::Branch(0x1), - TrieSegment::Leaf(Nibbles::empty()), + TrieSegment::Leaf(Nibbles::default()), ], vec![ TrieSegment::Branch(2), TrieSegment::Extension(Nibbles::from_str("0x00").unwrap()), TrieSegment::Branch(0x2), - TrieSegment::Leaf(Nibbles::empty()), + TrieSegment::Leaf(Nibbles::default()), ], ]; diff --git a/mpt_trie/src/trie_ops.rs b/mpt_trie/src/trie_ops.rs index 9cc158103..b06dc0e79 100644 --- a/mpt_trie/src/trie_ops.rs +++ b/mpt_trie/src/trie_ops.rs @@ -253,7 +253,7 @@ impl Iterator for PartialTrieIter { next_iter_item = match stack_entry { IterStackEntry::Root(root) => { - self.advance_iter_to_next_empty_leaf_or_hash_node(&root, Nibbles::empty()) + self.advance_iter_to_next_empty_leaf_or_hash_node(&root, Nibbles::default()) } IterStackEntry::Extension(num_nibbles) => { // Drop nibbles that extension added since we are going back up the trie. @@ -389,7 +389,7 @@ impl Node { // Final check at the root if we have an extension node. While this check also // exists as we recursively traverse down the trie, it can not perform this // check on the root node. - let wrapped_node = try_collapse_if_extension(updated_root, &Nibbles::empty())?; + let wrapped_node = try_collapse_if_extension(updated_root, &Nibbles::default())?; let node_ref: &Node = &wrapped_node; *self = node_ref.clone(); @@ -399,7 +399,7 @@ impl Node { pub(crate) fn trie_items(&self) -> impl Iterator { PartialTrieIter { - curr_key_after_last_branch: Nibbles::empty(), + curr_key_after_last_branch: Nibbles::default(), trie_stack: vec![IterStackEntry::Root(self.clone().into())], } } diff --git a/mpt_trie/src/trie_subsets.rs b/mpt_trie/src/trie_subsets.rs index b8e9cbf23..d83d7f8ea 100644 --- a/mpt_trie/src/trie_subsets.rs +++ b/mpt_trie/src/trie_subsets.rs @@ -439,7 +439,7 @@ mod tests { return_on_empty_or_hash: bool, ) -> Vec { let mut nodes = Vec::new(); - get_nodes_in_trie_intern_rec(trie, Nibbles::empty(), &mut nodes, return_on_empty_or_hash); + get_nodes_in_trie_intern_rec(trie, Nibbles::default(), &mut nodes, return_on_empty_or_hash); nodes } @@ -561,7 +561,7 @@ mod tests { assert_node_exists( &all_non_empty_and_hash_nodes, TrieNodeType::Branch, - Nibbles::empty(), + Nibbles::default(), ); assert_node_exists(&all_non_empty_and_hash_nodes, TrieNodeType::Branch, 0x1); assert_node_exists(&all_non_empty_and_hash_nodes, TrieNodeType::Leaf, 0x1234); @@ -588,7 +588,7 @@ mod tests { assert_node_exists( &all_non_empty_and_hash_nodes_partial, TrieNodeType::Branch, - Nibbles::empty(), + Nibbles::default(), ); assert_node_exists( &all_non_empty_and_hash_nodes_partial, @@ -613,7 +613,7 @@ mod tests { assert_node_exists( &all_non_empty_and_hash_nodes_partial, TrieNodeType::Branch, - Nibbles::empty(), + Nibbles::default(), ); assert_node_exists( &all_non_empty_and_hash_nodes_partial, diff --git a/mpt_trie/src/utils.rs b/mpt_trie/src/utils.rs index 531d96d0e..5d530878e 100644 --- a/mpt_trie/src/utils.rs +++ b/mpt_trie/src/utils.rs @@ -109,7 +109,7 @@ pub trait IntoTrieKey { impl, T: Iterator> IntoTrieKey for T { fn into_key(self) -> Nibbles { - let mut key = Nibbles::empty(); + let mut key = Nibbles::default(); for seg in self { match seg.borrow() {