pub async fn request_block<T: Payload>(
        &mut self,
        block_id: HashValue,
        num_blocks: u64,
        from: Author,
        timeout: Duration,
    ) -> failure::Result<BlockRetrievalResponse<T>> {
        ensure!(from != self.author, "Retrieve block from self");
        let mut req_msg = RequestBlock::default();
        req_msg.block_id = block_id.to_vec();
        req_msg.num_blocks = num_blocks;
        counters::BLOCK_RETRIEVAL_COUNT.inc_by(num_blocks as i64);
        let pre_retrieval_instant = Instant::now();

        let res_block = self
            .network_sender
            .request_block(from, req_msg, timeout)
            .await?;
        let mut blocks = vec![];
        let status = res_block.status();
        for block in res_block.blocks.into_iter() {
            match Block::try_from(block) {
                Ok(block) => {
                    block
                        .validate_signatures(self.validators.as_ref())
                        .and_then(|_| block.verify_well_formed())
                        .with_context(|e| format_err!("Invalid block because of {:?}", e))?;
                    blocks.push(block);
                }
                Err(e) => bail!("Failed to deserialize block because of {:?}", e),
            };
        }
        counters::BLOCK_RETRIEVAL_DURATION_S.observe_duration(pre_retrieval_instant.elapsed());
        let response = BlockRetrievalResponse { status, blocks };
        response.verify(block_id, num_blocks)?;
        Ok(response)
    }
/// Tries to retrieve num of blocks backwards starting from id from the given peer: the function
/// returns a future that is either fulfilled with BlockRetrievalResponse, or with a
/// BlockRetrievalFailure.
Tries to retrieve num of blocks backwards starting from id from the given peer: the function
returns a future that is either fulfilled with BlockRetrievalResponse, or with a
BlockRetrievalFailure.
Tries to retrieve num of blocks backwards starting from id from the given peer : the function returns a future that is either fulfilled with BlockRetrievalResponse or with a BlockRetrievalFailure .
pub async fn request_block<T: Payload>(
        &mut self,
        block_id: HashValue,
        num_blocks: u64,
        from: Author,
        timeout: Duration,
    ) -> failure::Result<BlockRetrievalResponse<T>> {
        ensure!(from != self.author, "Retrieve block from self");
        let mut req_msg = RequestBlock::default();
        req_msg.block_id = block_id.to_vec();
        req_msg.num_blocks = num_blocks;
        counters::BLOCK_RETRIEVAL_COUNT.inc_by(num_blocks as i64);
        let pre_retrieval_instant = Instant::now();
        let res_block = self
            .network_sender
            .request_block(from, req_msg, timeout)
            .await?;
        let mut blocks = vec![];
        let status = res_block.status();
        for block in res_block.blocks.into_iter() {
            match Block::try_from(block) {
                Ok(block) => {
                    block
                        .validate_signatures(self.validators.as_ref())
                        .and_then(|_| block.verify_well_formed())
                        .with_context(|e| format_err!("Invalid block because of {:?}", e))?;
                    blocks.push(block);
                }
                Err(e) => bail!("Failed to deserialize block because of {:?}", e),
            };
        }
        counters::BLOCK_RETRIEVAL_DURATION_S.observe_duration(pre_retrieval_instant.elapsed());
        let response = BlockRetrievalResponse { status, blocks };
        response.verify(block_id, num_blocks)?;
        Ok(response)
    }
pub async fn request_block < T : Payload > ( & mut self , block_id : HashValue , num_blocks : u64 , from : Author , timeout : Duration , ) -> failure :: Result < BlockRetrievalResponse < T > > { ensure ! ( from self author " " ) ; let mut req_msg = RequestBlock :: default ( ) ; req_msg . block_id = block_id . to_vec ( ) ; req_msg . num_blocks = num_blocks ; counters :: BLOCK_RETRIEVAL_COUNT . inc_by ( num_blocks as i64 ) ; let pre_retrieval_instant = Instant :: now ( ) ; let res_block = self . network_sender . request_block ( from , req_msg , timeout ) . await ? ; let mut blocks = vec ! [ ] ; let status = res_block . status ( ) ; for block in res_block . blocks . into_iter ( ) { match Block :: try_from ( block ) { Ok ( block ) => { block . validate_signatures ( self . validators . as_ref ( ) ) . and_then ( | _ | block . verify_well_formed ( ) ) . with_context ( | e | format_err ! ( " " e ) ) ? ; blocks . push ( block ) ; } Err ( e ) => bail ! ( " " e ) , } ; } counters :: BLOCK_RETRIEVAL_DURATION_S . observe_duration ( pre_retrieval_instant . elapsed ( ) ) ; let response = BlockRetrievalResponse { status , blocks } ; response . verify ( block_id , num_blocks ) ? ; Ok ( response ) }
Tries to retrieve num of blocks backwards starting from id from the given peer: the function
returns a future that is either fulfilled with BlockRetrievalResponse, or with a
BlockRetrievalFailure.
Tries to retrieve num of blocks backwards starting from id from the given peer : the function returns a future that is either fulfilled with BlockRetrievalResponse or with a BlockRetrievalFailure .
&mut self
block_id
HashValue
num_blocks
u64
from
Author
timeout
Duration
&mut self
block_id
HashValue
num_blocks
u64
from
Author
timeout
Duration