From e762c0e8166bd8ab99d109c060360fba5ca2f50c Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Tue, 12 Mar 2024 13:43:35 -0400 Subject: [PATCH] rename node `path` fields to `partial_path` (#587) --- firewood/src/merkle.rs | 79 ++++++++++++++++-------------- firewood/src/merkle/node.rs | 30 +++++++----- firewood/src/merkle/node/branch.rs | 16 +++--- firewood/src/merkle/node/leaf.rs | 23 +++++---- firewood/src/merkle/proof.rs | 18 +++---- firewood/src/merkle/stream.rs | 28 +++++------ firewood/src/shale/mod.rs | 2 +- 7 files changed, 106 insertions(+), 90 deletions(-) diff --git a/firewood/src/merkle.rs b/firewood/src/merkle.rs index 412afa16e..d8c044296 100644 --- a/firewood/src/merkle.rs +++ b/firewood/src/merkle.rs @@ -118,7 +118,7 @@ where NodeType::Leaf(n) => EncodedNode::new(EncodedNodeType::Leaf(n.clone())), NodeType::Branch(n) => { - let path = n.path.clone(); + let path = n.partial_path.clone(); // pair up DiskAddresses with encoded children and pick the right one let encoded_children = n.chd().iter().zip(n.children_encoded.iter()); @@ -179,7 +179,7 @@ impl Merkle { self.store .put_item( Node::from_branch(BranchNode { - path: vec![].into(), + partial_path: vec![].into(), children: [None; BranchNode::MAX_CHILDREN], value: None, children_encoded: Default::default(), @@ -310,7 +310,7 @@ impl Merkle { .chain(key_nibbles.clone()) .collect::>(); - let overlap = PrefixOverlap::from(&n.path, &key_remainder); + let overlap = PrefixOverlap::from(&n.partial_path, &key_remainder); #[allow(clippy::indexing_slicing)] match (overlap.unique_a.len(), overlap.unique_b.len()) { @@ -341,7 +341,7 @@ impl Merkle { children[new_leaf_index as usize] = Some(new_leaf); let new_branch = BranchNode { - path: PartialPath(overlap.shared.to_vec()), + partial_path: PartialPath(overlap.shared.to_vec()), children, value: n.data.clone().into(), children_encoded: Default::default(), @@ -374,7 +374,7 @@ impl Merkle { .as_ptr(); let mut new_branch = BranchNode { - path: PartialPath(new_branch_path), + partial_path: PartialPath(new_branch_path), children: [None; BranchNode::MAX_CHILDREN], value: Some(val.into()), children_encoded: Default::default(), @@ -418,7 +418,7 @@ impl Merkle { let new_leaf = self.put_node(new_leaf)?.as_ptr(); let mut new_branch = BranchNode { - path: PartialPath(new_branch_path), + partial_path: PartialPath(new_branch_path), children: [None; BranchNode::MAX_CHILDREN], value: None, children_encoded: Default::default(), @@ -437,7 +437,7 @@ impl Merkle { break None; } - NodeType::Branch(n) if n.path.len() == 0 => { + NodeType::Branch(n) if n.partial_path.len() == 0 => { #[allow(clippy::indexing_slicing)] match n.children[next_nibble as usize] { Some(c) => (node, c), @@ -470,7 +470,7 @@ impl Merkle { .chain(key_nibbles.clone()) .collect::>(); - let overlap = PrefixOverlap::from(&n.path, &key_remainder); + let overlap = PrefixOverlap::from(&n.partial_path, &key_remainder); #[allow(clippy::indexing_slicing)] match (overlap.unique_a.len(), overlap.unique_b.len()) { @@ -537,7 +537,7 @@ impl Merkle { .as_ptr(); let mut new_branch = BranchNode { - path: PartialPath(new_branch_path), + partial_path: PartialPath(new_branch_path), children: [None; BranchNode::MAX_CHILDREN], value: Some(val.into()), children_encoded: Default::default(), @@ -583,7 +583,7 @@ impl Merkle { let new_leaf = self.put_node(new_leaf)?.as_ptr(); let mut new_branch = BranchNode { - path: PartialPath(new_branch_path), + partial_path: PartialPath(new_branch_path), children: [None; BranchNode::MAX_CHILDREN], value: None, children_encoded: Default::default(), @@ -623,15 +623,15 @@ impl Merkle { None } NodeType::Leaf(n) => { - if n.path.len() == 0 { + if n.partial_path.len() == 0 { n.data = Data(val); None } else { #[allow(clippy::indexing_slicing)] - let idx = n.path[0]; + let idx = n.partial_path[0]; #[allow(clippy::indexing_slicing)] - (n.path = PartialPath(n.path[1..].to_vec())); + (n.partial_path = PartialPath(n.partial_path[1..].to_vec())); u.rehash(); Some((idx, true, None, val)) @@ -664,7 +664,7 @@ impl Merkle { let branch = self .put_node(Node::from_branch(BranchNode { - path: vec![].into(), + partial_path: vec![].into(), children: chd, value: Some(Data(val)), children_encoded: Default::default(), @@ -714,7 +714,7 @@ impl Merkle { // don't change the sentinal node if children.len() == 1 && !parents.is_empty() { - let branch_path = &branch.path.0; + let branch_path = &branch.partial_path.0; #[allow(clippy::indexing_slicing)] let (child_index, child) = children[0]; @@ -774,7 +774,7 @@ impl Merkle { match (children.len(), &branch.value, !parents.is_empty()) { // node is invalid, all single-child nodes should have data (1, None, true) => { - let parent_path = &branch.path.0; + let parent_path = &branch.partial_path.0; #[allow(clippy::indexing_slicing)] let (child_index, child) = children[0]; @@ -790,10 +790,10 @@ impl Merkle { .iter() .copied() .chain(once(child_index as u8)) - .chain(child.path.0.iter().copied()) + .chain(child.partial_path.0.iter().copied()) .collect(); - child.path = PartialPath(path); + child.partial_path = PartialPath(path); Node::from_branch(child) } @@ -802,10 +802,10 @@ impl Merkle { .iter() .copied() .chain(once(child_index as u8)) - .chain(child.path.0.iter().copied()) + .chain(child.partial_path.0.iter().copied()) .collect(); - child.path = PartialPath(path); + child.partial_path = PartialPath(path); Node::from_leaf(child) } @@ -821,7 +821,7 @@ impl Merkle { // branch nodes shouldn't have no children (0, Some(data), true) => { let leaf = Node::from_leaf(LeafNode::new( - PartialPath(branch.path.0.clone()), + PartialPath(branch.partial_path.0.clone()), data.clone(), )); @@ -958,12 +958,14 @@ impl Merkle { let next_ptr = match &node_ref.inner { #[allow(clippy::indexing_slicing)] - NodeType::Branch(n) if n.path.len() == 0 => match n.children[nib as usize] { - Some(c) => c, - None => return Ok(None), - }, + NodeType::Branch(n) if n.partial_path.len() == 0 => { + match n.children[nib as usize] { + Some(c) => c, + None => return Ok(None), + } + } NodeType::Branch(n) => { - let mut n_path_iter = n.path.iter().copied(); + let mut n_path_iter = n.partial_path.iter().copied(); if n_path_iter.next() != Some(nib) { return Ok(None); @@ -994,7 +996,10 @@ impl Merkle { } } NodeType::Leaf(n) => { - let node_ref = if once(nib).chain(key_nibbles).eq(n.path.iter().copied()) { + let node_ref = if once(nib) + .chain(key_nibbles) + .eq(n.partial_path.iter().copied()) + { Some(node_ref) } else { None @@ -1011,10 +1016,10 @@ impl Merkle { // when we're done iterating over nibbles, check if the node we're at has a value let node_ref = match &node_ref.inner { - NodeType::Branch(n) if n.value.as_ref().is_some() && n.path.is_empty() => { + NodeType::Branch(n) if n.value.as_ref().is_some() && n.partial_path.is_empty() => { Some(node_ref) } - NodeType::Leaf(n) if n.path.len() == 0 => Some(node_ref), + NodeType::Leaf(n) if n.partial_path.len() == 0 => Some(node_ref), _ => None, }; @@ -1461,7 +1466,7 @@ mod tests { } Node::from_branch(BranchNode { - path, + partial_path: path, children, value, children_encoded, @@ -1483,7 +1488,7 @@ mod tests { } Node::from_branch(BranchNode { - path, + partial_path: path, children, value, children_encoded, @@ -2084,7 +2089,7 @@ mod tests { .collect::>(); let node = Node::from_leaf(LeafNode { - path: PartialPath::from(path), + partial_path: PartialPath::from(path), data: Data(data.clone()), }); @@ -2103,7 +2108,7 @@ mod tests { .collect::>(); let node = Node::from_leaf(LeafNode { - path: PartialPath::from(path.clone()), + partial_path: PartialPath::from(path.clone()), data: Data(data), }); @@ -2122,7 +2127,7 @@ mod tests { .collect::>(); let node = Node::from_branch(BranchNode { - path: PartialPath::from(path.clone()), + partial_path: PartialPath::from(path.clone()), children: Default::default(), value: Some(Data(data.clone())), children_encoded: Default::default(), @@ -2143,7 +2148,7 @@ mod tests { .collect::>(); let node = Node::from_branch(BranchNode { - path: PartialPath::from(path.clone()), + partial_path: PartialPath::from(path.clone()), children: Default::default(), value: Some(Data(data)), children_encoded: Default::default(), @@ -2187,8 +2192,8 @@ mod tests { assert_eq!(&to_delete[0], &addr); let (path, data) = match node.inner() { - NodeType::Leaf(leaf) => (&leaf.path, Some(&leaf.data)), - NodeType::Branch(branch) => (&branch.path, branch.value.as_ref()), + NodeType::Leaf(leaf) => (&leaf.partial_path, Some(&leaf.data)), + NodeType::Branch(branch) => (&branch.partial_path, branch.value.as_ref()), }; assert_eq!(path, &PartialPath(new_path)); diff --git a/firewood/src/merkle/node.rs b/firewood/src/merkle/node.rs index 9177c9db8..1b03a3c06 100644 --- a/firewood/src/merkle/node.rs +++ b/firewood/src/merkle/node.rs @@ -112,15 +112,15 @@ impl NodeType { pub fn path_mut(&mut self) -> &mut PartialPath { match self { - NodeType::Branch(u) => &mut u.path, - NodeType::Leaf(node) => &mut node.path, + NodeType::Branch(u) => &mut u.partial_path, + NodeType::Leaf(node) => &mut node.partial_path, } } pub fn set_path(&mut self, path: PartialPath) { match self { - NodeType::Branch(u) => u.path = path, - NodeType::Leaf(node) => node.path = path, + NodeType::Branch(u) => u.partial_path = path, + NodeType::Leaf(node) => node.partial_path = path, } } @@ -210,7 +210,7 @@ impl Node { is_encoded_longer_than_hash_len: OnceLock::new(), inner: NodeType::Branch( BranchNode { - path: vec![].into(), + partial_path: vec![].into(), children: [Some(DiskAddress::null()); BranchNode::MAX_CHILDREN], value: Some(Data(Vec::new())), children_encoded: Default::default(), @@ -524,7 +524,7 @@ impl Serialize for EncodedNode { EncodedNodeType::Leaf(n) => { let data = Some(&*n.data); let chd: Vec<(u64, Vec)> = Default::default(); - let path: Vec<_> = from_nibbles(&n.path.encode()).collect(); + let path: Vec<_> = from_nibbles(&n.partial_path.encode()).collect(); (chd, data, path) } @@ -580,7 +580,10 @@ impl<'de> Deserialize<'de> for EncodedNode { Data(Vec::new()) }; - let node = EncodedNodeType::Leaf(LeafNode { path, data }); + let node = EncodedNodeType::Leaf(LeafNode { + partial_path: path, + data, + }); Ok(Self::new(node)) } else { @@ -608,7 +611,10 @@ impl Serialize for EncodedNode { fn serialize(&self, serializer: S) -> Result { match &self.node { EncodedNodeType::Leaf(n) => { - let list = [from_nibbles(&n.path.encode()).collect(), n.data.to_vec()]; + let list = [ + from_nibbles(&n.partial_path.encode()).collect(), + n.data.to_vec(), + ]; let mut seq = serializer.serialize_seq(Some(list.len()))?; for e in list { seq.serialize_element(&e)?; @@ -681,7 +687,7 @@ impl<'de> Deserialize<'de> for EncodedNode { }; let path = PartialPath::from_nibbles(Nibbles::<0>::new(&path).into_iter()); let node = EncodedNodeType::Leaf(LeafNode { - path, + partial_path: path, data: Data(data), }); Ok(Self::new(node)) @@ -828,7 +834,7 @@ mod tests { ) { let leaf = NodeType::Leaf(LeafNode::new(PartialPath(vec![1, 2, 3]), Data(vec![4, 5]))); let branch = NodeType::Branch(Box::new(BranchNode { - path: vec![].into(), + partial_path: vec![].into(), children: [Some(DiskAddress::from(1)); BranchNode::MAX_CHILDREN], value: Some(Data(vec![1, 2, 3])), children_encoded: std::array::from_fn(|_| Some(vec![1])), @@ -912,7 +918,7 @@ mod tests { value: impl Into>, children_encoded: [Option>; BranchNode::MAX_CHILDREN], ) { - let path = PartialPath(path.iter().copied().map(|x| x & 0xf).collect()); + let partial_path = PartialPath(path.iter().copied().map(|x| x & 0xf).collect()); let mut children = children.into_iter().map(|x| { if x == 0 { @@ -929,7 +935,7 @@ mod tests { .map(|x| Data(std::iter::repeat(x).take(x as usize).collect())); let node = Node::from_branch(BranchNode { - path, + partial_path, children, value, children_encoded, diff --git a/firewood/src/merkle/node/branch.rs b/firewood/src/merkle/node/branch.rs index da1b5341a..dbccbff4a 100644 --- a/firewood/src/merkle/node/branch.rs +++ b/firewood/src/merkle/node/branch.rs @@ -23,7 +23,7 @@ const MAX_CHILDREN: usize = 16; #[derive(PartialEq, Eq, Clone)] pub struct BranchNode { - pub(crate) path: PartialPath, + pub(crate) partial_path: PartialPath, pub(crate) children: [Option; MAX_CHILDREN], pub(crate) value: Option, pub(crate) children_encoded: [Option>; MAX_CHILDREN], @@ -32,7 +32,7 @@ pub struct BranchNode { impl Debug for BranchNode { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), FmtError> { write!(f, "[Branch")?; - write!(f, r#" path="{:?}""#, self.path)?; + write!(f, r#" path="{:?}""#, self.partial_path)?; for (i, c) in self.children.iter().enumerate() { if let Some(c) = c { @@ -62,13 +62,13 @@ impl BranchNode { pub const MSIZE: usize = Self::MAX_CHILDREN + 2; pub fn new( - path: PartialPath, + partial_path: PartialPath, chd: [Option; Self::MAX_CHILDREN], value: Option>, chd_encoded: [Option>; Self::MAX_CHILDREN], ) -> Self { BranchNode { - path, + partial_path, children: chd, value: value.map(Data), children_encoded: chd_encoded, @@ -176,7 +176,7 @@ impl BranchNode { } #[allow(clippy::unwrap_used)] - let path = from_nibbles(&self.path.encode()).collect::>(); + let path = from_nibbles(&self.partial_path.encode()).collect::>(); list[Self::MAX_CHILDREN + 1] = path; @@ -194,7 +194,7 @@ impl Storable for BranchNode { len + optional_data_len::(child.as_ref()) }); let path_len_size = size_of::() as u64; - let path_len = self.path.serialized_len(); + let path_len = self.partial_path.serialized_len(); children_len + data_len + children_encoded_len + path_len_size + path_len } @@ -202,7 +202,7 @@ impl Storable for BranchNode { fn serialize(&self, to: &mut [u8]) -> Result<(), crate::shale::ShaleError> { let mut cursor = Cursor::new(to); - let path: Vec = from_nibbles(&self.path.encode()).collect(); + let path: Vec = from_nibbles(&self.partial_path.encode()).collect(); cursor.write_all(&[path.len() as PathLen])?; cursor.write_all(&path)?; @@ -358,7 +358,7 @@ impl Storable for BranchNode { } let node = BranchNode { - path, + partial_path: path, children, value, children_encoded, diff --git a/firewood/src/merkle/node/leaf.rs b/firewood/src/merkle/node/leaf.rs index 905cf2b4c..d18d06eaf 100644 --- a/firewood/src/merkle/node/leaf.rs +++ b/firewood/src/merkle/node/leaf.rs @@ -22,26 +22,31 @@ type DataLen = u32; #[derive(PartialEq, Eq, Clone)] pub struct LeafNode { - pub(crate) path: PartialPath, + pub(crate) partial_path: PartialPath, pub(crate) data: Data, } impl Debug for LeafNode { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), FmtError> { - write!(f, "[Leaf {:?} {}]", self.path, hex::encode(&*self.data)) + write!( + f, + "[Leaf {:?} {}]", + self.partial_path, + hex::encode(&*self.data) + ) } } impl LeafNode { - pub fn new, D: Into>(path: P, data: D) -> Self { + pub fn new, D: Into>(partial_path: P, data: D) -> Self { Self { - path: path.into(), + partial_path: partial_path.into(), data: data.into(), } } pub const fn path(&self) -> &PartialPath { - &self.path + &self.partial_path } pub const fn data(&self) -> &Data { @@ -53,7 +58,7 @@ impl LeafNode { bincode::DefaultOptions::new() .serialize( [ - from_nibbles(&self.path.encode()).collect(), + from_nibbles(&self.partial_path.encode()).collect(), self.data.to_vec(), ] .as_slice(), @@ -76,7 +81,7 @@ impl Meta { impl Storable for LeafNode { fn serialized_len(&self) -> u64 { let meta_len = size_of::() as u64; - let path_len = self.path.serialized_len(); + let path_len = self.partial_path.serialized_len(); let data_len = self.data.len() as u64; meta_len + path_len + data_len @@ -85,11 +90,11 @@ impl Storable for LeafNode { fn serialize(&self, to: &mut [u8]) -> Result<(), crate::shale::ShaleError> { let mut cursor = Cursor::new(to); - let path = &self.path.encode(); + let path = &self.partial_path.encode(); let path = from_nibbles(path); let data = &self.data; - let path_len = self.path.serialized_len() as PathLen; + let path_len = self.partial_path.serialized_len() as PathLen; let data_len = data.len() as DataLen; let meta = Meta { path_len, data_len }; diff --git a/firewood/src/merkle/proof.rs b/firewood/src/merkle/proof.rs index 4709e5987..5f9f5fe46 100644 --- a/firewood/src/merkle/proof.rs +++ b/firewood/src/merkle/proof.rs @@ -333,7 +333,7 @@ impl + Send> Proof { let encoded_sub_proof = match child_node.inner() { NodeType::Leaf(n) => { break n - .path + .partial_path .iter() .copied() .eq(key_nibbles) // all nibbles have to match @@ -342,7 +342,7 @@ impl + Send> Proof { NodeType::Branch(n) => { let paths_match = n - .path + .partial_path .iter() .copied() .all(|nibble| Some(nibble) == key_nibbles.next()); @@ -420,7 +420,7 @@ fn locate_subproof( Ok((sub_proof.into(), key_nibbles)) } NodeType::Branch(n) => { - let partial_path = &n.path.0; + let partial_path = &n.partial_path.0; let does_not_match = key_nibbles.size_hint().0 < partial_path.len() || !partial_path @@ -518,7 +518,7 @@ where NodeType::Branch(n) => { // If either the key of left proof or right proof doesn't match with // stop here, this is the forkpoint. - let path = &*n.path; + let path = &*n.partial_path; if !path.is_empty() { [fork_left, fork_right] = [&left_chunks[index..], &right_chunks[index..]] @@ -552,7 +552,7 @@ where #[allow(clippy::indexing_slicing)] NodeType::Leaf(n) => { - let path = &*n.path; + let path = &*n.partial_path; [fork_left, fork_right] = [&left_chunks[index..], &right_chunks[index..]] .map(|chunks| chunks.chunks(path.len()).next().unwrap_or_default()) @@ -597,7 +597,7 @@ where } let p = u_ref.as_ptr(); - index += n.path.len(); + index += n.partial_path.len(); // Only one proof points to non-existent key. if fork_right.is_ne() { @@ -741,8 +741,8 @@ fn unset_node_ref, S: CachedStore, T: BinarySerde>( #[allow(clippy::indexing_slicing)] match &u_ref.inner() { - NodeType::Branch(n) if chunks[index..].starts_with(&n.path) => { - let index = index + n.path.len(); + NodeType::Branch(n) if chunks[index..].starts_with(&n.partial_path) => { + let index = index + n.partial_path.len(); let child_index = chunks[index] as usize; let node = n.chd()[child_index]; @@ -772,7 +772,7 @@ fn unset_node_ref, S: CachedStore, T: BinarySerde>( } NodeType::Branch(n) => { - let cur_key = &n.path; + let cur_key = &n.partial_path; // Find the fork point, it's a non-existent branch. // diff --git a/firewood/src/merkle/stream.rs b/firewood/src/merkle/stream.rs index 6f8ce6cca..18ad4fc62 100644 --- a/firewood/src/merkle/stream.rs +++ b/firewood/src/merkle/stream.rs @@ -146,8 +146,8 @@ impl<'a, S: CachedStore, T> Stream for MerkleNodeStream<'a, S, T> { let child = merkle.get_node(child_addr)?; let partial_path = match child.inner() { - NodeType::Branch(branch) => branch.path.iter().copied(), - NodeType::Leaf(leaf) => leaf.path.iter().copied(), + NodeType::Branch(branch) => branch.partial_path.iter().copied(), + NodeType::Leaf(leaf) => leaf.partial_path.iter().copied(), }; // The child's key is its parent's key, followed by the child's index, @@ -240,8 +240,8 @@ fn get_iterator_intial_state<'a, S: CachedStore, T>( let child = merkle.get_node(child_addr)?; let partial_key = match child.inner() { - NodeType::Branch(branch) => &branch.path, - NodeType::Leaf(leaf) => &leaf.path, + NodeType::Branch(branch) => &branch.partial_path, + NodeType::Leaf(leaf) => &leaf.partial_path, }; let (comparison, new_unmatched_key_nibbles) = @@ -272,13 +272,13 @@ fn get_iterator_intial_state<'a, S: CachedStore, T>( } } NodeType::Leaf(leaf) => { - if compare_partial_path(leaf.path.iter(), unmatched_key_nibbles).0 + if compare_partial_path(leaf.partial_path.iter(), unmatched_key_nibbles).0 == Ordering::Greater { // `child` is after `key`. let key = matched_key_nibbles .iter() - .chain(leaf.path.iter()) + .chain(leaf.partial_path.iter()) .copied() .collect(); iter_stack.push(IterationNode::Unvisited { key, node }); @@ -477,8 +477,8 @@ impl<'a, 'b, S: CachedStore, T> Iterator for PathIterator<'a, 'b, S, T> { }; let partial_path = match node.inner() { - NodeType::Branch(branch) => &branch.path, - NodeType::Leaf(leaf) => &leaf.path, + NodeType::Branch(branch) => &branch.partial_path, + NodeType::Leaf(leaf) => &leaf.partial_path, }; let (comparison, unmatched_key) = @@ -810,40 +810,40 @@ mod tests { assert_eq!(key, vec![0x00].into_boxed_slice()); let node = node.inner().as_branch().unwrap(); assert!(node.value.is_none()); - assert_eq!(node.path.to_vec(), vec![0x00, 0x00]); + assert_eq!(node.partial_path.to_vec(), vec![0x00, 0x00]); // Covers case of branch with value let (key, node) = stream.next().await.unwrap().unwrap(); assert_eq!(key, vec![0x00, 0x00, 0x00].into_boxed_slice()); let node = node.inner().as_branch().unwrap(); assert_eq!(node.value.clone().unwrap().to_vec(), vec![0x00, 0x00, 0x00]); - assert_eq!(node.path.to_vec(), vec![0x00, 0x00, 0x00]); + assert_eq!(node.partial_path.to_vec(), vec![0x00, 0x00, 0x00]); // Covers case of leaf with partial path let (key, node) = stream.next().await.unwrap().unwrap(); assert_eq!(key, vec![0x00, 0x00, 0x00, 0x01].into_boxed_slice()); let node = node.inner().as_leaf().unwrap(); assert_eq!(node.clone().data.to_vec(), vec![0x00, 0x00, 0x00, 0x01]); - assert_eq!(node.path.to_vec(), vec![0x01]); + assert_eq!(node.partial_path.to_vec(), vec![0x01]); let (key, node) = stream.next().await.unwrap().unwrap(); assert_eq!(key, vec![0x00, 0x00, 0x00, 0xFF].into_boxed_slice()); let node = node.inner().as_leaf().unwrap(); assert_eq!(node.clone().data.to_vec(), vec![0x00, 0x00, 0x00, 0xFF]); - assert_eq!(node.path.to_vec(), vec![0x0F]); + assert_eq!(node.partial_path.to_vec(), vec![0x0F]); let (key, node) = stream.next().await.unwrap().unwrap(); assert_eq!(key, vec![0x00, 0xD0, 0xD0].into_boxed_slice()); let node = node.inner().as_leaf().unwrap(); assert_eq!(node.clone().data.to_vec(), vec![0x00, 0xD0, 0xD0]); - assert_eq!(node.path.to_vec(), vec![0x00, 0x0D, 0x00]); // 0x0D00 becomes 0xDO + assert_eq!(node.partial_path.to_vec(), vec![0x00, 0x0D, 0x00]); // 0x0D00 becomes 0xDO // Covers case of leaf with no partial path let (key, node) = stream.next().await.unwrap().unwrap(); assert_eq!(key, vec![0x00, 0xFF].into_boxed_slice()); let node = node.inner().as_leaf().unwrap(); assert_eq!(node.clone().data.to_vec(), vec![0x00, 0xFF]); - assert_eq!(node.path.to_vec(), vec![0x0F]); + assert_eq!(node.partial_path.to_vec(), vec![0x0F]); check_stream_is_done(stream).await; } diff --git a/firewood/src/shale/mod.rs b/firewood/src/shale/mod.rs index f0aa7b516..8e2c70239 100644 --- a/firewood/src/shale/mod.rs +++ b/firewood/src/shale/mod.rs @@ -144,7 +144,7 @@ impl Obj { impl Obj { pub fn into_inner(mut self) -> Node { let empty_node = LeafNode { - path: PartialPath(Vec::new()), + partial_path: PartialPath(Vec::new()), data: Vec::new().into(), };