/// download any state, check its hash and store it, if need to download block and proof we trust them already
download any state, check its hash and store it, if need to download block and proof we trust them already
download any state check its hash and store it if need to download block and proof we trust them already
async fn download_block_and_state(engine: &dyn EngineOperations, block_id: &BlockIdExt, master_id: &BlockIdExt) -> Result<BlockStuff> {
    let handle = engine.load_block_handle(block_id)?;
    let block = if !handle.data_inited() {
        let (block, proof) = engine.download_block(&handle, None).await?;
        engine.store_block(&handle, &block).await?;
        if !handle.proof_inited() {
            engine.store_block_proof(&handle, &proof).await?;
        }
        block
    } else {
        engine.load_block(&handle).await?
    };
    if !handle.state_inited() {
        let state_update = block.block().read_state_update()?;
        log::info!(target: "boot", "download state {}", handle.id());
        let state = engine.download_state(handle.id(), master_id).await?;
        let state_hash = state.root_cell().repr_hash();
        if state_update.new_hash != state_hash {
            fail!("root_hash {} of downloaded state {} is wrong", state_hash.to_hex_string(), handle.id())
        }
        engine.store_state(&handle, &state).await?;
        engine.process_full_state_in_ext_db(&state).await?;
    }
    engine.set_applied(&handle, master_id.seq_no()).await?;
    Ok(block)
}
async fn download_block_and_state ( engine : & dyn EngineOperations , block_id : & BlockIdExt , master_id : & BlockIdExt ) -> Result < BlockStuff > { let handle = engine . load_block_handle ( block_id ) ? ; let block = if ! handle . data_inited ( ) { let ( block , proof ) = engine . download_block ( & handle , None ) . await ? ; engine . store_block ( & handle , & block ) . await ? ; if ! handle . proof_inited ( ) { engine . store_block_proof ( & handle , & proof ) . await ? ; } block } else { engine . load_block ( & handle ) . await ? } ; if ! handle . state_inited ( ) { let state_update = block . block ( ) . read_state_update ( ) ? ; log :: info ! ( target " " " " handle id ( ) ) ; let state = engine . download_state ( handle . id ( ) , master_id ) . await ? ; let state_hash = state . root_cell ( ) . repr_hash ( ) ; if state_update . new_hash != state_hash { fail ! ( " " state_hash to_hex_string ( ) handle id ( ) ) } engine . store_state ( & handle , & state ) . await ? ; engine . process_full_state_in_ext_db ( & state ) . await ? ; } engine . set_applied ( & handle , master_id . seq_no ( ) ) . await ? ; Ok ( block ) }
download any state, check its hash and store it, if need to download block and proof we trust them already
download any state check its hash and store it if need to download block and proof we trust them already
engine
&dyn EngineOperations
block_id
&BlockIdExt
master_id
&BlockIdExt