Struct sc_network_sync::strategy::chain_sync::ChainSync
source · pub struct ChainSync<B: BlockT, Client> { /* private fields */ }
Expand description
The main data structure which contains all the state for a chains active syncing strategy.
Implementations§
source§impl<B, Client> ChainSync<B, Client>where
B: BlockT,
Client: HeaderBackend<B> + BlockBackend<B> + HeaderMetadata<B, Error = Error> + ProofProvider<B> + Send + Sync + 'static,
impl<B, Client> ChainSync<B, Client>where
B: BlockT,
Client: HeaderBackend<B> + BlockBackend<B> + HeaderMetadata<B, Error = Error> + ProofProvider<B> + Send + Sync + 'static,
sourcepub fn new(
mode: ChainSyncMode,
client: Arc<Client>,
max_parallel_downloads: u32,
max_blocks_per_request: u32,
metrics_registry: Option<Registry>,
initial_peers: impl Iterator<Item = (PeerId, B::Hash, NumberFor<B>)>,
) -> Result<Self, ClientError>
pub fn new( mode: ChainSyncMode, client: Arc<Client>, max_parallel_downloads: u32, max_blocks_per_request: u32, metrics_registry: Option<Registry>, initial_peers: impl Iterator<Item = (PeerId, B::Hash, NumberFor<B>)>, ) -> Result<Self, ClientError>
Create a new instance.
sourcepub fn status(&self) -> SyncStatus<B>
pub fn status(&self) -> SyncStatus<B>
Returns the current sync status.
sourcepub fn num_sync_requests(&self) -> usize
pub fn num_sync_requests(&self) -> usize
Get an estimate of the number of parallel sync requests.
sourcepub fn num_downloaded_blocks(&self) -> usize
pub fn num_downloaded_blocks(&self) -> usize
Get the total number of downloaded blocks.
sourcepub fn add_peer(
&mut self,
peer_id: PeerId,
best_hash: B::Hash,
best_number: NumberFor<B>,
)
pub 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.
sourcepub fn update_chain_info(
&mut self,
best_hash: &B::Hash,
best_number: NumberFor<B>,
)
pub fn update_chain_info( &mut self, best_hash: &B::Hash, best_number: NumberFor<B>, )
Inform sync about a new best imported block.
sourcepub fn request_justification(&mut self, hash: &B::Hash, number: NumberFor<B>)
pub fn request_justification(&mut self, hash: &B::Hash, number: NumberFor<B>)
Request extra justification.
sourcepub fn clear_justification_requests(&mut self)
pub fn clear_justification_requests(&mut self)
Clear extra justification requests.
sourcepub fn set_sync_fork_request(
&mut self,
peers: Vec<PeerId>,
hash: &B::Hash,
number: NumberFor<B>,
)
pub 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.
sourcepub fn on_justification_import(
&mut self,
hash: B::Hash,
number: NumberFor<B>,
success: bool,
)
pub fn on_justification_import( &mut self, hash: B::Hash, number: NumberFor<B>, success: bool, )
Report a justification import (successful or not).
sourcepub fn on_block_finalized(&mut self, hash: &B::Hash, number: NumberFor<B>)
pub fn on_block_finalized(&mut self, hash: &B::Hash, number: NumberFor<B>)
Notify sync that a block has been finalized.
sourcepub fn on_validated_block_announce(
&mut self,
is_best: bool,
peer_id: PeerId,
announce: &BlockAnnounce<B::Header>,
) -> Option<(B::Hash, NumberFor<B>)>
pub 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.
sourcepub fn remove_peer(&mut self, peer_id: &PeerId)
pub fn remove_peer(&mut self, peer_id: &PeerId)
Notify that a sync peer has disconnected.
sourcepub fn report_metrics(&self)
pub fn report_metrics(&self)
Report prometheus metrics.
sourcepub fn on_block_response(
&mut self,
peer_id: PeerId,
request: BlockRequest<B>,
blocks: Vec<BlockData<B>>,
)
pub fn on_block_response( &mut self, peer_id: PeerId, request: BlockRequest<B>, blocks: Vec<BlockData<B>>, )
Submit blocks received in a response.
sourcepub fn on_state_response(
&mut self,
peer_id: PeerId,
response: OpaqueStateResponse,
)
pub fn on_state_response( &mut self, peer_id: PeerId, response: OpaqueStateResponse, )
Submit a state received in a response.
sourcepub fn on_blocks_processed(
&mut self,
imported: usize,
count: usize,
results: Vec<(Result<BlockImportStatus<NumberFor<B>>, BlockImportError>, B::Hash)>,
)
pub fn on_blocks_processed( &mut self, imported: usize, count: usize, results: Vec<(Result<BlockImportStatus<NumberFor<B>>, BlockImportError>, B::Hash)>, )
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.
sourcepub fn actions(&mut self) -> impl Iterator<Item = ChainSyncAction<B>>
pub fn actions(&mut self) -> impl Iterator<Item = ChainSyncAction<B>>
Get pending actions to perform.
Auto Trait Implementations§
impl<B, Client> Freeze for ChainSync<B, Client>
impl<B, Client> !RefUnwindSafe for ChainSync<B, Client>
impl<B, Client> Send for ChainSync<B, Client>
impl<B, Client> !Sync for ChainSync<B, Client>
impl<B, Client> Unpin for ChainSync<B, Client>
impl<B, Client> !UnwindSafe for ChainSync<B, Client>
Blanket Implementations§
source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CheckedConversion for T
impl<T> CheckedConversion for T
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§impl<T, Outer> IsWrappedBy<Outer> for T
impl<T, Outer> IsWrappedBy<Outer> for T
source§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<T> SaturatedConversion for T
impl<T> SaturatedConversion for T
source§fn saturated_from<T>(t: T) -> Selfwhere
Self: UniqueSaturatedFrom<T>,
fn saturated_from<T>(t: T) -> Selfwhere
Self: UniqueSaturatedFrom<T>,
source§fn saturated_into<T>(self) -> Twhere
Self: UniqueSaturatedInto<T>,
fn saturated_into<T>(self) -> Twhere
Self: UniqueSaturatedInto<T>,
T
. Read moresource§impl<S, T> UncheckedInto<T> for Swhere
T: UncheckedFrom<S>,
impl<S, T> UncheckedInto<T> for Swhere
T: UncheckedFrom<S>,
source§fn unchecked_into(self) -> T
fn unchecked_into(self) -> T
unchecked_from
.source§impl<T, S> UniqueSaturatedInto<T> for S
impl<T, S> UniqueSaturatedInto<T> for S
source§fn unique_saturated_into(self) -> T
fn unique_saturated_into(self) -> T
T
.