Struct bridgetree::Checkpoint

source ·
pub struct Checkpoint { /* private fields */ }
Expand description

A data structure used to store the information necessary to “rewind” the state of a BridgeTree to a particular leaf position.

This is needed because the BridgeTree::marked_indices map is a cache of information that crosses MerkleBridge boundaries, and so it is not sufficient to just truncate the list of bridges; instead, we use Checkpoint values to be able to rapidly restore the cache to its previous state.

Implementations§

Creates a new checkpoint from its constituent parts.

Creates a new empty checkpoint for the specified BridgeTree state.

Examples found in repository?
src/lib.rs (line 1027)
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
    pub fn checkpoint(&mut self) {
        match self.current_bridge.take() {
            Some(cur_b) => {
                let is_marked = self.get_marked_leaf(cur_b.position()).is_some();

                // Do not create a duplicate bridge
                if self
                    .prior_bridges
                    .last()
                    .map_or(false, |pb| pb.position() == cur_b.position())
                {
                    self.current_bridge = Some(cur_b);
                } else {
                    self.current_bridge = Some(cur_b.successor(false));
                    self.prior_bridges.push(cur_b);
                }

                self.checkpoints
                    .push(Checkpoint::at_length(self.prior_bridges.len(), is_marked));
            }
            None => {
                self.checkpoints.push(Checkpoint::at_length(0, false));
            }
        }

        if self.checkpoints.len() > self.max_checkpoints {
            self.drop_oldest_checkpoint();
        }
    }

Returns the length of the BridgeTree::prior_bridges vector of the BridgeTree to which this checkpoint refers.

This is the number of bridges that will be retained in the event of a rewind to this checkpoint.

Returns whether the current state of the tree had been marked at the point that this checkpoint was made.

In the event of a rewind, the rewind logic will ensure that mark information is properly reconstituted for the checkpointed tree state.

Returns a set of the positions that have been marked during the period that this checkpoint is the current checkpoint.

Returns the set of previously-marked positions that have had their marks removed during the period that this checkpoint is the current checkpoint.

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Deserialize this value from the given Serde deserializer. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.