pub trait ChainSync<Block: BlockT>: Send {
Show 23 methods // Required 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§

source

fn peer_info(&self, who: &PeerId) -> Option<PeerInfo<Block>>

Returns the state of the sync of the given peer.

Returns None if the peer is unknown.

source

fn status(&self) -> SyncStatus<Block>

Returns the current sync status.

source

fn num_sync_requests(&self) -> usize

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

source

fn num_downloaded_blocks(&self) -> usize

Number of downloaded blocks.

source

fn num_peers(&self) -> usize

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

source

fn num_active_peers(&self) -> usize

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

source

fn new_peer( &mut self, who: PeerId, best_hash: Block::Hash, best_number: NumberFor<Block> ) -> Result<Option<BlockRequest<Block>>, BadPeer>

Handle a new connected peer.

Call this method whenever we connect to a new peer.

source

fn update_chain_info( &mut self, best_hash: &Block::Hash, best_number: NumberFor<Block> )

Signal that a new best block has been imported.

source

fn request_justification( &mut self, hash: &Block::Hash, number: NumberFor<Block> )

Schedule a justification request for the given block.

source

fn clear_justification_requests(&mut self)

Clear all pending justification requests.

source

fn set_sync_fork_request( &mut self, peers: Vec<PeerId>, hash: &Block::Hash, number: NumberFor<Block> )

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

source

fn on_block_data( &mut self, who: &PeerId, request: Option<BlockRequest<Block>>, response: BlockResponse<Block> ) -> Result<OnBlockData<Block>, BadPeer>

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.

source

fn process_block_response_data( &mut self, blocks_to_import: Result<OnBlockData<Block>, BadPeer> )

Procss received block data.

source

fn on_block_justification( &mut self, who: PeerId, response: BlockResponse<Block> ) -> Result<OnBlockJustification<Block>, BadPeer>

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

request must be the original request that triggered response.

source

fn on_justification_import( &mut self, hash: Block::Hash, number: NumberFor<Block>, success: bool )

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

source

fn on_block_finalized(&mut self, hash: &Block::Hash, number: NumberFor<Block>)

Notify about finalization of the given block.

source

fn push_block_announce_validation( &mut self, who: PeerId, hash: Block::Hash, announce: BlockAnnounce<Block::Header>, is_best: bool )

Push a block announce validation.

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

source

fn poll_block_announce_validation<'a>( &mut self, cx: &mut Context<'a> ) -> Poll<PollBlockAnnounceValidation<Block::Header>>

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.

source

fn peer_disconnected(&mut self, who: &PeerId)

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.

source

fn metrics(&self) -> Metrics

Return some key metrics.

source

fn block_response_into_blocks( &self, request: &BlockRequest<Block>, response: OpaqueBlockResponse ) -> Result<Vec<BlockData<Block>>, String>

Access blocks from implementation-specific block response.

source

fn poll( &mut self, cx: &mut Context<'_> ) -> Poll<PollBlockAnnounceValidation<Block::Header>>

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.

source

fn send_block_request(&mut self, who: PeerId, request: BlockRequest<Block>)

Send block request to peer

Implementors§