Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move requests-responses and polling from ChainSync to SyncingEngine #1650

Merged
merged 22 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
b8e7133
Simplify pending responses polling in `ChainSync`
dmitry-markin Sep 15, 2023
25bdbce
Prepare `ChainSync` for extraction of requests-responses
dmitry-markin Sep 19, 2023
5a090ec
Move requests-responses from `ChainSync` to `SyncingEngine`
dmitry-markin Sep 20, 2023
5875b22
Remove obsolete code from `ChainSync`
dmitry-markin Sep 20, 2023
06af3c7
Fix sync restart test in `ChainSync`
dmitry-markin Sep 20, 2023
4d2c1b8
Move block announce protocol initialization to `SyncingEngine`
dmitry-markin Sep 21, 2023
68812ff
minor: rename `who` -> `peer_id`
dmitry-markin Sep 21, 2023
c62b37e
Introduce `BlockRequestEvent`
dmitry-markin Sep 21, 2023
a3ff69b
Generate an error when discarding a pending response
dmitry-markin Sep 21, 2023
e323033
Introduce `PendingResponses` stream
dmitry-markin Sep 22, 2023
1308f90
minor: docs
dmitry-markin Sep 22, 2023
3432169
minor: typo
dmitry-markin Sep 22, 2023
5e02182
Simplify `PendingResponses` by using `StreamMap`
dmitry-markin Sep 25, 2023
7f4889a
Make `PendingResponses` `Send`
dmitry-markin Sep 25, 2023
b7cd126
Apply suggestions from code review
dmitry-markin Sep 26, 2023
8b950f3
Apply review suggestions
dmitry-markin Sep 26, 2023
73c7d14
Merge remote-tracking branch 'origin/master' into dm-extract-request-…
dmitry-markin Sep 26, 2023
7e7134d
Apply suggestions from code review
dmitry-markin Sep 26, 2023
129beb3
minor: rustfmt
dmitry-markin Sep 26, 2023
f6dc58d
Merge remote-tracking branch 'origin/master' into dm-extract-request-…
dmitry-markin Sep 26, 2023
c7fd5ed
Remove resolved pending responses from `StreamMap`
dmitry-markin Sep 27, 2023
6abebe4
Merge remote-tracking branch 'origin/master' into dm-extract-request-…
dmitry-markin Sep 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 18 additions & 10 deletions substrate/client/network/common/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -204,6 +204,23 @@ pub enum PeerRequest<B: BlockT> {
WarpProof,
}

#[derive(Debug)]
pub enum PeerRequestType {
dmitry-markin marked this conversation as resolved.
Show resolved Hide resolved
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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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>);
}
1 change: 1 addition & 0 deletions substrate/client/network/sync/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ prost = "0.11"
schnellru = "0.2.1"
smallvec = "1.11.0"
thiserror = "1.0"
tokio-stream = "0.1.14"
fork-tree = { path = "../../../utils/fork-tree" }
prometheus-endpoint = { package = "substrate-prometheus-endpoint", path = "../../../utils/prometheus" }
sc-client-api = { path = "../../api" }
Expand Down
Loading