/// Checks that the restored catch-up package contains the same state hash as
/// the one computed by the state manager from the restored artifacts and drops
/// all states below the last CUP.
Checks that the restored catch-up package contains the same state hash as
the one computed by the state manager from the restored artifacts and drops
all states below the last CUP.
Checks that the restored catch - up package contains the same state hash as the one computed by the state manager from the restored artifacts and drops all states below the last CUP .
pub(crate) fn assert_consistency_and_clean_up<T>(
    state_manager: &dyn StateManager<State = T>,
    pool: &mut ConsensusPoolImpl,
) {
    let last_cup = pool.get_cache().catch_up_package();
    if last_cup.height() == Height::from(0) {
        return;
    }
    let hash = match state_manager.get_state_hash_at(last_cup.height()) {
        Ok(hash) => hash,
        Err(StateHashError::Transient(err)) => {
            println!(
                "REPLAY WARN: no hash for the state at CUP height {:?}: {:?}",
                last_cup.height(),
                err
            );
            return;
        }
        Err(StateHashError::Permanent(err)) => {
            panic!(
                "REPLAY ERROR: couldn't fetch the state at CUP height {:?}: {:?}",
                last_cup.height(),
                err
            );
        }
    };
    assert_eq!(
        hash,
        last_cup.content.state_hash,
        "The hash state of the CUP at height {:?} does not correspond to the hash of the computed state",
        last_cup.height()
    );
    let purge_height = last_cup.height();
    println!("Removing all states below height {:?}", purge_height);
    state_manager.remove_states_below(purge_height);
    pool.apply_changes(
        &SysTimeSource::new(),
        ChangeAction::PurgeValidatedBelow(purge_height).into(),
    );
}
pub ( crate ) fn assert_consistency_and_clean_up < T > ( state_manager : & dyn StateManager < State = T > , pool : & mut ConsensusPoolImpl , ) { let last_cup = pool . get_cache ( ) . catch_up_package ( ) ; if last_cup . height ( ) == Height :: from ( 0 ) { return ; } let hash = match state_manager . get_state_hash_at ( last_cup . height ( ) ) { Ok ( hash ) => hash , Err ( StateHashError :: Transient ( err ) ) => { println ! ( " " last_cup height ( ) err ) ; return ; } Err ( StateHashError :: Permanent ( err ) ) => { panic ! ( " " last_cup height ( ) err ) ; } } ; assert_eq ! ( hash last_cup content state_hash " " last_cup height ( ) ) ; let purge_height = last_cup . height ( ) ; println ! ( " " purge_height ) ; state_manager . remove_states_below ( purge_height ) ; pool . apply_changes ( & SysTimeSource :: new ( ) , ChangeAction :: PurgeValidatedBelow ( purge_height ) . into ( ) , ) ; }
Checks that the restored catch-up package contains the same state hash as
the one computed by the state manager from the restored artifacts and drops
all states below the last CUP.
Checks that the restored catch - up package contains the same state hash as the one computed by the state manager from the restored artifacts and drops all states below the last CUP .
state_manager
&dyn StateManager<State = T>
pool
&mut ConsensusPoolImpl