// build bundle for a validating (just now) block. 
// Uses real engine for top shard blocks and external messages.
build bundle for a validating (just now) block.
Uses real engine for top shard blocks and external messages.
build bundle for a validating ( just now ) block . Uses real engine for top shard blocks and external messages .
pub async fn build_for_validating_block(
        shard: ShardIdent,
        _min_masterchain_block_id: BlockIdExt,
        prev_blocks_ids: Vec<BlockIdExt>,
        candidate: BlockCandidate,
        engine: Arc<dyn EngineOperations>,
    ) -> Result<Self> {
        log::info!("Building for validating block, candidate: {}", candidate.block_id);
        let mut states = HashMap::new();
        let is_master = shard.is_masterchain();
        //
        // last mc state
        //
        let mc_state = engine.load_last_applied_mc_state().await?;
        let last_mc_id = mc_state.block_id();
        let mut oldest_mc_seq_no = last_mc_id.seq_no();
        let mut newest_mc_seq_no = last_mc_id.seq_no();
        //
        // top shard blocks
        //
        let top_shard_blocks = if is_master {
            engine.get_shard_blocks(last_mc_id.seq_no())?
        } else {
            vec![]
        };
        //
        // external messages
        //
        let external_messages = engine.get_external_messages(&shard)?;
        // 
        // neighbors
        //
        let mut neighbors = vec!();
        let shards = mc_state.shard_state_extra()?.shards();
        let neighbor_list = shards.get_neighbours(&shard)?;
        for shard in neighbor_list.iter() {
            states.insert(shard.block_id().clone(), engine.load_state(shard.block_id()).await?);
            neighbors.push(shard.block_id().clone());
        }
        if shards.is_empty() || mc_state.block_id().seq_no() != 0 {
            states.insert(mc_state.block_id().clone(), mc_state.clone());
        }
        //
        // prev_blocks & states
        //
        let mut blocks = HashMap::new();
        let prev1 = engine.load_block(engine.load_block_handle(&prev_blocks_ids[0])?.deref()).await?;
        states.insert(prev_blocks_ids[0].clone(), engine.load_state(&prev_blocks_ids[0]).await?);
        blocks.insert(prev_blocks_ids[0].clone(), prev1);
        if prev_blocks_ids.len() > 1 {
            let prev2 = engine.load_block(engine.load_block_handle(&prev_blocks_ids[1])?.deref()).await?;
            states.insert(prev_blocks_ids[1].clone(), engine.load_state(&prev_blocks_ids[1]).await?);
            blocks.insert(prev_blocks_ids[1].clone(), prev2);
        }
        // collect needed mc states
        for (_, state) in states.iter() {
            let nb = OutMsgQueueInfoStuff::from_shard_state(state)?;
            for entry in nb.entries() {
                if entry.mc_seqno < oldest_mc_seq_no {
                    oldest_mc_seq_no = entry.mc_seqno;
                } else if entry.mc_seqno > newest_mc_seq_no {
                    newest_mc_seq_no = entry.mc_seqno;
                }
            }
        }
        // mc states and merkle updates
        let mc_pfx = AccountIdPrefixFull::any_masterchain();
        let oldest_mc_state = engine.load_state(
            engine.find_block_by_seq_no(&mc_pfx, oldest_mc_seq_no).await?.id()
        ).await?;
        let mut mc_states = vec!(oldest_mc_state.block_id().clone());
        states.insert(oldest_mc_state.block_id().clone(), oldest_mc_state);
        let mut mc_merkle_updates = HashMap::new();
        for mc_seq_no in oldest_mc_seq_no + 1..=newest_mc_seq_no {
            let handle = engine.find_block_by_seq_no(&mc_pfx, mc_seq_no).await?;
            let block = engine.load_block(&handle).await?;
            mc_merkle_updates.insert(block.id().clone(), block.block().read_state_update()?);
            states.insert(block.id().clone(), engine.load_state(block.id()).await?);
            mc_states.push(block.id().clone());
        }
        let index = CollatorTestBundleIndex {
            id: candidate.block_id.clone(),
            top_shard_blocks: top_shard_blocks.iter().map(|tsb| tsb.proof_for().clone()).collect(),
            external_messages: external_messages.iter().map(|(_, id)| id.clone()).collect(),
            last_mc_state: last_mc_id.clone(),
            min_ref_mc_seqno: oldest_mc_seq_no,
            mc_states,
            neighbors,
            prev_blocks: prev_blocks_ids,
            created_by: candidate.created_by.clone(),
            rand_seed: None,
            now: engine.now(),
            fake: true,
            contains_ethalon: false,
            contains_candidate: true,
        };
        Ok(Self {
            index,
            top_shard_blocks,
            external_messages,
            states,
            mc_merkle_updates,
            blocks,
            aux_mc_shard_states: lockfree::map::Map::new(),
            shard_states_cache: lockfree::map::Map::new(),
            block_handle_cache: Arc::new(lockfree::map::Map::new()),
            candidate: Some(candidate),
        })
    }
