pub trait ChainSync<Block: BlockT>: Send {
Show 23 methods fn peer_info(&self, who: &PeerId) -> Option<PeerInfo<Block>>; fn status(&self) -> SyncStatus<Block>; fn num_sync_requests(&self) -> usize; fn num_downloaded_blocks(&self) -> usize; fn num_peers(&self) -> usize; fn num_active_peers(&self) -> usize; fn new_peer(
        &mut self,
        who: PeerId,
        best_hash: Block::Hash,
        best_number: NumberFor<Block>
    ) -> Result<Option<BlockRequest<Block>>, BadPeer>; fn update_chain_info(
        &mut self,
        best_hash: &Block::Hash,
        best_number: NumberFor<Block>
    ); fn request_justification(
        &mut self,
        hash: &Block::Hash,
        number: NumberFor<Block>
    ); fn clear_justification_requests(&mut self); fn set_sync_fork_request(
        &mut self,
        peers: Vec<PeerId>,
        hash: &Block::Hash,
        number: NumberFor<Block>
    ); fn on_block_data(
        &mut self,
        who: &PeerId,
        request: Option<BlockRequest<Block>>,
        response: BlockResponse<Block>
    ) -> Result<OnBlockData<Block>, BadPeer>; fn process_block_response_data(
        &mut self,
        blocks_to_import: Result<OnBlockData<Block>, BadPeer>
    ); fn on_block_justification(
        &mut self,
        who: PeerId,
        response: BlockResponse<Block>
    ) -> Result<OnBlockJustification<Block>, BadPeer>; fn on_justification_import(
        &mut self,
        hash: Block::Hash,
        number: NumberFor<Block>,
        success: bool
    ); fn on_block_finalized(&mut self, hash: &Block::Hash, number: NumberFor<Block>); fn push_block_announce_validation(
        &mut self,
        who: PeerId,
        hash: Block::Hash,
        announce: BlockAnnounce<Block::Header>,
        is_best: bool
    ); fn poll_block_announce_validation<'a>(
        &mut self,
        cx: &mut Context<'a>
    ) -> Poll<PollBlockAnnounceValidation<Block::Header>>; fn peer_disconnected(&mut self, who: &PeerId); fn metrics(&self) -> Metrics; fn block_response_into_blocks(
        &self,
        request: &BlockRequest<Block>,
        response: OpaqueBlockResponse
    ) -> Result<Vec<BlockData<Block>>, String>; fn poll(
        &mut self,
        cx: &mut Context<'_>
    ) -> Poll<PollBlockAnnounceValidation<Block::Header>>; fn send_block_request(&mut self, who: PeerId, request: BlockRequest<Block>);
}
Expand description

Something that represents the syncing strategy to download past and future blocks of the chain.

Required Methods§

Returns the state of the sync of the given peer.

Returns None if the peer is unknown.

Returns the current sync status.

Number of active forks requests. This includes requests that are pending or could be issued right away.

Number of downloaded blocks.

Returns the current number of peers stored within this state machine.

Returns the number of peers we’re connected to and that are being queried.

Handle a new connected peer.

Call this method whenever we connect to a new peer.

Signal that a new best block has been imported.

Schedule a justification request for the given block.

Clear all pending justification requests.

Request syncing for the given block from given set of peers.

Handle a response from the remote to a block request that we made.

request must be the original request that triggered response. or None if data comes from the block announcement.

If this corresponds to a valid block, this outputs the block that must be imported in the import queue.

Procss received block data.

Handle a response from the remote to a justification request that we made.

request must be the original request that triggered response.

Call this when a justification has been processed by the import queue, with or without errors.

Notify about finalization of the given block.

Push a block announce validation.

It is required that ChainSync::poll_block_announce_validation is called to check for finished block announce validations.

Poll block announce validation.

Block announce validations can be pushed by using ChainSync::push_block_announce_validation.

This should be polled until it returns Poll::Pending.

If PollBlockAnnounceValidation::ImportHeader is returned, then the caller MUST try to import passed header (call on_block_data). The network request isn’t sent in this case.

Call when a peer has disconnected. Canceled obsolete block request may result in some blocks being ready for import, so this functions checks for such blocks and returns them.

Return some key metrics.

Access blocks from implementation-specific block response.

Advance the state of ChainSync

Internally calls ChainSync::poll_block_announce_validation() and this function should be polled until it returns Poll::Pending to consume all pending events.

Send block request to peer

Implementors§