Skip to main content

Storage

Trait Storage 

Source
pub trait Storage:
    Sized
    + Send
    + Sync
    + 'static {
    // Required methods
    fn default() -> impl Send + Future<Output = Result<Self>>;
    fn block_height(&self) -> impl Send + Future<Output = Result<u64>>;
    fn leaf_upper_bound(
        &self,
        leaf: impl Into<LeafRequest> + Send,
    ) -> impl Send + Future<Output = Result<Option<LeafQueryData<SeqTypes>>>>;
    fn get_leaves_in_range(
        &self,
        start: u32,
        end: u32,
    ) -> impl Send + Future<Output = Result<Vec<LeafQueryData<SeqTypes>>>>;
    fn insert_leaf(
        &self,
        leaf: LeafQueryData<SeqTypes>,
    ) -> impl Send + Future<Output = Result<()>>;
    fn stake_table_lower_bound(
        &self,
        epoch: EpochNumber,
    ) -> impl Send + Future<Output = Result<Option<(EpochNumber, StakeTableState, Version, Version)>>>;
    fn insert_stake_table(
        &self,
        epoch: EpochNumber,
        stake_table: &StakeTableState,
        epoch_root_protocol_version: Version,
        next_epoch_root_protocol_version: Version,
    ) -> impl Send + Future<Output = Result<()>>;
}
Expand description

Client-side database for a [LightClient].

Required Methods§

Source

fn default() -> impl Send + Future<Output = Result<Self>>

Create a default, empty instance of the state.

This is an async, fallible version of Default::default. If Self: Default, this is equivalent to ready(Ok(<Self as Default>::default())).

Source

fn block_height(&self) -> impl Send + Future<Output = Result<u64>>

Get the number of blocks known to be in the chain.

This is equivalent to one more than the block number of the latest known block.

Because the database is not constantly being updated, this may be an underestimate of the true number of blocks that exist.

Source

fn leaf_upper_bound( &self, leaf: impl Into<LeafRequest> + Send, ) -> impl Send + Future<Output = Result<Option<LeafQueryData<SeqTypes>>>>

Get the earliest available leaf which is later than or equal to the requested leaf.

This will either be the leaf requested, or can be used as the known-finalized endpoint in a leaf chain proving that requested leaf is finalized (after the requested leaf is fetched from elsewhere).

If there is no known leaf later than the requested leaf, the result is None.

Source

fn get_leaves_in_range( &self, start: u32, end: u32, ) -> impl Send + Future<Output = Result<Vec<LeafQueryData<SeqTypes>>>>

Get all leaves in the range [start, end)

Source

fn insert_leaf( &self, leaf: LeafQueryData<SeqTypes>, ) -> impl Send + Future<Output = Result<()>>

Add a leaf to the cache.

This may result in an older leaf being removed.

Source

fn stake_table_lower_bound( &self, epoch: EpochNumber, ) -> impl Send + Future<Output = Result<Option<(EpochNumber, StakeTableState, Version, Version)>>>

Get the stake table for the latest epoch which is not later than epoch.

If such a stake table is available in the database, returns the loaded epoch number, the stake table state, the protocol version of the epoch root header under whose rules that stake table’s active set was selected, and the protocol version of the epoch root header in the next epoch (used to seed iter 1 of a catchup that resumes from this row).

Source

fn insert_stake_table( &self, epoch: EpochNumber, stake_table: &StakeTableState, epoch_root_protocol_version: Version, next_epoch_root_protocol_version: Version, ) -> impl Send + Future<Output = Result<()>>

Add a stake table to the cache.

epoch_root_protocol_version is the protocol version of the epoch root header in epoch e-2 (the snapshot point), used so that future cache hits can apply the same active-set selection rules without re-fetching the root.

next_epoch_root_protocol_version is the protocol version of the epoch root header in epoch e-1 (the snapshot point for e+1), used so that a future catchup resuming from this row can seed iter 1’s filter version without re-fetching that root.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<T: Storage> Storage for Arc<T>

Source§

async fn default() -> Result<Self>

Source§

async fn block_height(&self) -> Result<u64>

Source§

async fn leaf_upper_bound( &self, leaf: impl Into<LeafRequest> + Send, ) -> Result<Option<LeafQueryData<SeqTypes>>>

Source§

async fn get_leaves_in_range( &self, start: u32, end: u32, ) -> Result<Vec<LeafQueryData<SeqTypes>>>

Source§

async fn insert_leaf(&self, leaf: LeafQueryData<SeqTypes>) -> Result<()>

Source§

async fn stake_table_lower_bound( &self, epoch: EpochNumber, ) -> Result<Option<(EpochNumber, StakeTableState, Version, Version)>>

Source§

async fn insert_stake_table( &self, epoch: EpochNumber, stake_table: &StakeTableState, epoch_root_protocol_version: Version, next_epoch_root_protocol_version: Version, ) -> Result<()>

Implementors§

Source§

impl Storage for SqlStorage

Available on crate feature client only.