Struct grin_core::core::pmmr::VecBackend

source ·
pub struct VecBackend<T: PMMRable> {
    pub data: Option<Vec<T>>,
    pub hashes: Vec<Hash>,
    pub removed: HashSet<u64>,
}
Expand description

Simple/minimal/naive MMR backend implementation backed by Vec and Vec. Removed pos are maintained in a HashSet.

Fields§

§data: Option<Vec<T>>

Backend elements (optional, possible to just store hashes).

§hashes: Vec<Hash>

Vec of hashes for the PMMR (both leaves and parents).

§removed: HashSet<u64>

Positions of removed elements (is this applicable if we do not store data?)

Implementations§

source§

impl<T: PMMRable> VecBackend<T>

source

pub fn new() -> VecBackend<T>

Instantiates a new empty vec backend.

source

pub fn new_hash_only() -> VecBackend<T>

Instantiate a new empty “hash only” vec backend.

source

pub fn size(&self) -> u64

Size of this vec backend in hashes.

Trait Implementations§

source§

impl<T: PMMRable> Backend<T> for VecBackend<T>

source§

fn n_unpruned_leaves(&self) -> u64

Number of leaves in the MMR

source§

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

NOTE this function is needlessly inefficient with repeated calls to n_leaves()

source§

fn append(&mut self, elmt: &T, hashes: &[Hash]) -> Result<(), String>

Append the provided Hashes to the backend storage, and optionally an associated data element to flatfile storage (for leaf nodes only). The position of the first element of the Vec in the MMR is provided to help the implementation.
source§

fn append_pruned_subtree( &mut self, _hash: Hash, _pos0: u64 ) -> Result<(), String>

Rebuilding a PMMR locally from PIBD segments requires pruned subtree support. This allows us to append an existing pruned subtree directly without the underlying leaf nodes.
source§

fn append_hash(&mut self, _hash: Hash) -> Result<(), String>

Append a single hash to the pmmr
source§

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

Get a Hash by insertion position.
source§

fn get_data(&self, pos0: u64) -> Option<T::E>

Get underlying data by insertion position.
source§

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

Get a Hash by original insertion position (ignoring the remove log).
source§

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

Get hash for 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<T::E>

Get a Data Element by original insertion position (ignoring the remove log).
source§

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

Number of leaves up to the given leaf index
source§

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

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

fn remove(&mut self, pos0: u64) -> Result<(), String>

Remove Hash by insertion position. An index is also provided so the underlying backend can implement some rollback of positions up to a given index (practically the index is the height of a block that triggered removal).
source§

fn remove_from_leaf_set(&mut self, _pos0: u64)

Remove a leaf from the leaf set
source§

fn reset_prune_list(&mut self)

Reset prune list, used when PIBD is reset
source§

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

Rewind the backend state to a previous position, as if all append operations after that had been canceled. Expects a position in the PMMR to rewind to as well as bitmaps representing the positions added and removed since the rewind position. These are what we will “undo” during the rewind.
source§

fn snapshot(&self, _header: &BlockHeader) -> Result<(), String>

Saves a snapshot of the rewound utxo file with the block hash as filename suffix. We need this when sending a txhashset zip file to a node for fast sync.
source§

fn release_files(&mut self)

Release underlying datafiles and locks
source§

fn dump_stats(&self)

For debugging purposes so we can see how compaction is doing.
source§

impl<T: Clone + PMMRable> Clone for VecBackend<T>

source§

fn clone(&self) -> VecBackend<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug + PMMRable> Debug for VecBackend<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for VecBackend<T>

§

impl<T> RefUnwindSafe for VecBackend<T>
where T: RefUnwindSafe,

§

impl<T> Send for VecBackend<T>
where T: Send,

§

impl<T> Sync for VecBackend<T>
where T: Sync,

§

impl<T> Unpin for VecBackend<T>
where T: Unpin,

§

impl<T> UnwindSafe for VecBackend<T>
where T: UnwindSafe,

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> CloneAny for T
where T: Any + Clone,

source§

fn clone_any(&self) -> Box<dyn CloneAny>

source§

fn clone_any_send(&self) -> Box<dyn CloneAny + Send>
where T: Send,

source§

fn clone_any_sync(&self) -> Box<dyn CloneAny + Sync>
where T: Sync,

source§

fn clone_any_send_sync(&self) -> Box<dyn CloneAny + Send + Sync>
where T: Send + Sync,

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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> DebugAny for T
where T: Any + Debug,

source§

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