pub fn fetch_checkpoint<T>(
    checkpoints: &T,
    pruned_mode: bool,
    tip_height: u64,
    height: u64,
) -> Result<Option<MerkleCheckPoint>, ChainStorageError>
where
    T: ArrayLike<Value = MerkleCheckPoint>,
    ChainStorageError: From<T::Error>,
{
    let tip_index = tip_height.saturating_sub(1);
    let height_offset = tip_index
        .checked_sub(height)
        .ok_or_else(|| ChainStorageError::OutOfRange)?;

    let last_cp_index = checkpoints.len()?.saturating_sub(1);
    let index = last_cp_index
        .checked_sub(height_offset as usize)
        .ok_or_else(|| ChainStorageError::BeyondPruningHorizon)?;
    if pruned_mode && index == 0 {
        // In pruned mode the first checkpoint is an accumulation of all checkpoints from the genesis block to horizon
        // block height.
        return Err(ChainStorageError::BeyondPruningHorizon);
    }
    checkpoints.get(index as usize).map_err(Into::into)
}
/// Retrieves the checkpoint corresponding to the provided height, if the checkpoint is part of the horizon state then a
/// BeyondPruningHorizon error will be returned.
Retrieves the checkpoint corresponding to the provided height, if the checkpoint is part of the horizon state then a
BeyondPruningHorizon error will be returned.
Retrieves the checkpoint corresponding to the provided height if the checkpoint is part of the horizon state then a BeyondPruningHorizon error will be returned .
pub fn fetch_checkpoint<T>(
    checkpoints: &T,
    pruned_mode: bool,
    tip_height: u64,
    height: u64,
) -> Result<Option<MerkleCheckPoint>, ChainStorageError>
where
    T: ArrayLike<Value = MerkleCheckPoint>,
    ChainStorageError: From<T::Error>,
{
    let tip_index = tip_height.saturating_sub(1);
    let height_offset = tip_index
        .checked_sub(height)
        .ok_or_else(|| ChainStorageError::OutOfRange)?;
    let last_cp_index = checkpoints.len()?.saturating_sub(1);
    let index = last_cp_index
        .checked_sub(height_offset as usize)
        .ok_or_else(|| ChainStorageError::BeyondPruningHorizon)?;
    if pruned_mode && index == 0 {
        // In pruned mode the first checkpoint is an accumulation of all checkpoints from the genesis block to horizon
        // block height.
        return Err(ChainStorageError::BeyondPruningHorizon);
    }
    checkpoints.get(index as usize).map_err(Into::into)
}
pub fn fetch_checkpoint < T > ( checkpoints : & T , pruned_mode : bool , tip_height : u64 , height : u64 , ) -> Result < Option < MerkleCheckPoint > , ChainStorageError > where T : ArrayLike < Value = MerkleCheckPoint > , ChainStorageError : From < T :: Error > , { let tip_index = tip_height . saturating_sub ( 1 ) ; let height_offset = tip_index . checked_sub ( height ) . ok_or_else ( | | ChainStorageError :: OutOfRange ) ? ; let last_cp_index = checkpoints . len ( ) ? . saturating_sub ( 1 ) ; let index = last_cp_index . checked_sub ( height_offset as usize ) . ok_or_else ( | | ChainStorageError :: BeyondPruningHorizon ) ? ; if pruned_mode && index == 0 { // In pruned mode the first checkpoint is an accumulation of all checkpoints from the genesis block to horizon // block height. return Err ( ChainStorageError :: BeyondPruningHorizon ) ; } checkpoints . get ( index as usize ) . map_err ( Into :: into ) }
Retrieves the checkpoint corresponding to the provided height, if the checkpoint is part of the horizon state then a
BeyondPruningHorizon error will be returned.
Retrieves the checkpoint corresponding to the provided height if the checkpoint is part of the horizon state then a BeyondPruningHorizon error will be returned .
checkpoints
&T
pruned_mode
bool
tip_height
u64
height
u64
checkpoints
&T
pruned_mode
bool
tip_height
u64
height
u64