pub trait ChainSync<Block: BlockT>: Send {
Show 31 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 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 justification_requests(
        &mut self
    ) -> Box<dyn Iterator<Item = (PeerId, BlockRequest<Block>)> + '_>; fn block_requests(
        &mut self
    ) -> Box<dyn Iterator<Item = (&PeerId, BlockRequest<Block>)> + '_>; fn state_request(&mut self) -> Option<(PeerId, OpaqueStateRequest)>; fn warp_sync_request(&mut self) -> Option<(PeerId, WarpProofRequest<Block>)>; fn on_block_data(
        &mut self,
        who: &PeerId,
        request: Option<BlockRequest<Block>>,
        response: BlockResponse<Block>
    ) -> Result<OnBlockData<Block>, BadPeer>; fn on_state_data(
        &mut self,
        who: &PeerId,
        response: OpaqueStateResponse
    ) -> Result<OnStateData<Block>, BadPeer>; fn on_warp_sync_data(
        &mut self,
        who: &PeerId,
        response: EncodedProof
    ) -> Result<(), BadPeer>; fn on_block_justification(
        &mut self,
        who: PeerId,
        response: BlockResponse<Block>
    ) -> Result<OnBlockJustification<Block>, BadPeer>; fn on_blocks_processed(
        &mut self,
        imported: usize,
        count: usize,
        results: Vec<(Result<BlockImportStatus<NumberFor<Block>>, BlockImportError>, Block::Hash)>
    ) -> Box<dyn Iterator<Item = Result<(PeerId, BlockRequest<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(
        &mut self,
        cx: &mut Context<'_>
    ) -> Poll<PollBlockAnnounceValidation<Block::Header>>; fn peer_disconnected(&mut self, who: &PeerId) -> Option<OnBlockData<Block>>; fn metrics(&self) -> Metrics; fn create_opaque_block_request(
        &self,
        request: &BlockRequest<Block>
    ) -> OpaqueBlockRequest; fn encode_block_request(
        &self,
        request: &OpaqueBlockRequest
    ) -> Result<Vec<u8>, String>; fn decode_block_response(
        &self,
        response: &[u8]
    ) -> Result<OpaqueBlockResponse, String>; fn block_response_into_blocks(
        &self,
        request: &BlockRequest<Block>,
        response: OpaqueBlockResponse
    ) -> Result<Vec<BlockData<Block>>, String>; fn encode_state_request(
        &self,
        request: &OpaqueStateRequest
    ) -> Result<Vec<u8>, String>; fn decode_state_response(
        &self,
        response: &[u8]
    ) -> Result<OpaqueStateResponse, String>;
}
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.

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.

Get an iterator over all scheduled justification requests.

Get an iterator over all block requests of all peers.

Get a state request, if any.

Get a warp sync request, if any.

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.

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

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

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

request must be the original request that triggered response.

A batch of blocks have been processed, with or without errors.

Call this when a batch of blocks have been processed by the import queue, with or without errors.

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.

Create implementation-specific block request.

Encode implementation-specific block request.

Decode implementation-specific block response.

Access blocks from implementation-specific block response.

Encode implementation-specific state request.

Decode implementation-specific state response.

Implementors§