/// Attempt to merge the set of oldest checkpoints into the horizon state and return the number of checkpoints that have
/// been merged.
Attempt to merge the set of oldest checkpoints into the horizon state and return the number of checkpoints that have
been merged.
Attempt to merge the set of oldest checkpoints into the horizon state and return the number of checkpoints that have been merged .
pub fn merge_checkpoints<T>(checkpoints: &mut T, max_cp_count: usize) -> Result<(usize, Vec<u32>), ChainStorageError>
where
    T: ArrayLike<Value = MerkleCheckPoint> + ArrayLikeExt<Value = MerkleCheckPoint>,
    ChainStorageError: From<T::Error>,
{
    let cp_count = checkpoints.len()?;
    let mut stxo_leaf_indices = Vec::new();
    match (cp_count + 1).checked_sub(max_cp_count) {
        Some(num_cps_merged) => match checkpoints.get(0)? {
            Some(mut merged_cp) => {
                for index in 1..num_cps_merged {
                    if let Some(cp) = checkpoints.get(index)? {
                        stxo_leaf_indices.append(&mut cp.nodes_deleted().to_vec());
                        merged_cp.append(cp);
                    }
                }
                checkpoints.shift(num_cps_merged)?;
                checkpoints.push_front(merged_cp)?;
                Ok((num_cps_merged, stxo_leaf_indices))
            },
            None => Ok((0, stxo_leaf_indices)),
        },
        None => Ok((0, stxo_leaf_indices)),
    }
}
pub fn merge_checkpoints < T > ( checkpoints : & mut T , max_cp_count : usize ) -> Result < ( usize , Vec < u32 > ) , ChainStorageError > where T : ArrayLike < Value = MerkleCheckPoint > + ArrayLikeExt < Value = MerkleCheckPoint > , ChainStorageError : From < T :: Error > , { let cp_count = checkpoints . len ( ) ? ; let mut stxo_leaf_indices = Vec :: new ( ) ; match ( cp_count + 1 ) . checked_sub ( max_cp_count ) { Some ( num_cps_merged ) => match checkpoints . get ( 0 ) ? { Some ( mut merged_cp ) => { for index in 1 .. num_cps_merged { if let Some ( cp ) = checkpoints . get ( index ) ? { stxo_leaf_indices . append ( & mut cp . nodes_deleted ( ) . to_vec ( ) ) ; merged_cp . append ( cp ) ; } } checkpoints . shift ( num_cps_merged ) ? ; checkpoints . push_front ( merged_cp ) ? ; Ok ( ( num_cps_merged , stxo_leaf_indices ) ) } , None => Ok ( ( 0 , stxo_leaf_indices ) ) , } , None => Ok ( ( 0 , stxo_leaf_indices ) ) , } }
Attempt to merge the set of oldest checkpoints into the horizon state and return the number of checkpoints that have
been merged.
Attempt to merge the set of oldest checkpoints into the horizon state and return the number of checkpoints that have been merged .
checkpoints
&mut T
max_cp_count
usize