From bccd15158d55dd1df0cd5028624cb713b6492da9 Mon Sep 17 00:00:00 2001 From: Nazar Mokrynskyi Date: Sat, 30 Jul 2022 01:51:07 +0300 Subject: [PATCH] Trivial networking changes for Substrate PR https://github.com/paritytech/substrate/pull/11940 --- Cargo.lock | 17 ++++++++--- .../Cargo.toml | 1 - .../src/lib.rs | 30 +++++++------------ parachain-template/node/Cargo.toml | 1 + parachain-template/node/src/service.rs | 1 + polkadot-parachain/Cargo.toml | 1 + polkadot-parachain/src/service.rs | 1 + test/service/Cargo.toml | 2 +- test/service/src/lib.rs | 6 ++-- 9 files changed, 31 insertions(+), 29 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 067ce40f972..46446b56b0f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1892,7 +1892,6 @@ dependencies = [ "cumulus-test-service", "futures", "futures-timer", - "parking_lot 0.12.1", "polkadot-cli", "polkadot-client", "polkadot-primitives", @@ -2071,7 +2070,6 @@ dependencies = [ "pallet-transaction-payment", "parachains-common", "parity-scale-codec", - "parking_lot 0.12.1", "polkadot-cli", "polkadot-primitives", "polkadot-service", @@ -2085,6 +2083,7 @@ dependencies = [ "sc-consensus", "sc-executor", "sc-network", + "sc-network-common", "sc-rpc", "sc-service", "sc-telemetry", @@ -6372,6 +6371,7 @@ dependencies = [ "sc-executor", "sc-keystore", "sc-network", + "sc-network-common", "sc-rpc", "sc-rpc-api", "sc-service", @@ -7108,6 +7108,7 @@ dependencies = [ "polkadot-overseer", "polkadot-primitives", "sc-network", + "sc-network-common", "sp-consensus", "thiserror", "tracing-gum", @@ -7629,6 +7630,7 @@ dependencies = [ "sc-consensus", "sc-executor", "sc-network", + "sc-network-common", "sc-rpc", "sc-service", "sc-sysinfo", @@ -8009,6 +8011,7 @@ dependencies = [ "sc-finality-grandpa", "sc-keystore", "sc-network", + "sc-network-common", "sc-offchain", "sc-service", "sc-sync-state-rpc", @@ -8191,6 +8194,7 @@ dependencies = [ "sc-executor", "sc-finality-grandpa", "sc-network", + "sc-network-common", "sc-service", "sc-tracing", "sc-transaction-pool", @@ -9137,7 +9141,6 @@ name = "sc-authority-discovery" version = "0.10.0-dev" source = "git+https://github.com/paritytech/substrate?branch=master#3e0554a94193c1221c6bf12c7efabc25e2d63404" dependencies = [ - "async-trait", "futures", "futures-timer", "ip_network", @@ -9149,6 +9152,7 @@ dependencies = [ "rand 0.7.3", "sc-client-api", "sc-network", + "sc-network-common", "sp-api", "sp-authority-discovery", "sp-blockchain", @@ -9625,7 +9629,7 @@ dependencies = [ "log", "parity-util-mem", "sc-client-api", - "sc-network", + "sc-network-common", "sc-transaction-pool-api", "sp-blockchain", "sp-runtime", @@ -9700,7 +9704,9 @@ name = "sc-network-common" version = "0.10.0-dev" source = "git+https://github.com/paritytech/substrate?branch=master#3e0554a94193c1221c6bf12c7efabc25e2d63404" dependencies = [ + "async-trait", "bitflags", + "bytes", "futures", "libp2p", "parity-scale-codec", @@ -9711,6 +9717,7 @@ dependencies = [ "sp-consensus", "sp-finality-grandpa", "sp-runtime", + "thiserror", ] [[package]] @@ -9725,6 +9732,7 @@ dependencies = [ "log", "lru 0.7.7", "sc-network", + "sc-network-common", "sp-runtime", "substrate-prometheus-endpoint", "tracing", @@ -9796,6 +9804,7 @@ dependencies = [ "rand 0.7.3", "sc-client-api", "sc-network", + "sc-network-common", "sc-utils", "sp-api", "sp-core", diff --git a/client/relay-chain-inprocess-interface/Cargo.toml b/client/relay-chain-inprocess-interface/Cargo.toml index e0479c3fc08..44c14034266 100644 --- a/client/relay-chain-inprocess-interface/Cargo.toml +++ b/client/relay-chain-inprocess-interface/Cargo.toml @@ -8,7 +8,6 @@ edition = "2021" async-trait = "0.1.56" futures = "0.3.21" futures-timer = "3.0.2" -parking_lot = "0.12.1" tracing = "0.1.34" # Substrate diff --git a/client/relay-chain-inprocess-interface/src/lib.rs b/client/relay-chain-inprocess-interface/src/lib.rs index 15635539172..e168651a2aa 100644 --- a/client/relay-chain-inprocess-interface/src/lib.rs +++ b/client/relay-chain-inprocess-interface/src/lib.rs @@ -27,7 +27,6 @@ use cumulus_primitives_core::{ }; use cumulus_relay_chain_interface::{RelayChainError, RelayChainInterface, RelayChainResult}; use futures::{FutureExt, Stream, StreamExt}; -use parking_lot::Mutex; use polkadot_client::{ClientHandle, ExecuteWithClient, FullBackend}; use polkadot_service::{ AuxStore, BabeApi, CollatorPair, Configuration, Handle, NewFull, TaskManager, @@ -50,7 +49,7 @@ const TIMEOUT_IN_SECONDS: u64 = 6; pub struct RelayChainInProcessInterface { full_client: Arc, backend: Arc, - sync_oracle: Arc>>, + sync_oracle: Arc, overseer_handle: Option, } @@ -59,7 +58,7 @@ impl RelayChainInProcessInterface { pub fn new( full_client: Arc, backend: Arc, - sync_oracle: Arc>>, + sync_oracle: Arc, overseer_handle: Option, ) -> Self { Self { full_client, backend, sync_oracle, overseer_handle } @@ -169,8 +168,7 @@ where } async fn is_major_syncing(&self) -> RelayChainResult { - let mut network = self.sync_oracle.lock(); - Ok(network.is_major_syncing()) + Ok(self.sync_oracle.is_major_syncing()) } fn overseer_handle(&self) -> RelayChainResult> { @@ -272,7 +270,7 @@ where let block_id = BlockId::Hash(hash); if backend.blockchain().status(block_id)? == BlockStatus::InChain { - return Ok(BlockCheckStatus::InChain) + return Ok(BlockCheckStatus::InChain); } let listener = client.import_notification_stream(); @@ -289,7 +287,7 @@ where struct RelayChainInProcessInterfaceBuilder { polkadot_client: polkadot_client::Client, backend: Arc, - sync_oracle: Arc>>, + sync_oracle: Arc, overseer_handle: Option, } @@ -375,8 +373,7 @@ pub fn build_inprocess_relay_chain( hwbench, )?; - let sync_oracle: Box = Box::new(full_node.network.clone()); - let sync_oracle = Arc::new(Mutex::new(sync_oracle)); + let sync_oracle: Arc = Arc::new(full_node.network.clone()); let relay_chain_interface_builder = RelayChainInProcessInterfaceBuilder { polkadot_client: full_node.client.clone(), backend: full_node.backend.clone(), @@ -391,8 +388,6 @@ pub fn build_inprocess_relay_chain( #[cfg(test)] mod tests { - use parking_lot::Mutex; - use super::*; use polkadot_primitives::v2::Block as PBlock; @@ -410,11 +405,11 @@ mod tests { struct DummyNetwork {} impl SyncOracle for DummyNetwork { - fn is_major_syncing(&mut self) -> bool { + fn is_major_syncing(&self) -> bool { unimplemented!("Not needed for test") } - fn is_offline(&mut self) -> bool { + fn is_offline(&self) -> bool { unimplemented!("Not needed for test") } } @@ -428,17 +423,12 @@ mod tests { let block_builder = client.init_polkadot_block_builder(); let block = block_builder.build().expect("Finalizes the block").block; - let dummy_network: Box = Box::new(DummyNetwork {}); + let dummy_network: Arc = Arc::new(DummyNetwork {}); ( client.clone(), block, - RelayChainInProcessInterface::new( - client, - backend.clone(), - Arc::new(Mutex::new(dummy_network)), - None, - ), + RelayChainInProcessInterface::new(client, backend.clone(), dummy_network, None), ) } diff --git a/parachain-template/node/Cargo.toml b/parachain-template/node/Cargo.toml index 5ef58cb6d4e..5aff8e02c54 100644 --- a/parachain-template/node/Cargo.toml +++ b/parachain-template/node/Cargo.toml @@ -33,6 +33,7 @@ sc-consensus = { git = "https://github.com/paritytech/substrate", branch = "mast sc-executor = { git = "https://github.com/paritytech/substrate", branch = "master", features = ["wasmtime"] } sc-keystore = { git = "https://github.com/paritytech/substrate", branch = "master" } sc-network = { git = "https://github.com/paritytech/substrate", branch = "master" } +sc-network-common = { git = "https://github.com/paritytech/substrate", branch = "master" } sc-rpc = { git = "https://github.com/paritytech/substrate", branch = "master" } sc-rpc-api = { git = "https://github.com/paritytech/substrate", branch = "master" } sc-service = { git = "https://github.com/paritytech/substrate", branch = "master", features = ["wasmtime"] } diff --git a/parachain-template/node/src/service.rs b/parachain-template/node/src/service.rs index 9b50508622f..e9f187a8543 100644 --- a/parachain-template/node/src/service.rs +++ b/parachain-template/node/src/service.rs @@ -28,6 +28,7 @@ use cumulus_relay_chain_rpc_interface::RelayChainRPCInterface; use sc_client_api::ExecutorProvider; use sc_executor::NativeElseWasmExecutor; use sc_network::NetworkService; +use sc_network_common::service::NetworkBlock; use sc_service::{Configuration, PartialComponents, TFullBackend, TFullClient, TaskManager}; use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker, TelemetryWorkerHandle}; use sp_api::ConstructRuntimeApi; diff --git a/polkadot-parachain/Cargo.toml b/polkadot-parachain/Cargo.toml index c775b9fc78c..0c160303240 100644 --- a/polkadot-parachain/Cargo.toml +++ b/polkadot-parachain/Cargo.toml @@ -45,6 +45,7 @@ sc-telemetry = { git = "https://github.com/paritytech/substrate", branch = "mast sc-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "master" } sc-network = { git = "https://github.com/paritytech/substrate", branch = "master" } +sc-network-common = { git = "https://github.com/paritytech/substrate", branch = "master" } sc-basic-authorship = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-timestamp = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "master" } diff --git a/polkadot-parachain/src/service.rs b/polkadot-parachain/src/service.rs index cd8eaf242c5..3a01d8cb4e1 100644 --- a/polkadot-parachain/src/service.rs +++ b/polkadot-parachain/src/service.rs @@ -47,6 +47,7 @@ use sc_consensus::{ }; use sc_executor::WasmExecutor; use sc_network::NetworkService; +use sc_network_common::service::NetworkBlock; use sc_service::{Configuration, PartialComponents, TFullBackend, TFullClient, TaskManager}; use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker, TelemetryWorkerHandle}; use sp_api::{ApiExt, ConstructRuntimeApi}; diff --git a/test/service/Cargo.toml b/test/service/Cargo.toml index 27720cbcc94..3c6ade15d41 100644 --- a/test/service/Cargo.toml +++ b/test/service/Cargo.toml @@ -14,7 +14,6 @@ clap = { version = "3.2.15", features = ["derive", "deprecated"] } codec = { package = "parity-scale-codec", version = "3.0.0" } criterion = { version = "0.3.6", features = [ "async_tokio" ] } jsonrpsee = { version = "0.14.0", features = ["server"] } -parking_lot = "0.12.1" rand = "0.8.5" serde = { version = "1.0.140", features = ["derive"] } tokio = { version = "1.19.2", features = ["macros"] } @@ -31,6 +30,7 @@ sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "mas sc-consensus = { git = "https://github.com/paritytech/substrate", branch = "master" } sc-executor = { git = "https://github.com/paritytech/substrate", branch = "master", features = ["wasmtime"] } sc-network = { git = "https://github.com/paritytech/substrate", branch = "master" } +sc-network-common = { git = "https://github.com/paritytech/substrate", branch = "master" } sc-rpc = { git = "https://github.com/paritytech/substrate", branch = "master" } sc-service = { git = "https://github.com/paritytech/substrate", branch = "master", features = [ "wasmtime" ] } sc-tracing = { git = "https://github.com/paritytech/substrate", branch = "master" } diff --git a/test/service/src/lib.rs b/test/service/src/lib.rs index d3a52b7db7a..479b325ee43 100644 --- a/test/service/src/lib.rs +++ b/test/service/src/lib.rs @@ -39,13 +39,13 @@ use cumulus_relay_chain_inprocess_interface::RelayChainInProcessInterface; use cumulus_relay_chain_interface::{RelayChainError, RelayChainInterface, RelayChainResult}; use cumulus_relay_chain_rpc_interface::RelayChainRPCInterface; use cumulus_test_runtime::{Hash, Header, NodeBlock as Block, RuntimeApi}; -use parking_lot::Mutex; use frame_system_rpc_runtime_api::AccountNonceApi; use polkadot_primitives::v2::{CollatorPair, Hash as PHash, PersistedValidationData}; use polkadot_service::ProvideRuntimeApi; use sc_client_api::execution_extensions::ExecutionStrategies; use sc_network::{config::TransportConfig, multiaddr, NetworkService}; +use sc_network_common::service::{NetworkBlock, NetworkStateInfo}; use sc_service::{ config::{ DatabaseSource, KeepBlocks, KeystoreConfig, MultiaddrWithPeerId, NetworkConfiguration, @@ -182,7 +182,7 @@ async fn build_relay_chain_interface( task_manager: &mut TaskManager, ) -> RelayChainResult> { if let Some(relay_chain_url) = collator_options.relay_chain_rpc_url { - return Ok(Arc::new(RelayChainRPCInterface::new(relay_chain_url).await?) as Arc<_>) + return Ok(Arc::new(RelayChainRPCInterface::new(relay_chain_url).await?) as Arc<_>); } let relay_chain_full_node = polkadot_test_service::new_full( @@ -199,7 +199,7 @@ async fn build_relay_chain_interface( Ok(Arc::new(RelayChainInProcessInterface::new( relay_chain_full_node.client.clone(), relay_chain_full_node.backend.clone(), - Arc::new(Mutex::new(Box::new(relay_chain_full_node.network.clone()))), + Arc::new(relay_chain_full_node.network.clone()), relay_chain_full_node.overseer_handle, )) as Arc<_>) }