rename MerklePath::inner_nodes to authenticated_nodes and update docs

This name better reflects its actual functionality, but is open to
bikeshedding.
This commit is contained in:
Qyriad 2025-05-09 15:10:23 +02:00
parent 03647457d9
commit 6b702bd4a8

View file

@ -88,21 +88,31 @@ impl MerklePath {
Ok(()) Ok(())
} }
/// Returns an iterator over every inner node of this [MerklePath]. /// Given the node this path opens to, return an iterator of all the nodes that are known via
/// this path.
/// ///
/// The iteration order is unspecified. /// Each item in the iterator is an [InnerNodeInfo], containing the hash of a node as `.value`,
/// and its two children as `.left` and `.right`. The very first item in that iterator will be
/// the parent of `node_to_prove`, either `left` or `right` will be `node_to_prove` itself, and
/// the other child will be `node_to_prove` as stored in this [MerklePath].
///
/// From there, the iterator will continue to yield every further parent and both of its
/// children, up to and including the root node.
///
/// If `node_to_prove` is not the node this path is an opening to, or `index` is not the
/// correct index for that node, the returned nodes will be meaningless.
/// ///
/// # Errors /// # Errors
/// Returns an error if the specified index is not valid for this path. /// Returns an error if the specified index is not valid for this path.
pub fn inner_nodes( pub fn authenticated_nodes(
&self, &self,
index: u64, index: u64,
node: RpoDigest, node_to_prove: RpoDigest,
) -> Result<InnerNodeIterator, MerkleError> { ) -> Result<InnerNodeIterator, MerkleError> {
Ok(InnerNodeIterator { Ok(InnerNodeIterator {
nodes: &self.nodes, nodes: &self.nodes,
index: NodeIndex::new(self.depth(), index)?, index: NodeIndex::new(self.depth(), index)?,
value: node, value: node_to_prove,
}) })
} }
} }
@ -293,7 +303,8 @@ mod tests {
let node = int_to_node(5); let node = int_to_node(5);
let root = merkle_path.compute_root(index, node).unwrap(); let root = merkle_path.compute_root(index, node).unwrap();
let inner_root = merkle_path.inner_nodes(index, node).unwrap().last().unwrap().value; let inner_root =
merkle_path.authenticated_nodes(index, node).unwrap().last().unwrap().value;
assert_eq!(root, inner_root); assert_eq!(root, inner_root);
} }