[][src]Struct grin_core::core::pmmr::PMMR

pub struct PMMR<'a, T, B> where
    T: PMMRable,
    B: Backend<T>, 
{ pub last_pos: u64, // some fields omitted }

Prunable Merkle Mountain Range implementation. All positions within the tree start at 1 as they're postorder tree traversal positions rather than array indices.

Heavily relies on navigation operations within a binary tree. In particular, all the implementation needs to keep track of the MMR structure is how far we are in the sequence of nodes making up the MMR.

Fields

last_pos: u64

The last position in the PMMR

Methods

impl<'a, T, B> PMMR<'a, T, B> where
    T: PMMRable,
    B: 'a + Backend<T>, 
[src]

pub fn new(backend: &'a mut B) -> PMMR<T, B>[src]

Build a new prunable Merkle Mountain Range using the provided backend.

pub fn at(backend: &'a mut B, last_pos: u64) -> PMMR<T, B>[src]

Build a new prunable Merkle Mountain Range pre-initialized until last_pos with the provided backend.

pub fn readonly_pmmr(&self) -> ReadonlyPMMR<T, B>[src]

Build a "readonly" view of this PMMR.

pub fn leaf_pos_iter(&self) -> impl Iterator<Item = u64> + '_[src]

Iterator over current (unpruned, unremoved) leaf positions.

pub fn peaks(&self) -> Vec<Hash>[src]

Returns a vec of the peaks of this MMR.

pub fn bag_the_rhs(&self, peak_pos: u64) -> Option<Hash>[src]

Takes a single peak position and hashes together all the peaks to the right of this peak (if any). If this return a hash then this is our peaks sibling. If none then the sibling of our peak is the peak to the left.

pub fn root(&self) -> Hash[src]

Computes the root of the MMR. Find all the peaks in the current tree and "bags" them to get a single peak.

pub fn merkle_proof(&self, pos: u64) -> Result<MerkleProof, String>[src]

Build a Merkle proof for the element at the given position.

pub fn push(&mut self, elmt: &T) -> Result<u64, String>[src]

Push a new element into the MMR. Computes new related peaks at the same time if applicable.

pub fn snapshot(&mut self, header: &BlockHeader) -> Result<(), String>[src]

Saves a snapshot of the MMR tagged with the block hash. Specifically - snapshots the utxo file as we need this rewound before sending the txhashset zip file to another node for fast-sync.

pub fn truncate(&mut self) -> Result<(), String>[src]

Truncate the MMR by rewinding back to empty state.

pub fn rewind(
    &mut self,
    position: u64,
    rewind_rm_pos: &Bitmap
) -> Result<(), String>
[src]

Rewind the PMMR to a previous position, as if all push operations after that had been canceled. Expects a position in the PMMR to rewind and bitmaps representing the positions added and removed that we want to "undo".

pub fn prune(&mut self, position: u64) -> Result<bool, String>[src]

Prunes (removes) the leaf from the MMR at the specified position. Returns an error if prune is called on a non-leaf position. Returns false if the leaf node has already been pruned. Returns true if pruning is successful.

pub fn get_hash(&self, pos: u64) -> Option<Hash>[src]

Get the hash at provided position in the MMR.

pub fn get_data(&self, pos: u64) -> Option<T::E>[src]

Get the data element at provided position in the MMR.

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

Walks all unpruned nodes in the MMR and revalidate all parent hashes

pub fn is_empty(&self) -> bool[src]

Is the MMR empty?

pub fn unpruned_size(&self) -> u64[src]

Total size of the tree, including intermediary nodes and ignoring any pruning.

pub fn dump(&self, short: bool)[src]

Debugging utility to print information about the MMRs. Short version only prints the last 8 nodes.

pub fn dump_stats(&self)[src]

Prints PMMR statistics to the logs, used for debugging.

pub fn dump_from_file(&self, short: bool)[src]

Debugging utility to print information about the MMRs. Short version only prints the last 8 nodes. Looks in the underlying hash file and so ignores the remove log.

Auto Trait Implementations

impl<'a, T, B> Send for PMMR<'a, T, B> where
    B: Send,
    T: Send

impl<'a, T, B> Unpin for PMMR<'a, T, B> where
    T: Unpin

impl<'a, T, B> Sync for PMMR<'a, T, B> where
    B: Sync,
    T: Sync

impl<'a, T, B> !UnwindSafe for PMMR<'a, T, B>

impl<'a, T, B> RefUnwindSafe for PMMR<'a, T, B> where
    B: RefUnwindSafe,
    T: RefUnwindSafe

Blanket Implementations

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

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

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<T> BorrowMut<T> for T where
    T: ?Sized
[src]

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

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

impl<T> UnsafeAny for T where
    T: Any

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> Erased for T