55 clippy:: missing_errors_doc,
66 reason = "Found 1 occurrences after enabling the lint."
77) ]
8- #![ expect(
9- clippy:: needless_continue,
10- reason = "Found 1 occurrences after enabling the lint."
11- ) ]
128
139use firewood_storage:: {
14- Children , FileIoError , HashType , Hashable , IntoHashType , NibblesIterator , Path , PathComponent ,
15- PathIterItem , Preimage , TrieHash , ValueDigest ,
10+ Children , FileIoError , HashType , Hashable , IntoHashType , IntoSplitPath , PackedPathRef ,
11+ PartialPath , PathComponent , PathIterItem , Preimage , SplitPath , TrieHash , TriePath ,
12+ TriePathFromPackedBytes , ValueDigest ,
1613} ;
1714use thiserror:: Error ;
1815
19- use crate :: merkle:: { Key , Value } ;
16+ use crate :: merkle:: Value ;
2017
2118#[ derive( Debug , Error ) ]
2219#[ non_exhaustive]
@@ -84,7 +81,7 @@ pub enum ProofError {
8481/// A node in a proof.
8582pub struct ProofNode {
8683 /// The key this node is at. Each byte is a nibble.
87- pub key : Key ,
84+ pub key : PartialPath ,
8885 /// The length of the key prefix that is shared with the previous node.
8986 pub partial_len : usize ,
9087 /// None if the node does not have a value.
@@ -112,16 +109,22 @@ impl std::fmt::Debug for ProofNode {
112109}
113110
114111impl Hashable for ProofNode {
115- fn parent_prefix_path ( & self ) -> impl Iterator < Item = u8 > + Clone {
116- self . full_path ( ) . take ( self . partial_len )
112+ fn parent_prefix_path ( & self ) -> impl IntoSplitPath + ' _ {
113+ self . full_path ( )
114+ . into_split_path ( )
115+ . split_at ( self . partial_len )
116+ . 0
117117 }
118118
119- fn partial_path ( & self ) -> impl Iterator < Item = u8 > + Clone {
120- self . full_path ( ) . skip ( self . partial_len )
119+ fn partial_path ( & self ) -> impl IntoSplitPath + ' _ {
120+ self . full_path ( )
121+ . into_split_path ( )
122+ . split_at ( self . partial_len )
123+ . 1
121124 }
122125
123- fn full_path ( & self ) -> impl Iterator < Item = u8 > + Clone {
124- self . key . as_ref ( ) . iter ( ) . copied ( )
126+ fn full_path ( & self ) -> impl IntoSplitPath + ' _ {
127+ & self . key
125128 }
126129
127130 fn value_digest ( & self ) -> Option < ValueDigest < & [ u8 ] > > {
@@ -182,7 +185,7 @@ impl<T: ProofCollection + ?Sized> Proof<T> {
182185 key : K ,
183186 root_hash : & TrieHash ,
184187 ) -> Result < Option < ValueDigest < & [ u8 ] > > , ProofError > {
185- let key = Path ( NibblesIterator :: new ( key. as_ref ( ) ) . collect ( ) ) ;
188+ let key = PackedPathRef :: path_from_packed_bytes ( key. as_ref ( ) ) ;
186189
187190 let Some ( last_node) = self . 0 . as_ref ( ) . last ( ) else {
188191 return Err ( ProofError :: Empty ) ;
@@ -199,14 +202,14 @@ impl<T: ProofCollection + ?Sized> Proof<T> {
199202 // Assert that only nodes whose keys are an even number of nibbles
200203 // have a `value_digest`.
201204 #[ cfg( not( feature = "branch_factor_256" ) ) ]
202- if node. full_path ( ) . count ( ) % 2 != 0 && node. value_digest ( ) . is_some ( ) {
205+ if node. full_path ( ) . len ( ) % 2 != 0 && node. value_digest ( ) . is_some ( ) {
203206 return Err ( ProofError :: ValueAtOddNibbleLength ) ;
204207 }
205208
206209 if let Some ( next_node) = iter. peek ( ) {
207210 // Assert that every node's key is a prefix of `key`, except for the last node,
208211 // whose key can be equal to or a suffix of `key` in an exclusion proof.
209- if next_nibble ( node. full_path ( ) , key. iter ( ) . copied ( ) ) . is_none ( ) {
212+ if next_nibble ( node. full_path ( ) , key) . is_none ( ) {
210213 return Err ( ProofError :: ShouldBePrefixOfProvenKey ) ;
211214 }
212215
@@ -217,16 +220,14 @@ impl<T: ProofCollection + ?Sized> Proof<T> {
217220 return Err ( ProofError :: ShouldBePrefixOfNextKey ) ;
218221 } ;
219222
220- let next_nibble =
221- PathComponent :: try_new ( next_nibble) . ok_or ( ProofError :: ChildIndexOutOfBounds ) ?;
222223 expected_hash = node. children ( ) [ next_nibble]
223224 . as_ref ( )
224225 . ok_or ( ProofError :: NodeNotInTrie ) ?
225226 . clone ( ) ;
226227 }
227228 }
228229
229- if last_node. full_path ( ) . eq ( key. iter ( ) . copied ( ) ) {
230+ if last_node. full_path ( ) . path_eq ( & key) {
230231 return Ok ( last_node. value_digest ( ) ) ;
231232 }
232233
@@ -384,23 +385,18 @@ impl ProofCollection for EmptyProofCollection {
384385
385386/// Returns the next nibble in `c` after `b`.
386387/// Returns None if `b` is not a strict prefix of `c`.
387- fn next_nibble < B , C > ( b : B , c : C ) -> Option < u8 >
388+ fn next_nibble < B , C > ( b : B , c : C ) -> Option < PathComponent >
388389where
389- B : IntoIterator < Item = u8 > ,
390- C : IntoIterator < Item = u8 > ,
390+ B : IntoSplitPath ,
391+ C : IntoSplitPath ,
391392{
392- let b = b. into_iter ( ) ;
393- let mut c = c. into_iter ( ) ;
394-
395- // Check if b is a prefix of c
396- for b_item in b {
397- match c. next ( ) {
398- Some ( c_item) if b_item == c_item => continue ,
399- _ => return None ,
400- }
393+ let common = b
394+ . into_split_path ( )
395+ . longest_common_prefix ( c. into_split_path ( ) ) ;
396+ match ( common. a_suffix . split_first ( ) , common. b_suffix . split_first ( ) ) {
397+ ( None , Some ( ( next, _) ) ) => Some ( next) ,
398+ _ => None ,
401399 }
402-
403- c. next ( )
404400}
405401
406402fn verify_opt_value_digest (
0 commit comments