Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Network sync refactoring (part 3) #11347

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 20 additions & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ members = [
"client/informant",
"client/keystore",
"client/network",
"client/network/common",
"client/network-gossip",
"client/network/common",
"client/network/light",
"client/network/sync",
"client/network/test",
"client/offchain",
Expand Down
1 change: 1 addition & 0 deletions client/network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ sc-block-builder = { version = "0.10.0-dev", path = "../block-builder" }
sc-client-api = { version = "4.0.0-dev", path = "../api" }
sc-consensus = { version = "0.10.0-dev", path = "../consensus/common" }
sc-network-common = { version = "0.10.0-dev", path = "./common" }
sc-network-light = { version = "0.10.0-dev", path = "./light" }
sc-network-sync = { version = "0.10.0-dev", path = "./sync" }
sc-peerset = { version = "4.0.0-dev", path = "../peerset" }
sc-utils = { version = "4.0.0-dev", path = "../utils" }
Expand Down
2 changes: 1 addition & 1 deletion client/network/build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const PROTOS: &[&str] = &["src/schema/light.v1.proto", "src/schema/bitswap.v1.2.0.proto"];
const PROTOS: &[&str] = &["src/schema/bitswap.v1.2.0.proto"];

fn main() {
prost_build::compile_protos(PROTOS, &["src/schema"]).unwrap();
Expand Down
33 changes: 33 additions & 0 deletions client/network/light/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[package]
description = "Substrate light network protocol"
name = "sc-network-light"
version = "0.10.0-dev"
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2021"
homepage = "https://substrate.io"
repository = "https://github.com/paritytech/substrate/"
documentation = "https://docs.rs/sc-network-light"
readme = "README.md"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[build-dependencies]
prost-build = "0.9"

[dependencies]
codec = { package = "parity-scale-codec", version = "3.0.0", features = [
"derive",
] }
futures = "0.3.21"
libp2p = "0.44.0"
log = "0.4.16"
prost = "0.9"
sp-blockchain = { version = "4.0.0-dev", path = "../../../primitives/blockchain" }
sc-client-api = { version = "4.0.0-dev", path = "../../api" }
sc-network-common = { version = "0.10.0-dev", path = "../common" }
sc-peerset = { version = "4.0.0-dev", path = "../../peerset" }
sp-core = { version = "6.0.0", path = "../../../primitives/core" }
sp-runtime = { version = "6.0.0", path = "../../../primitives/runtime" }
thiserror = "1.0"
5 changes: 5 additions & 0 deletions client/network/light/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const PROTOS: &[&str] = &["src/schema/light.v1.proto"];

fn main() {
prost_build::compile_protos(PROTOS, &["src/schema"]).unwrap();
}
22 changes: 22 additions & 0 deletions client/network/light/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// This file is part of Substrate.

// Copyright (C) 2017-2022 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

//! Light client data structures of the networking layer.

pub mod light_client_requests;
mod schema;
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
//! `crate::request_responses::RequestResponsesBehaviour` with
//! [`LightClientRequestHandler`](handler::LightClientRequestHandler).

use crate::{schema, PeerId};
use crate::schema;
use codec::{self, Decode, Encode};
use futures::{channel::mpsc, prelude::*};
use libp2p::PeerId;
use log::{debug, trace};
use prost::Message;
use sc_client_api::{ProofProvider, StorageProof};
Expand Down Expand Up @@ -55,7 +56,7 @@ where
B: Block,
Client: ProofProvider<B> + Send + Sync + 'static,
{
/// Create a new [`sc_network_sync::block_request_handler::BlockRequestHandler`].
/// Create a new [`LightClientRequestHandler`].
pub fn new(protocol_id: &ProtocolId, client: Arc<Client>) -> (Self, ProtocolConfig) {
// For now due to lack of data on light client request handling in production systems, this
// value is chosen to match the block request limit.
Expand Down
25 changes: 25 additions & 0 deletions client/network/light/src/schema.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// This file is part of Substrate.

// Copyright (C) 2017-2022 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

//! Include sources generated from protobuf definitions.

pub(crate) mod v1 {
pub(crate) mod light {
include!(concat!(env!("OUT_DIR"), "/api.v1.light.rs"));
}
}
8 changes: 4 additions & 4 deletions client/network/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ where
/// Request response configuration for the light client request protocol.
///
/// Can be constructed either via
/// [`crate::light_client_requests::generate_protocol_config`] allowing outgoing but not
/// incoming requests, or constructed via
/// [`crate::light_client_requests::handler::LightClientRequestHandler::new`] allowing
/// both outgoing and incoming requests.
/// [`sc_network_light::light_client_requests::generate_protocol_config`] allowing outgoing but
/// not incoming requests, or constructed via
/// [`sc_network_light::light_client_requests::handler::LightClientRequestHandler::new`]
/// allowing both outgoing and incoming requests.
pub light_client_request_protocol_config: RequestResponseConfig,

/// Request response configuration for the state request protocol.
Expand Down
2 changes: 1 addition & 1 deletion client/network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ mod utils;
pub mod bitswap;
pub mod config;
pub mod error;
pub mod light_client_requests;
pub mod network_state;
pub mod transactions;

Expand All @@ -267,6 +266,7 @@ pub use protocol::{
event::{DhtEvent, Event, ObservedRole},
PeerInfo,
};
pub use sc_network_light::light_client_requests;
pub use sc_network_sync::{
block_request_handler,
state::StateDownloadProgress,
Expand Down
6 changes: 0 additions & 6 deletions client/network/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@

//! Include sources generated from protobuf definitions.

pub mod v1 {
pub mod light {
include!(concat!(env!("OUT_DIR"), "/api.v1.light.rs"));
}
}

pub mod bitswap {
include!(concat!(env!("OUT_DIR"), "/bitswap.message.rs"));
}
4 changes: 2 additions & 2 deletions client/network/src/service/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use crate::{
config, light_client_requests::handler::LightClientRequestHandler,
state_request_handler::StateRequestHandler, Event, NetworkService, NetworkWorker,
config, state_request_handler::StateRequestHandler, Event, NetworkService, NetworkWorker,
};

use futures::prelude::*;
use libp2p::PeerId;
use sc_network_common::config::ProtocolId;
use sc_network_light::light_client_requests::handler::LightClientRequestHandler;
use sc_network_sync::block_request_handler::BlockRequestHandler;
use sp_runtime::traits::{Block as BlockT, Header as _};
use std::{borrow::Cow, sync::Arc, time::Duration};
Expand Down
4 changes: 1 addition & 3 deletions client/network/sync/src/block_request_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ pub fn generate_protocol_config(protocol_id: &ProtocolId) -> ProtocolConfig {
}

/// Generate the block protocol name from chain specific protocol identifier.
// Visibility `pub(crate)` to allow `crate::light_client_requests::sender` to generate block request
// protocol name and send block requests.
pub(crate) fn generate_protocol_name(protocol_id: &ProtocolId) -> String {
fn generate_protocol_name(protocol_id: &ProtocolId) -> String {
format!("/{}/sync/2", protocol_id.as_ref())
}

Expand Down