Struct tari_mmr::MmrCache [−][src]
pub struct MmrCache<D, BaseBackend, CpBackend> where
D: Digest,
BaseBackend: ArrayLike<Value = Hash>, {
pub curr_mmr: PrunedMutableMmr<D>,
// some fields omitted
}
Expand description
The MMR cache is used to calculate Merkle and Merklish roots based on the state of the set of shared checkpoints. It can efficiently create an updated cache state when small checkpoint rewinds were detected or the checkpoint state has been expanded.
Fields
curr_mmr: PrunedMutableMmr<D>
Implementations
pub fn new(
base_mmr: BaseBackend,
checkpoints: CpBackend,
config: MmrCacheConfig
) -> Result<MmrCache<D, BaseBackend, CpBackend>, MerkleMountainRangeError>
pub fn new(
base_mmr: BaseBackend,
checkpoints: CpBackend,
config: MmrCacheConfig
) -> Result<MmrCache<D, BaseBackend, CpBackend>, MerkleMountainRangeError>
Creates a new MMR cache with access to the provided set of shared checkpoints.
pub fn checkpoints_merged(
&mut self,
num_merged: usize
) -> Result<(), MerkleMountainRangeError>
pub fn checkpoints_merged(
&mut self,
num_merged: usize
) -> Result<(), MerkleMountainRangeError>
Inform the MmrCache that the first N checkpoints have been merged to allow the base and current indices to be updated.
This function updates the state of the MMR cache based on the current state of the shared checkpoints.
Reset the MmrCache and rebuild the base and current MMR state.
pub fn fetch_mmr_node(
&self,
leaf_index: u32
) -> Result<(Option<Hash>, bool), MerkleMountainRangeError>
pub fn fetch_mmr_node(
&self,
leaf_index: u32
) -> Result<(Option<Hash>, bool), MerkleMountainRangeError>
Returns the hash of the leaf index provided, as well as its deletion status. The node has been marked for deletion if the boolean value is true.
Search for the leaf index of the given hash in the nodes of the current and base MMR.
Methods from Deref<Target = PrunedMutableMmr<D>>
Return the number of leaf nodes in the MutableMmr
that have not been marked as deleted.
NB: This is semantically different to MerkleMountainRange::len()
. The latter returns the total number of
nodes in the MMR, while this function returns the number of leaf nodes minus the number of nodes marked for
deletion.
Returns true if the the MMR contains no nodes, OR all nodes have been marked for deletion
pub fn get_leaf_hash(
&self,
leaf_index: u32
) -> Result<Option<Hash>, MerkleMountainRangeError>
pub fn get_leaf_hash(
&self,
leaf_index: u32
) -> Result<Option<Hash>, MerkleMountainRangeError>
This function returns the hash of the leaf index provided, indexed from 0. If the hash does not exist, or if it
has been marked for deletion, None
is returned.
pub fn get_leaf_status(
&self,
leaf_index: u32
) -> Result<(Option<Hash>, bool), MerkleMountainRangeError>
pub fn get_leaf_status(
&self,
leaf_index: u32
) -> Result<(Option<Hash>, bool), MerkleMountainRangeError>
Returns the hash of the leaf index provided, as well as its deletion status. The node has been marked for deletion if the boolean value is true.
Returns the number of leaf nodes in the MMR.
Returns a merkle(ish) root for this merkle set.
The root is calculated by concatenating the MMR merkle root with the compressed serialisation of the bitmap and then hashing the result.
Returns only the MMR merkle root without the compressed serialisation of the bitmap
Walks the nodes in the MMR and validates all parent hashes
This just calls through to the underlying MMR’s validate method. There’s nothing we can do to check whether
the roaring bitmap represents all the leaf nodes that we want to delete. Note: A struct that uses
MutableMmr
and links it to actual data should be able to do this though.
pub fn to_leaf_nodes(
&self,
leaf_index: usize,
count: usize
) -> Result<MutableMmrLeafNodes, MerkleMountainRangeError>
pub fn to_leaf_nodes(
&self,
leaf_index: usize,
count: usize
) -> Result<MutableMmrLeafNodes, MerkleMountainRangeError>
Returns the state of the MMR that consists of the leaf hashes and the deleted nodes.
Expose the MerkleMountainRange for verifying proofs