Trait sc_network_common::sync::ChainSync
source · pub trait ChainSync<Block: BlockT>: Send {
Show 22 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 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(
&mut self,
cx: &mut Context<'_>
) -> 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§
sourcefn peer_info(&self, who: &PeerId) -> Option<PeerInfo<Block>>
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.
sourcefn status(&self) -> SyncStatus<Block>
fn status(&self) -> SyncStatus<Block>
Returns the current sync status.
sourcefn num_sync_requests(&self) -> usize
fn num_sync_requests(&self) -> usize
Number of active forks requests. This includes requests that are pending or could be issued right away.
sourcefn num_downloaded_blocks(&self) -> usize
fn num_downloaded_blocks(&self) -> usize
Number of downloaded blocks.
sourcefn num_peers(&self) -> usize
fn num_peers(&self) -> usize
Returns the current number of peers stored within this state machine.
sourcefn num_active_peers(&self) -> usize
fn num_active_peers(&self) -> usize
Returns the number of peers we’re connected to and that are being queried.
sourcefn new_peer(
&mut self,
who: PeerId,
best_hash: Block::Hash,
best_number: NumberFor<Block>
) -> Result<Option<BlockRequest<Block>>, BadPeer>
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.
sourcefn update_chain_info(
&mut self,
best_hash: &Block::Hash,
best_number: NumberFor<Block>
)
fn update_chain_info( &mut self, best_hash: &Block::Hash, best_number: NumberFor<Block> )
Signal that a new best block has been imported.
sourcefn request_justification(
&mut self,
hash: &Block::Hash,
number: NumberFor<Block>
)
fn request_justification( &mut self, hash: &Block::Hash, number: NumberFor<Block> )
Schedule a justification request for the given block.
sourcefn clear_justification_requests(&mut self)
fn clear_justification_requests(&mut self)
Clear all pending justification requests.
sourcefn set_sync_fork_request(
&mut self,
peers: Vec<PeerId>,
hash: &Block::Hash,
number: NumberFor<Block>
)
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.
sourcefn on_block_data(
&mut self,
who: &PeerId,
request: Option<BlockRequest<Block>>,
response: BlockResponse<Block>
) -> Result<OnBlockData<Block>, BadPeer>
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.
sourcefn on_block_justification(
&mut self,
who: PeerId,
response: BlockResponse<Block>
) -> Result<OnBlockJustification<Block>, BadPeer>
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
.
sourcefn on_justification_import(
&mut self,
hash: Block::Hash,
number: NumberFor<Block>,
success: bool
)
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.
sourcefn on_block_finalized(&mut self, hash: &Block::Hash, number: NumberFor<Block>)
fn on_block_finalized(&mut self, hash: &Block::Hash, number: NumberFor<Block>)
Notify about finalization of the given block.
sourcefn push_block_announce_validation(
&mut self,
who: PeerId,
hash: Block::Hash,
announce: BlockAnnounce<Block::Header>,
is_best: bool
)
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.
sourcefn poll_block_announce_validation(
&mut self,
cx: &mut Context<'_>
) -> Poll<PollBlockAnnounceValidation<Block::Header>>
fn poll_block_announce_validation( &mut self, cx: &mut Context<'_> ) -> 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
.
sourcefn peer_disconnected(&mut self, who: &PeerId)
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.
sourcefn block_response_into_blocks(
&self,
request: &BlockRequest<Block>,
response: OpaqueBlockResponse
) -> Result<Vec<BlockData<Block>>, String>
fn block_response_into_blocks( &self, request: &BlockRequest<Block>, response: OpaqueBlockResponse ) -> Result<Vec<BlockData<Block>>, String>
Access blocks from implementation-specific block response.
sourcefn poll(
&mut self,
cx: &mut Context<'_>
) -> Poll<PollBlockAnnounceValidation<Block::Header>>
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.
sourcefn send_block_request(&mut self, who: PeerId, request: BlockRequest<Block>)
fn send_block_request(&mut self, who: PeerId, request: BlockRequest<Block>)
Send block request to peer