Struct grin_core::core::pmmr::PMMR

source ·
pub struct PMMR<'a, T, B>
where T: PMMRable, B: Backend<T>,
{ pub size: u64, /* private fields */ }
Expand description

Prunable Merkle Mountain Range implementation. All positions within the tree start at 0 just like 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§

§size: u64

Number of nodes in the PMMR

Implementations§

source§

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

source

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

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

source

pub fn at(backend: &'a mut B, size: u64) -> PMMR<'_, T, B>

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

source

pub fn readonly_pmmr(&self) -> ReadonlyPMMR<'_, T, B>

Build a “readonly” view of this PMMR.

source

pub fn push(&mut self, leaf: &T) -> Result<u64, String>

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

source

pub fn push_pruned_subtree( &mut self, hash: Hash, pos0: u64 ) -> Result<(), String>

Push a pruned subtree into the PMMR

source

pub fn reset_prune_list(&mut self)

Reset prune list

source

pub fn remove_from_leaf_set(&mut self, pos0: u64)

Remove the specified position from the leaf set

source

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

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.

source

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

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”.

source

pub fn prune(&mut self, pos0: u64) -> Result<bool, String>

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.

source

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

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

source

pub fn dump(&self, short: bool)

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

source

pub fn dump_stats(&self)

Prints PMMR statistics to the logs, used for debugging.

source

pub fn dump_from_file(&self, short: bool)

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.

Trait Implementations§

source§

impl<'a, T, B> ReadablePMMR for PMMR<'a, T, B>
where T: PMMRable, B: 'a + Backend<T>,

§

type Item = <T as PMMRable>::E

Leaf type
source§

fn get_hash(&self, pos0: u64) -> Option<Hash>

Get the hash at provided position in the MMR. NOTE all positions are 0-based, so a size n MMR has nodes in positions 0 through n-1 just like a Rust Range 0..n
source§

fn get_data(&self, pos0: u64) -> Option<Self::Item>

Get the data element at provided position in the MMR.
source§

fn get_from_file(&self, pos0: u64) -> Option<Hash>

Get the hash from the underlying MMR file (ignores the remove log).
source§

fn get_peak_from_file(&self, pos0: u64) -> Option<Hash>

Get the hash for the provided peak pos. Optimized for reading peak hashes rather than arbitrary pos hashes. Peaks can be assumed to not be compacted.
source§

fn get_data_from_file(&self, pos0: u64) -> Option<Self::Item>

Get the data element at provided position in the MMR (ignores the remove log).
source§

fn unpruned_size(&self) -> u64

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

fn leaf_pos_iter(&self) -> Box<dyn Iterator<Item = u64> + '_>

Iterator over current (unpruned, unremoved) leaf positions.
source§

fn leaf_idx_iter(&self, from_idx: u64) -> Box<dyn Iterator<Item = u64> + '_>

Iterator over current (unpruned, unremoved) leaf insertion indices.
source§

fn n_unpruned_leaves(&self) -> u64

Number of leaves in the MMR
source§

fn n_unpruned_leaves_to_index(&self, to_index: u64) -> u64

Number of leaves in the MMR up to index
source§

fn is_empty(&self) -> bool

Is the MMR empty?
source§

fn bag_the_rhs(&self, peak_pos0: u64) -> Option<Hash>

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.
source§

fn peaks(&self) -> Vec<Hash>

Returns a vec of the peaks of this MMR.
source§

fn peak_path(&self, peak_pos0: u64) -> Vec<Hash>

Hashes of the peaks excluding peak_pos, where the rhs is bagged together
source§

fn root(&self) -> Result<Hash, String>

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

fn merkle_proof(&self, pos0: u64) -> Result<MerkleProof, String>

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

Auto Trait Implementations§

§

impl<'a, T, B> Freeze for PMMR<'a, T, B>

§

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

§

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

§

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

§

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

§

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

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> UnsafeAny for T
where T: Any,