pub fn fetch_block(
    config: &Configuration,
    hash: HeaderHash,
    logger: &Logger,
) -> Result<Block, FetchBlockError> {
    if config.protocol != Protocol::Grpc {
        unimplemented!()
    }

    if config.trusted_peers.is_empty() {
        return Err(FetchBlockError::NoTrustedPeers);
    }

    let mut block = None;

    let logger = logger.new(o!("block" => hash.to_string()));

    for address in trusted_peers_shuffled(&config) {
        let logger = logger.new(o!("peer_address" => address.to_string()));
        let peer = Peer::new(address, Protocol::Grpc);
        match grpc::fetch_block(peer, hash, &logger) {
            Err(grpc::FetchBlockError::Connect { source: e }) => {
                warn!(logger, "unable to reach peer for block download"; "reason" => %e);
            }
            Err(e) => {
                warn!(logger, "failed to download block"; "error" => ?e);
            }
            Ok(b) => {
                info!(logger, "initial bootstrap completed");
                block = Some(b);
                break;
            }
        }
    }

    if let Some(block) = block {
        Ok(block)
    } else {
        Err(FetchBlockError::CouldNotDownloadBlock {
            block: hash.to_owned(),
        })
    }
}
/// Queries the trusted peers for a block identified with the hash.
/// The calling thread is blocked until the block is retrieved.
/// This function is called during blockchain initialization
/// to retrieve the genesis block.
Queries the trusted peers for a block identified with the hash.
The calling thread is blocked until the block is retrieved.
This function is called during blockchain initialization
to retrieve the genesis block.
Queries the trusted peers for a block identified with the hash . The calling thread is blocked until the block is retrieved . This function is called during blockchain initialization to retrieve the genesis block .
pub fn fetch_block(
    config: &Configuration,
    hash: HeaderHash,
    logger: &Logger,
) -> Result<Block, FetchBlockError> {
    if config.protocol != Protocol::Grpc {
        unimplemented!()
    }
    if config.trusted_peers.is_empty() {
        return Err(FetchBlockError::NoTrustedPeers);
    }
    let mut block = None;
    let logger = logger.new(o!("block" => hash.to_string()));
    for address in trusted_peers_shuffled(&config) {
        let logger = logger.new(o!("peer_address" => address.to_string()));
        let peer = Peer::new(address, Protocol::Grpc);
        match grpc::fetch_block(peer, hash, &logger) {
            Err(grpc::FetchBlockError::Connect { source: e }) => {
                warn!(logger, "unable to reach peer for block download"; "reason" => %e);
            }
            Err(e) => {
                warn!(logger, "failed to download block"; "error" => ?e);
            }
            Ok(b) => {
                info!(logger, "initial bootstrap completed");
                block = Some(b);
                break;
            }
        }
    }
    if let Some(block) = block {
        Ok(block)
    } else {
        Err(FetchBlockError::CouldNotDownloadBlock {
            block: hash.to_owned(),
        })
    }
}
pub fn fetch_block ( config : & Configuration , hash : HeaderHash , logger : & Logger , ) -> Result < Block , FetchBlockError > { if config . protocol != Protocol :: Grpc { unimplemented ! ( ) } if config . trusted_peers . is_empty ( ) { return Err ( FetchBlockError :: NoTrustedPeers ) ; } let mut block = None ; let logger = logger . new ( o ! ( " " hash to_string ( ) ) ) ; for address in trusted_peers_shuffled ( & config ) { let logger = logger . new ( o ! ( " " address to_string ( ) ) ) ; let peer = Peer :: new ( address , Protocol :: Grpc ) ; match grpc :: fetch_block ( peer , hash , & logger ) { Err ( grpc :: FetchBlockError :: Connect { source : e } ) => { warn ! ( logger " " " " e ) ; } Err ( e ) => { warn ! ( logger " " " " e ) ; } Ok ( b ) => { info ! ( logger " " ) ; block = Some ( b ) ; break ; } } } if let Some ( block ) = block { Ok ( block ) } else { Err ( FetchBlockError :: CouldNotDownloadBlock { block : hash . to_owned ( ) , } ) } }
Queries the trusted peers for a block identified with the hash.
Queries the trusted peers for a block identified with the hash .
config
&Configuration
hash
HeaderHash
logger
&Logger
config
&Configuration
hash
HeaderHash
logger
&Logger