Trait sc_network_sync::strategy::SyncingStrategy
source · pub trait SyncingStrategy<B>: Sendwhere
B: BlockT,{
Show 17 methods
// Required methods
fn add_peer(
&mut self,
peer_id: PeerId,
best_hash: B::Hash,
best_number: NumberFor<B>,
);
fn remove_peer(&mut self, peer_id: &PeerId);
fn on_validated_block_announce(
&mut self,
is_best: bool,
peer_id: PeerId,
announce: &BlockAnnounce<B::Header>,
) -> Option<(B::Hash, NumberFor<B>)>;
fn set_sync_fork_request(
&mut self,
peers: Vec<PeerId>,
hash: &B::Hash,
number: NumberFor<B>,
);
fn request_justification(&mut self, hash: &B::Hash, number: NumberFor<B>);
fn clear_justification_requests(&mut self);
fn on_justification_import(
&mut self,
hash: B::Hash,
number: NumberFor<B>,
success: bool,
);
fn on_generic_response(
&mut self,
peer_id: &PeerId,
key: StrategyKey,
protocol_name: ProtocolName,
response: Box<dyn Any + Send>,
);
fn on_blocks_processed(
&mut self,
imported: usize,
count: usize,
results: Vec<(Result<BlockImportStatus<NumberFor<B>>, BlockImportError>, B::Hash)>,
);
fn on_block_finalized(&mut self, hash: &B::Hash, number: NumberFor<B>);
fn update_chain_info(
&mut self,
best_hash: &B::Hash,
best_number: NumberFor<B>,
);
fn is_major_syncing(&self) -> bool;
fn num_peers(&self) -> usize;
fn status(&self) -> SyncStatus<B>;
fn num_downloaded_blocks(&self) -> usize;
fn num_sync_requests(&self) -> usize;
fn actions(
&mut self,
network_service: &NetworkServiceHandle,
) -> Result<Vec<SyncingAction<B>>, ClientError>;
}
Expand description
Syncing strategy for syncing engine to use
Required Methods§
sourcefn add_peer(
&mut self,
peer_id: PeerId,
best_hash: B::Hash,
best_number: NumberFor<B>,
)
fn add_peer( &mut self, peer_id: PeerId, best_hash: B::Hash, best_number: NumberFor<B>, )
Notify syncing state machine that a new sync peer has connected.
sourcefn remove_peer(&mut self, peer_id: &PeerId)
fn remove_peer(&mut self, peer_id: &PeerId)
Notify that a sync peer has disconnected.
sourcefn on_validated_block_announce(
&mut self,
is_best: bool,
peer_id: PeerId,
announce: &BlockAnnounce<B::Header>,
) -> Option<(B::Hash, NumberFor<B>)>
fn on_validated_block_announce( &mut self, is_best: bool, peer_id: PeerId, announce: &BlockAnnounce<B::Header>, ) -> Option<(B::Hash, NumberFor<B>)>
Submit a validated block announcement.
Returns new best hash & best number of the peer if they are updated.
sourcefn set_sync_fork_request(
&mut self,
peers: Vec<PeerId>,
hash: &B::Hash,
number: NumberFor<B>,
)
fn set_sync_fork_request( &mut self, peers: Vec<PeerId>, hash: &B::Hash, number: NumberFor<B>, )
Configure an explicit fork sync request in case external code has detected that there is a stale fork missing.
Note that this function should not be used for recent blocks. Sync should be able to download all the recent forks normally.
Passing empty peers
set effectively removes the sync request.
sourcefn request_justification(&mut self, hash: &B::Hash, number: NumberFor<B>)
fn request_justification(&mut self, hash: &B::Hash, number: NumberFor<B>)
Request extra justification.
sourcefn clear_justification_requests(&mut self)
fn clear_justification_requests(&mut self)
Clear extra justification requests.
sourcefn on_justification_import(
&mut self,
hash: B::Hash,
number: NumberFor<B>,
success: bool,
)
fn on_justification_import( &mut self, hash: B::Hash, number: NumberFor<B>, success: bool, )
Report a justification import (successful or not).
sourcefn on_generic_response(
&mut self,
peer_id: &PeerId,
key: StrategyKey,
protocol_name: ProtocolName,
response: Box<dyn Any + Send>,
)
fn on_generic_response( &mut self, peer_id: &PeerId, key: StrategyKey, protocol_name: ProtocolName, response: Box<dyn Any + Send>, )
Process generic response.
Strategy has to create opaque response and should be to downcast it back into concrete type internally. Failure to downcast is an implementation bug.
sourcefn on_blocks_processed(
&mut self,
imported: usize,
count: usize,
results: Vec<(Result<BlockImportStatus<NumberFor<B>>, BlockImportError>, B::Hash)>,
)
fn on_blocks_processed( &mut self, imported: usize, count: usize, results: Vec<(Result<BlockImportStatus<NumberFor<B>>, BlockImportError>, B::Hash)>, )
A batch of blocks that have been processed, with or without errors.
Call this when a batch of blocks that have been processed by the import queue, with or without errors.
sourcefn on_block_finalized(&mut self, hash: &B::Hash, number: NumberFor<B>)
fn on_block_finalized(&mut self, hash: &B::Hash, number: NumberFor<B>)
Notify a syncing strategy that a block has been finalized.
sourcefn update_chain_info(&mut self, best_hash: &B::Hash, best_number: NumberFor<B>)
fn update_chain_info(&mut self, best_hash: &B::Hash, best_number: NumberFor<B>)
Inform sync about a new best imported block.
fn is_major_syncing(&self) -> bool
sourcefn status(&self) -> SyncStatus<B>
fn status(&self) -> SyncStatus<B>
Returns the current sync status.
sourcefn num_downloaded_blocks(&self) -> usize
fn num_downloaded_blocks(&self) -> usize
Get the total number of downloaded blocks.
sourcefn num_sync_requests(&self) -> usize
fn num_sync_requests(&self) -> usize
Get an estimate of the number of parallel sync requests.
sourcefn actions(
&mut self,
network_service: &NetworkServiceHandle,
) -> Result<Vec<SyncingAction<B>>, ClientError>
fn actions( &mut self, network_service: &NetworkServiceHandle, ) -> Result<Vec<SyncingAction<B>>, ClientError>
Get actions that should be performed by the owner on the strategy’s behalf