Struct tari_mmr::MerkleMountainRange [−][src]
pub struct MerkleMountainRange<D, B> { /* fields omitted */ }
Expand description
An implementation of a Merkle Mountain Range (MMR). The MMR is append-only and immutable. Only the hashes are stored in this data structure. The data itself can be stored anywhere as long as you can maintain a 1:1 mapping of the hash of that data to the leaf nodes in the MMR.
Implementations
Create a new Merkle mountain range using the given backend for storage
Clears the MMR and assigns its state from the list of leaf hashes given in leaf_hashes
.
pub fn assign_iter<I: IntoIterator<Item = Hash>>(
&mut self,
hash_iter: I
) -> Result<(), MerkleMountainRangeError>
pub fn assign_iter<I: IntoIterator<Item = Hash>>(
&mut self,
hash_iter: I
) -> Result<(), MerkleMountainRangeError>
Clears the MMR and assigns its state from the provided iterator, which must produce a finite number of Hashes.
Return the number of nodes in the full Merkle Mountain range, excluding bagged hashes
Returns true if the MMR contains no hashes
pub fn get_node_hash(
&self,
node_index: usize
) -> Result<Option<Hash>, MerkleMountainRangeError>
pub fn get_node_hash(
&self,
node_index: usize
) -> Result<Option<Hash>, MerkleMountainRangeError>
This function returns the hash of the node index provided indexed from 0
Returns the number of leaf nodes in the MMR.
pub fn get_leaf_hash(
&self,
leaf_index: usize
) -> Result<Option<Hash>, MerkleMountainRangeError>
pub fn get_leaf_hash(
&self,
leaf_index: usize
) -> Result<Option<Hash>, MerkleMountainRangeError>
This function returns the hash of the leaf index provided, indexed from 0
pub fn get_leaf_hashes(
&self,
leaf_index: usize,
count: usize
) -> Result<Vec<Hash>, MerkleMountainRangeError>
pub fn get_leaf_hashes(
&self,
leaf_index: usize,
count: usize
) -> Result<Vec<Hash>, MerkleMountainRangeError>
Returns a set of leaf hashes from the MMR.
This function will return the single merkle root of the MMR by simply hashing the peaks together.
Note that this differs from the bagging strategy used in other MMR implementations, and saves you a few hashes
Push a new element into the MMR. Computes new related peaks at the same time if applicable. Returns the new length of the merkle mountain range (the number of all nodes, not just leaf nodes).
Walks the nodes in the MMR and revalidates all parent hashes
Search for the node index of the given hash in the MMR. This is a very slow function, being O(n). In general, it’s better to cache the index of the hash when storing it rather than using this function, but it’s here for completeness.
Search for the leaf index of the given hash in the leaf nodes of the MMR.
Trait Implementations
impl<D, B, B2> PartialEq<MerkleMountainRange<D, B2>> for MerkleMountainRange<D, B> where
D: Digest,
B: ArrayLike<Value = Hash>,
B2: ArrayLike<Value = Hash>,
impl<D, B, B2> PartialEq<MerkleMountainRange<D, B2>> for MerkleMountainRange<D, B> where
D: Digest,
B: ArrayLike<Value = Hash>,
B2: ArrayLike<Value = Hash>,
impl<D, B> TryFrom<&'_ MerkleMountainRange<D, B>> for PrunedHashSet where
D: Digest,
B: ArrayLike<Value = Hash>,
impl<D, B> TryFrom<&'_ MerkleMountainRange<D, B>> for PrunedHashSet where
D: Digest,
B: ArrayLike<Value = Hash>,
type Error = MerkleMountainRangeError
type Error = MerkleMountainRangeError
The type returned in the event of a conversion error.
Performs the conversion.