/// Search through the blockstore and return a tuple containing:
///   - the first block with a missing state root
///   - the state root of that blocks predecessor
Search through the blockstore and return a tuple containing:
the first block with a missing state root
the state root of that blocks predecessor
Search through the blockstore and return a tuple containing : the first block with a missing state root the state root of that blocks predecessor
fn search_for_present_state_root(
    commit_store: &CommitStore,
    state_view_factory: &StateViewFactory,
    initial_state_root: &str,
) -> Result<Option<(BlockPair, String)>, StateVerificationError> {
    // If there is no chain to process, then we are done.
    let block = match commit_store.get_chain_head() {
        Ok(block) => block,
        Err(DatabaseError::NotFoundError(_)) => return Ok(None),
        Err(err) => {
            return Err(StateVerificationError::InvalidChainError(format!(
                "Unable to check for chain head: {}",
                err
            )))
        }
    };
    // Check the head first
    if state_view_factory
        .create_view::<SettingsView>(block.header().state_root_hash())
        .is_ok()
    {
        return Ok(None);
    }
    let mut previous_state_root = initial_state_root.to_string();
    for block in commit_store.get_block_by_height_iter(None, ByHeightDirection::Increasing) {
        if state_view_factory
            .create_view::<SettingsView>(block.header().state_root_hash())
            .is_err()
        {
            return Ok(Some((block, previous_state_root)));
        }
        previous_state_root = hex::encode(block.header().state_root_hash());
    }
    // This should never happen, since we already checked that the chain head
    // didn't have a state root
    Err(StateVerificationError::InvalidChainError(
        "Chain head state missing but all blocks had state root present".to_string(),
    ))
}
fn search_for_present_state_root ( commit_store : & CommitStore , state_view_factory : & StateViewFactory , initial_state_root : & str , ) -> Result < Option < ( BlockPair , String ) > , StateVerificationError > { // If there is no chain to process, then we are done. let block = match commit_store . get_chain_head ( ) { Ok ( block ) => block , Err ( DatabaseError :: NotFoundError ( _ ) ) => return Ok ( None ) , Err ( err ) => { return Err ( StateVerificationError :: InvalidChainError ( format ! ( " " err ) ) ) } } ; // Check the head first if state_view_factory . create_view :: < SettingsView > ( block . header ( ) . state_root_hash ( ) ) . is_ok ( ) { return Ok ( None ) ; } let mut previous_state_root = initial_state_root . to_string ( ) ; for block in commit_store . get_block_by_height_iter ( None , ByHeightDirection :: Increasing ) { if state_view_factory . create_view :: < SettingsView > ( block . header ( ) . state_root_hash ( ) ) . is_err ( ) { return Ok ( Some ( ( block , previous_state_root ) ) ) ; } previous_state_root = hex :: encode ( block . header ( ) . state_root_hash ( ) ) ; } // This should never happen, since we already checked that the chain head // didn't have a state root Err ( StateVerificationError :: InvalidChainError ( " " . to_string ( ) , ) ) }
Search through the blockstore and return a tuple containing:
 the first block with a missing state root
 the state root of that blocks predecessor
Search through the blockstore and return a tuple containing : the first block with a missing state root the state root of that blocks predecessor
commit_store
&CommitStore
state_view_factory
&StateViewFactory
initial_state_root
&str