mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 08:07:58 +00:00
Move requests-responses and polling from ChainSync to SyncingEngine (#1650)
Move request-response handling from `ChainSync` to `SyncingEngine` as part of [Sync 2.0](https://github.com/paritytech/polkadot-sdk/issues/534) refactoring aimed at making `ChainSync` a pure state machine. Resolves https://github.com/paritytech/polkadot-sdk/issues/502. --------- Co-authored-by: Aaro Altonen <48052676+altonen@users.noreply.github.com> Co-authored-by: Bastian Köcher <git@kchr.de>
This commit is contained in:
@@ -36,7 +36,7 @@ use sp_runtime::{
|
||||
};
|
||||
use warp::WarpSyncProgress;
|
||||
|
||||
use std::{any::Any, fmt, fmt::Formatter, pin::Pin, sync::Arc, task::Poll};
|
||||
use std::{any::Any, fmt, fmt::Formatter, pin::Pin, sync::Arc};
|
||||
|
||||
/// The sync status of a peer we are trying to sync with
|
||||
#[derive(Debug)]
|
||||
@@ -204,6 +204,23 @@ pub enum PeerRequest<B: BlockT> {
|
||||
WarpProof,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum PeerRequestType {
|
||||
Block,
|
||||
State,
|
||||
WarpProof,
|
||||
}
|
||||
|
||||
impl<B: BlockT> PeerRequest<B> {
|
||||
pub fn get_type(&self) -> PeerRequestType {
|
||||
match self {
|
||||
PeerRequest::Block(_) => PeerRequestType::Block,
|
||||
PeerRequest::State => PeerRequestType::State,
|
||||
PeerRequest::WarpProof => PeerRequestType::WarpProof,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Wrapper for implementation-specific state request.
|
||||
///
|
||||
/// NOTE: Implementation must be able to encode and decode it for network purposes.
|
||||
@@ -289,9 +306,6 @@ pub trait ChainSync<Block: BlockT>: Send {
|
||||
/// Returns the current number of peers stored within this state machine.
|
||||
fn num_peers(&self) -> usize;
|
||||
|
||||
/// Returns the number of peers we're connected to and that are being queried.
|
||||
fn num_active_peers(&self) -> usize;
|
||||
|
||||
/// Handle a new connected peer.
|
||||
///
|
||||
/// Call this method whenever we connect to a new peer.
|
||||
@@ -369,10 +383,4 @@ pub trait ChainSync<Block: BlockT>: Send {
|
||||
|
||||
/// Return some key metrics.
|
||||
fn metrics(&self) -> Metrics;
|
||||
|
||||
/// Advance the state of `ChainSync`
|
||||
fn poll(&mut self, cx: &mut std::task::Context) -> Poll<()>;
|
||||
|
||||
/// Send block request to peer
|
||||
fn send_block_request(&mut self, who: PeerId, request: BlockRequest<Block>);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user