pub async fn build_for_validating_block ( shard : ShardIdent , _min_masterchain_block_id : BlockIdExt , prev_blocks_ids : Vec < BlockIdExt > , candidate : BlockCandidate , engine : Arc < dyn EngineOperations > , ) -> Result < Self > { log :: info ! ( " " candidate block_id ) ; let mut states = HashMap :: new ( ) ; let is_master = shard . is_masterchain ( ) ; // // last mc state // let mc_state = engine . load_last_applied_mc_state ( ) . await ? ; let last_mc_id = mc_state . block_id ( ) ; let mut oldest_mc_seq_no = last_mc_id . seq_no ( ) ; let mut newest_mc_seq_no = last_mc_id . seq_no ( ) ; // // top shard blocks // let top_shard_blocks = if is_master { engine . get_shard_blocks ( last_mc_id . seq_no ( ) ) ? } else { vec ! [ ] } ; // // external messages // let external_messages = engine . get_external_messages ( & shard ) ? ; //  // neighbors // let mut neighbors = vec ! ( ) ; let shards = mc_state . shard_state_extra ( ) ? . shards ( ) ; let neighbor_list = shards . get_neighbours ( & shard ) ? ; for shard in neighbor_list . iter ( ) { states . insert ( shard . block_id ( ) . clone ( ) , engine . load_state ( shard . block_id ( ) ) . await ? ) ; neighbors . push ( shard . block_id ( ) . clone ( ) ) ; } if shards . is_empty ( ) || mc_state . block_id ( ) . seq_no ( ) != 0 { states . insert ( mc_state . block_id ( ) . clone ( ) , mc_state . clone ( ) ) ; } // // prev_blocks & states // let mut blocks = HashMap :: new ( ) ; let prev1 = engine . load_block ( engine . load_block_handle ( & prev_blocks_ids [ 0 ] ) ? . deref ( ) ) . await ? ; states . insert ( prev_blocks_ids [ 0 ] . clone ( ) , engine . load_state ( & prev_blocks_ids [ 0 ] ) . await ? ) ; blocks . insert ( prev_blocks_ids [ 0 ] . clone ( ) , prev1 ) ; if prev_blocks_ids . len ( ) > 1 { let prev2 = engine . load_block ( engine . load_block_handle ( & prev_blocks_ids [ 1 ] ) ? . deref ( ) ) . await ? ; states . insert ( prev_blocks_ids [ 1 ] . clone ( ) , engine . load_state ( & prev_blocks_ids [ 1 ] ) . await ? ) ; blocks . insert ( prev_blocks_ids [ 1 ] . clone ( ) , prev2 ) ; } // collect needed mc states for ( _ , state ) in states . iter ( ) { let nb = OutMsgQueueInfoStuff :: from_shard_state ( state ) ? ; for entry in nb . entries ( ) { if entry . mc_seqno < oldest_mc_seq_no { oldest_mc_seq_no = entry . mc_seqno ; } else if entry . mc_seqno > newest_mc_seq_no { newest_mc_seq_no = entry . mc_seqno ; } } } // mc states and merkle updates let mc_pfx = AccountIdPrefixFull :: any_masterchain ( ) ; let oldest_mc_state = engine . load_state ( engine . find_block_by_seq_no ( & mc_pfx , oldest_mc_seq_no ) . await ? . id ( ) ) . await ? ; let mut mc_states = vec ! ( oldest_mc_state block_id ( ) clone ( ) ) ; states . insert ( oldest_mc_state . block_id ( ) . clone ( ) , oldest_mc_state ) ; let mut mc_merkle_updates = HashMap :: new ( ) ; for mc_seq_no in oldest_mc_seq_no + 1 ..= newest_mc_seq_no { let handle = engine . find_block_by_seq_no ( & mc_pfx , mc_seq_no ) . await ? ; let block = engine . load_block ( & handle ) . await ? ; mc_merkle_updates . insert ( block . id ( ) . clone ( ) , block . block ( ) . read_state_update ( ) ? ) ; states . insert ( block . id ( ) . clone ( ) , engine . load_state ( block . id ( ) ) . await ? ) ; mc_states . push ( block . id ( ) . clone ( ) ) ; } let index = CollatorTestBundleIndex { id : candidate . block_id . clone ( ) , top_shard_blocks : top_shard_blocks . iter ( ) . map ( | tsb | tsb . proof_for ( ) . clone ( ) ) . collect ( ) , external_messages : external_messages . iter ( ) . map ( | ( _ , id ) | id . clone ( ) ) . collect ( ) , last_mc_state : last_mc_id . clone ( ) , min_ref_mc_seqno : oldest_mc_seq_no , mc_states , neighbors , prev_blocks : prev_blocks_ids , created_by : candidate . created_by . clone ( ) , rand_seed : None , now : engine . now ( ) , fake : true , contains_ethalon : false , contains_candidate : true , } ; Ok ( Self { index , top_shard_blocks , external_messages , states , mc_merkle_updates , blocks , aux_mc_shard_states : lockfree :: map :: Map :: new ( ) , shard_states_cache : lockfree :: map :: Map :: new ( ) , block_handle_cache : Arc :: new ( lockfree :: map :: Map :: new ( ) ) , candidate : Some ( candidate ) , } ) }
build bundle for a validating (just now) block.
build bundle for a validating ( just now ) block .
shard
ShardIdent
_min_masterchain_block_id
BlockIdExt
prev_blocks_ids
Vec<BlockIdExt>
candidate
BlockCandidate
engine
Arc<dyn EngineOperations>