[][src]Struct tari_mmr::MmrCache

pub struct MmrCache<D, BaseBackend, CpBackend> where
    D: Digest,
    BaseBackend: ArrayLike<Value = Hash>, 
{ pub curr_mmr: PrunedMutableMmr<D>, // some fields omitted }

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

impl<D, BaseBackend, CpBackend> MmrCache<D, BaseBackend, CpBackend> where
    D: Digest,
    BaseBackend: ArrayLike<Value = Hash>,
    CpBackend: ArrayLike<Value = MerkleCheckPoint>, 
[src]

pub fn new(
    base_mmr: BaseBackend,
    checkpoints: CpBackend,
    config: MmrCacheConfig
) -> Result<MmrCache<D, BaseBackend, CpBackend>, MerkleMountainRangeError>
[src]

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>
[src]

Inform the MmrCache that the first N checkpoints have been merged to allow the base and current indices to be updated.

pub fn update(&mut self) -> Result<(), MerkleMountainRangeError>[src]

This function updates the state of the MMR cache based on the current state of the shared checkpoints.

pub fn reset(&mut self) -> Result<(), MerkleMountainRangeError>[src]

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>
[src]

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.

pub fn find_leaf_index(
    &self,
    hash: &Hash
) -> Result<Option<u32>, MerkleMountainRangeError>
[src]

Search for the leaf index of the given hash in the nodes of the current and base MMR.

Methods from Deref<Target = PrunedMutableMmr<D>>

pub fn len(&self) -> u32[src]

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.

pub fn is_empty(&self) -> Result<bool, MerkleMountainRangeError>[src]

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>
[src]

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>
[src]

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.

pub fn get_leaf_count(&self) -> usize[src]

Returns the number of leaf nodes in the MMR.

pub fn get_merkle_root(&self) -> Result<Hash, MerkleMountainRangeError>[src]

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.

pub fn get_mmr_only_root(&self) -> Result<Hash, MerkleMountainRangeError>[src]

Returns only the MMR merkle root without the compressed serialisation of the bitmap

pub fn find_node_index(
    &self,
    hash: &Hash
) -> Result<Option<usize>, MerkleMountainRangeError>
[src]

pub fn find_leaf_index(
    &self,
    hash: &Hash
) -> Result<Option<u32>, MerkleMountainRangeError>
[src]

pub fn validate(&self) -> Result<(), MerkleMountainRangeError>[src]

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>
[src]

Returns the state of the MMR that consists of the leaf hashes and the deleted nodes.

pub fn mmr(&self) -> &MerkleMountainRange<D, B>[src]

Expose the MerkleMountainRange for verifying proofs

pub fn deleted(&self) -> &Bitmap[src]

Return a reference to the bitmap of deleted nodes

Trait Implementations

impl<D: Debug, BaseBackend: Debug, CpBackend: Debug> Debug for MmrCache<D, BaseBackend, CpBackend> where
    D: Digest,
    BaseBackend: ArrayLike<Value = Hash>, 
[src]

impl<D, BaseBackend, CpBackend> Deref for MmrCache<D, BaseBackend, CpBackend> where
    D: Digest,
    BaseBackend: ArrayLike<Value = Hash>, 
[src]

type Target = PrunedMutableMmr<D>

The resulting type after dereferencing.

Auto Trait Implementations

impl<D, BaseBackend, CpBackend> RefUnwindSafe for MmrCache<D, BaseBackend, CpBackend> where
    BaseBackend: RefUnwindSafe,
    CpBackend: RefUnwindSafe,
    D: RefUnwindSafe

impl<D, BaseBackend, CpBackend> Send for MmrCache<D, BaseBackend, CpBackend> where
    BaseBackend: Send,
    CpBackend: Send,
    D: Send

impl<D, BaseBackend, CpBackend> Sync for MmrCache<D, BaseBackend, CpBackend> where
    BaseBackend: Sync,
    CpBackend: Sync,
    D: Sync

impl<D, BaseBackend, CpBackend> Unpin for MmrCache<D, BaseBackend, CpBackend> where
    BaseBackend: Unpin,
    CpBackend: Unpin,
    D: Unpin

impl<D, BaseBackend, CpBackend> UnwindSafe for MmrCache<D, BaseBackend, CpBackend> where
    BaseBackend: UnwindSafe,
    CpBackend: UnwindSafe,
    D: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,