Struct CheckPoint

Source
pub struct CheckPoint(/* private fields */);
Expand description

A checkpoint is a node of a reference-counted linked list of BlockIds.

Checkpoints are cheaply cloneable and are useful to find the agreement point between two sparse block chains.

Implementations§

Source§

impl CheckPoint

Source

pub fn new(block: BlockId) -> CheckPoint

Construct a new base block at the front of a linked list.

Source

pub fn from_block_ids( block_ids: impl IntoIterator<Item = BlockId>, ) -> Result<CheckPoint, Option<CheckPoint>>

Construct a checkpoint from a list of BlockIds in ascending height order.

§Errors

This method will error if any of the follow occurs:

  • The blocks iterator is empty, in which case, the error will be None.
  • The blocks iterator is not in ascending height order.
  • The blocks iterator contains multiple BlockIds of the same height.

The error type is the last successful checkpoint constructed (if any).

Source

pub fn from_header(header: &Header, height: u32) -> CheckPoint

Construct a checkpoint from the given header and block height.

If header is of the genesis block, the checkpoint won’t have a prev node. Otherwise, we return a checkpoint linked with the previous block.

Source

pub fn push(self, block: BlockId) -> Result<CheckPoint, CheckPoint>

Puts another checkpoint onto the linked list representing the blockchain.

Returns an Err(self) if the block you are pushing on is not at a greater height that the one you are pushing on to.

Source

pub fn extend( self, blocks: impl IntoIterator<Item = BlockId>, ) -> Result<CheckPoint, CheckPoint>

Extends the checkpoint linked list by a iterator of block ids.

Returns an Err(self) if there is block which does not have a greater height than the previous one.

Source

pub fn block_id(&self) -> BlockId

Get the BlockId of the checkpoint.

Source

pub fn height(&self) -> u32

Get the height of the checkpoint.

Source

pub fn hash(&self) -> BlockHash

Get the block hash of the checkpoint.

Source

pub fn prev(&self) -> Option<CheckPoint>

Get the previous checkpoint in the chain

Source

pub fn iter(&self) -> CheckPointIter

Iterate from this checkpoint in descending height.

Source

pub fn get(&self, height: u32) -> Option<CheckPoint>

Get checkpoint at height.

Returns None if checkpoint at height does not exist`.

Source

pub fn range<R>(&self, range: R) -> impl Iterator<Item = CheckPoint>
where R: RangeBounds<u32>,

Iterate checkpoints over a height range.

Note that we always iterate checkpoints in reverse height order (iteration starts at tip height).

Source

pub fn floor_at(&self, height: u32) -> Option<CheckPoint>

Returns the checkpoint at height if one exists, otherwise the nearest checkpoint at a lower height.

This is equivalent to taking the “floor” of height over this checkpoint chain.

Returns None if no checkpoint exists at or below the given height.

Source

pub fn floor_below(&self, offset: u32) -> Option<CheckPoint>

Returns the checkpoint located a number of heights below this one.

This is a convenience wrapper for CheckPoint::floor_at, subtracting to_subtract from the current height.

  • If a checkpoint exists exactly offset heights below, it is returned.
  • Otherwise, the nearest checkpoint below that target height is returned.

Returns None if to_subtract is greater than the current height, or if there is no checkpoint at or below the target height.

Source

pub fn insert(self, block_id: BlockId) -> CheckPoint

Inserts block_id at its height within the chain.

The effect of insert depends on whether a height already exists. If it doesn’t the block_id we inserted and all pre-existing blocks higher than it will be re-inserted after it. If the height already existed and has a conflicting block hash then it will be purged along with all block following it. The returned chain will have a tip of the block_id passed in. Of course, if the block_id was already present then this just returns self.

§Panics

This panics if called with a genesis block that differs from that of self.

Source

pub fn eq_ptr(&self, other: &CheckPoint) -> bool

This method tests for self and other to have equal internal pointers.

Trait Implementations§

Source§

impl Clone for CheckPoint

Source§

fn clone(&self) -> CheckPoint

Returns a duplicate 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 Debug for CheckPoint

Source§

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

Formats the value using the given formatter. Read more
Source§

impl IntoIterator for CheckPoint

Source§

type Item = CheckPoint

The type of the elements being iterated over.
Source§

type IntoIter = CheckPointIter

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> <CheckPoint as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
Source§

impl PartialEq for CheckPoint

Source§

fn eq(&self, other: &CheckPoint) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

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

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

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>,

Source§

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>,

Source§

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V