diff --git a/substrate/Cargo.lock b/substrate/Cargo.lock index 68272e1df9c8cbe4b291ff362d83c4937c729b17..1683cc2b06b696b59a848578db6d9cdca9494eab 100644 --- a/substrate/Cargo.lock +++ b/substrate/Cargo.lock @@ -8509,6 +8509,7 @@ dependencies = [ "sc-client-api", "sc-consensus", "sc-network-common", + "sc-network-light", "sc-network-sync", "sc-peerset", "sc-utils", @@ -8564,6 +8565,25 @@ dependencies = [ "tracing", ] +[[package]] +name = "sc-network-light" +version = "0.10.0-dev" +dependencies = [ + "futures", + "libp2p", + "log", + "parity-scale-codec", + "prost", + "prost-build", + "sc-client-api", + "sc-network-common", + "sc-peerset", + "sp-blockchain", + "sp-core", + "sp-runtime", + "thiserror", +] + [[package]] name = "sc-network-sync" version = "0.10.0-dev" diff --git a/substrate/Cargo.toml b/substrate/Cargo.toml index 39ccceeb3a0307f8a62cd382cb8cfb4c2fdb0e68..41739fe6f1ebc0081844158bda00e448bf15bec5 100644 --- a/substrate/Cargo.toml +++ b/substrate/Cargo.toml @@ -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", diff --git a/substrate/client/network/Cargo.toml b/substrate/client/network/Cargo.toml index 51e7e762f529248f74d6fdff1766113bede4d609..7e12d9862f8ef50e4ff09ee9cc6f9e5537063c76 100644 --- a/substrate/client/network/Cargo.toml +++ b/substrate/client/network/Cargo.toml @@ -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" } diff --git a/substrate/client/network/build.rs b/substrate/client/network/build.rs index f551f61dab3d4cf4c12311e84fbd70dd14b6f19d..671277230a7746b4da5e4e1d9d6b68f5ccf10b3e 100644 --- a/substrate/client/network/build.rs +++ b/substrate/client/network/build.rs @@ -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(); diff --git a/substrate/client/network/light/Cargo.toml b/substrate/client/network/light/Cargo.toml new file mode 100644 index 0000000000000000000000000000000000000000..8bbbce9274c0c50907f7568042f48f6d92f4b548 --- /dev/null +++ b/substrate/client/network/light/Cargo.toml @@ -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" diff --git a/substrate/client/network/light/build.rs b/substrate/client/network/light/build.rs new file mode 100644 index 0000000000000000000000000000000000000000..9c44bcd29318168397802bb7de04088c55309cc7 --- /dev/null +++ b/substrate/client/network/light/build.rs @@ -0,0 +1,5 @@ +const PROTOS: &[&str] = &["src/schema/light.v1.proto"]; + +fn main() { + prost_build::compile_protos(PROTOS, &["src/schema"]).unwrap(); +} diff --git a/substrate/client/network/light/src/lib.rs b/substrate/client/network/light/src/lib.rs new file mode 100644 index 0000000000000000000000000000000000000000..2b7cf226f90dd095274930271463b432bde77edc --- /dev/null +++ b/substrate/client/network/light/src/lib.rs @@ -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; diff --git a/substrate/client/network/src/light_client_requests.rs b/substrate/client/network/light/src/light_client_requests.rs similarity index 100% rename from substrate/client/network/src/light_client_requests.rs rename to substrate/client/network/light/src/light_client_requests.rs diff --git a/substrate/client/network/src/light_client_requests/handler.rs b/substrate/client/network/light/src/light_client_requests/handler.rs similarity index 98% rename from substrate/client/network/src/light_client_requests/handler.rs rename to substrate/client/network/light/src/light_client_requests/handler.rs index bf65cba5f82e58b9af42ce53fc90f7258eec2691..3c87ccfd6ed9f5fdc6acf9503970f9f22c042040 100644 --- a/substrate/client/network/src/light_client_requests/handler.rs +++ b/substrate/client/network/light/src/light_client_requests/handler.rs @@ -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}; @@ -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. diff --git a/substrate/client/network/light/src/schema.rs b/substrate/client/network/light/src/schema.rs new file mode 100644 index 0000000000000000000000000000000000000000..09cc82cc2811ab851a5299bc07e5e1af1cbca25c --- /dev/null +++ b/substrate/client/network/light/src/schema.rs @@ -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")); + } +} diff --git a/substrate/client/network/src/schema/light.v1.proto b/substrate/client/network/light/src/schema/light.v1.proto similarity index 100% rename from substrate/client/network/src/schema/light.v1.proto rename to substrate/client/network/light/src/schema/light.v1.proto diff --git a/substrate/client/network/src/config.rs b/substrate/client/network/src/config.rs index cfb06331b55a18464b99a217c091f6894d3e0991..e44977e5be6b3968f47c9305a08a86eebe7fad7f 100644 --- a/substrate/client/network/src/config.rs +++ b/substrate/client/network/src/config.rs @@ -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. diff --git a/substrate/client/network/src/lib.rs b/substrate/client/network/src/lib.rs index 3957aab22cca945729d801683b65489e82385754..fff30550eb8c9ead9d8f91dc133eb98b46d7daa1 100644 --- a/substrate/client/network/src/lib.rs +++ b/substrate/client/network/src/lib.rs @@ -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; @@ -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, diff --git a/substrate/client/network/src/schema.rs b/substrate/client/network/src/schema.rs index 80301a59c29ef5052fc9d7daa2973c38a6309baa..4893bc28a73555ff754edaa30cda4559d42a05a0 100644 --- a/substrate/client/network/src/schema.rs +++ b/substrate/client/network/src/schema.rs @@ -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")); } diff --git a/substrate/client/network/src/service/tests.rs b/substrate/client/network/src/service/tests.rs index 36205f32d33c6cabd3f4ce8bcf76d6f0afce7585..808546d67fc7c8a89abc813170380ea14ba8af5a 100644 --- a/substrate/client/network/src/service/tests.rs +++ b/substrate/client/network/src/service/tests.rs @@ -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}; diff --git a/substrate/client/network/sync/src/block_request_handler.rs b/substrate/client/network/sync/src/block_request_handler.rs index b9ffd24cee4c778536ea9c3d61f1a746e94505a9..78d6a1a7d16808d614e985467e14eaf51ad6f19b 100644 --- a/substrate/client/network/sync/src/block_request_handler.rs +++ b/substrate/client/network/sync/src/block_request_handler.rs @@ -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()) }