Trait sc_network_common::sync::ChainSync
source · 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§
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 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 justification_requests(
&mut self
) -> Box<dyn Iterator<Item = (PeerId, BlockRequest<Block>)> + '_>
fn justification_requests(
&mut self
) -> Box<dyn Iterator<Item = (PeerId, BlockRequest<Block>)> + '_>
Get an iterator over all scheduled justification requests.
sourcefn block_requests(
&mut self
) -> Box<dyn Iterator<Item = (&PeerId, BlockRequest<Block>)> + '_>
fn block_requests(
&mut self
) -> Box<dyn Iterator<Item = (&PeerId, BlockRequest<Block>)> + '_>
Get an iterator over all block requests of all peers.
sourcefn state_request(&mut self) -> Option<(PeerId, OpaqueStateRequest)>
fn state_request(&mut self) -> Option<(PeerId, OpaqueStateRequest)>
Get a state request, if any.
sourcefn warp_sync_request(&mut self) -> Option<(PeerId, WarpProofRequest<Block>)>
fn warp_sync_request(&mut self) -> Option<(PeerId, WarpProofRequest<Block>)>
Get a warp sync request, if any.
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_state_data(
&mut self,
who: &PeerId,
response: OpaqueStateResponse
) -> Result<OnStateData<Block>, BadPeer>
fn on_state_data(
&mut self,
who: &PeerId,
response: OpaqueStateResponse
) -> Result<OnStateData<Block>, BadPeer>
Handle a response from the remote to a state request that we made.
sourcefn on_warp_sync_data(
&mut self,
who: &PeerId,
response: EncodedProof
) -> Result<(), BadPeer>
fn on_warp_sync_data(
&mut self,
who: &PeerId,
response: EncodedProof
) -> Result<(), BadPeer>
Handle a response from the remote to a warp proof request that we made.
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_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_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>>>
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.
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
.
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.
sourcefn peer_disconnected(&mut self, who: &PeerId) -> Option<OnBlockData<Block>>
fn peer_disconnected(&mut self, who: &PeerId) -> Option<OnBlockData<Block>>
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 create_opaque_block_request(
&self,
request: &BlockRequest<Block>
) -> OpaqueBlockRequest
fn create_opaque_block_request(
&self,
request: &BlockRequest<Block>
) -> OpaqueBlockRequest
Create implementation-specific block request.
sourcefn encode_block_request(
&self,
request: &OpaqueBlockRequest
) -> Result<Vec<u8>, String>
fn encode_block_request(
&self,
request: &OpaqueBlockRequest
) -> Result<Vec<u8>, String>
Encode implementation-specific block request.
sourcefn decode_block_response(
&self,
response: &[u8]
) -> Result<OpaqueBlockResponse, String>
fn decode_block_response(
&self,
response: &[u8]
) -> Result<OpaqueBlockResponse, String>
Decode implementation-specific block response.
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 encode_state_request(
&self,
request: &OpaqueStateRequest
) -> Result<Vec<u8>, String>
fn encode_state_request(
&self,
request: &OpaqueStateRequest
) -> Result<Vec<u8>, String>
Encode implementation-specific state request.
sourcefn decode_state_response(
&self,
response: &[u8]
) -> Result<OpaqueStateResponse, String>
fn decode_state_response(
&self,
response: &[u8]
) -> Result<OpaqueStateResponse, String>
Decode implementation-specific state response.