[−][src]Struct tari_mmr::MerkleChangeTracker
A struct that wraps an MMR to keep track of changes to the MMR over time. This enables one to roll
back changes to a point in history. Think of MerkleChangeTracker
as 'git' for MMRs.
[MutableMMr] implements std::ops::Deref, so that once you've wrapped the MMR, all the immutable methods are available through the auto-dereferencing.
The basic philosophy of MerkleChangeTracker
is as follows:
- Start with a 'base' MMR. For efficiency, you usually want to make this a [pruned_mmr::PrunedMmr], but it doesn't have to be.
- We then maintain a change-list for every append and delete that is made on the MMR.
- You can
commit
the change-set at any time, which will create a new MerkleCheckPoint summarising the changes, and the current change-set is reset. - You can
rewind
to a previously committed checkpoint, p. This entails resetting the MMR to the base state and then replaying every checkpoint in sequence until checkpoint p is reached.rewind_to_start
andreplay
perform similar functions. - You can
reset
the ChangeTracker, which clears the current change-set and moves you back to the most recent checkpoint ('HEAD')
Methods
impl<D, BaseBackend, CpBackend> MerkleChangeTracker<D, BaseBackend, CpBackend> where
D: Digest,
BaseBackend: ArrayLike<Value = Hash>,
CpBackend: ArrayLike<Value = MerkleCheckPoint> + ArrayLikeExt<Value = MerkleCheckPoint>,
[src]
D: Digest,
BaseBackend: ArrayLike<Value = Hash>,
CpBackend: ArrayLike<Value = MerkleCheckPoint> + ArrayLikeExt<Value = MerkleCheckPoint>,
pub fn new(
base: MutableMmr<D, BaseBackend>,
diffs: CpBackend
) -> Result<MerkleChangeTracker<D, BaseBackend, CpBackend>, MerkleMountainRangeError>
[src]
base: MutableMmr<D, BaseBackend>,
diffs: CpBackend
) -> Result<MerkleChangeTracker<D, BaseBackend, CpBackend>, MerkleMountainRangeError>
Wrap an MMR inside a change tracker.
Parameters
base
: The base, or anchor point of the change tracker. This represents the earliest point that you can MerkleChangeTracker::rewind to.mmr
: An empty MMR instance that will be used to maintain the current state of the MMR.diffs
: The (usually empty) collection of diffs that will be used to store the MMR checkpoints.
Returns
A new MerkleChangeTracker
instance that is configured using the MMR and ChangeTracker instances provided.
pub fn checkpoint_count(&self) -> usize
[src]
Return the number of Checkpoints this change tracker has recorded
pub fn push(&mut self, hash: &Hash) -> Result<usize, MerkleMountainRangeError>
[src]
Push the given hash into the MMR and update the current change-set
pub fn reset(&mut self) -> Result<(), MerkleMountainRangeError>
[src]
Discards the current change-set and resets the MMR state to that of the last checkpoint
pub fn delete_and_compress(
&mut self,
leaf_node_index: u32,
compress: bool
) -> bool
[src]
&mut self,
leaf_node_index: u32,
compress: bool
) -> bool
Mark a node for deletion and optionally compress the deletion bitmap. See MutableMmr::delete_and_compress for more details
pub fn delete(&mut self, leaf_node_index: u32) -> bool
[src]
Mark a node for completion, and compress the roaring bitmap. See [delete_and_compress] for details.
pub fn compress(&mut self) -> bool
[src]
Compress the roaring bitmap mapping deleted nodes. You never have to call this method unless you have been
calling [delete_and_compress] with compress
set to false
ahead of a call to [get_merkle_root].
pub fn commit(&mut self) -> Result<(), CpBackend::Error>
[src]
Commit the change history since the last commit to a new MerkleCheckPoint and clear the current change set.
pub fn rewind(
&mut self,
steps_back: usize
) -> Result<(), MerkleMountainRangeError>
[src]
&mut self,
steps_back: usize
) -> Result<(), MerkleMountainRangeError>
Rewind the MMR state by the given number of Checkpoints.
Example:
Assuming we start with an empty Mutable MMR, and apply the following: push(1), push(2), delete(1), Checkpoint (1) push(3), push(4) Checkpoint (2) push(5), delete(4) Checkpoint (3) push(6)
The state is now:
1 2 3 4 5 6
x x
After calling rewind(1)
, The push of 6 wasn't check-pointed, so it will be discarded, and rewinding back one
point to checkpoint 2 the state will be:
1 2 3 4
x
Calling rewind(1)
again will yield:
1 2
x
pub fn rewind_to_start(&mut self) -> Result<(), MerkleMountainRangeError>
[src]
Rewinds the MMR back to the state of the base MMR; essentially discarding all the history accumulated to date.
pub fn replay(
&mut self,
num_checkpoints: usize
) -> Result<(), MerkleMountainRangeError>
[src]
&mut self,
num_checkpoints: usize
) -> Result<(), MerkleMountainRangeError>
Similar to MerkleChangeTracker::rewind, replay
moves the MMR state through checkpoints, but uses the base
MMR as the starting point and steps forward through num_checkpoints
checkpoints, rather than rewinding from
the current state.
pub fn get_checkpoint(
&self,
index: usize
) -> Result<MerkleCheckPoint, MerkleMountainRangeError>
[src]
&self,
index: usize
) -> Result<MerkleCheckPoint, MerkleMountainRangeError>
Trait Implementations
impl<D, BaseBackend, DiffBackend> Deref for MerkleChangeTracker<D, BaseBackend, DiffBackend> where
D: Digest,
BaseBackend: ArrayLike<Value = Hash>,
[src]
D: Digest,
BaseBackend: ArrayLike<Value = Hash>,
type Target = PrunedMutableMmr<D>
The resulting type after dereferencing.
fn deref(&self) -> &Self::Target
[src]
Auto Trait Implementations
impl<D, BaseBackend, CpBackend> Send for MerkleChangeTracker<D, BaseBackend, CpBackend> where
BaseBackend: Send,
CpBackend: Send,
D: Send,
BaseBackend: Send,
CpBackend: Send,
D: Send,
impl<D, BaseBackend, CpBackend> Unpin for MerkleChangeTracker<D, BaseBackend, CpBackend> where
BaseBackend: Unpin,
CpBackend: Unpin,
D: Unpin,
BaseBackend: Unpin,
CpBackend: Unpin,
D: Unpin,
impl<D, BaseBackend, CpBackend> Sync for MerkleChangeTracker<D, BaseBackend, CpBackend> where
BaseBackend: Sync,
CpBackend: Sync,
D: Sync,
BaseBackend: Sync,
CpBackend: Sync,
D: Sync,
impl<D, BaseBackend, CpBackend> UnwindSafe for MerkleChangeTracker<D, BaseBackend, CpBackend> where
BaseBackend: UnwindSafe,
CpBackend: UnwindSafe,
D: UnwindSafe,
BaseBackend: UnwindSafe,
CpBackend: UnwindSafe,
D: UnwindSafe,
impl<D, BaseBackend, CpBackend> RefUnwindSafe for MerkleChangeTracker<D, BaseBackend, CpBackend> where
BaseBackend: RefUnwindSafe,
CpBackend: RefUnwindSafe,
D: RefUnwindSafe,
BaseBackend: RefUnwindSafe,
CpBackend: RefUnwindSafe,
D: RefUnwindSafe,
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Same<T> for T
type Output = T
Should always be Self