Trivial networking changes for Substrate PR #11940 (#1486)

* Trivial networking changes for Substrate PR https://github.com/paritytech/substrate/pull/11940

* Apply formatting rules

* update lockfile for {"polkadot", "substrate"}

Co-authored-by: parity-processbot <>
This commit is contained in:
Nazar Mokrynskyi
2022-08-10 00:59:34 +03:00
committed by GitHub
parent 4436f2b1b6
commit 47bfa4f90f
9 changed files with 276 additions and 274 deletions
+260 -251
View File
File diff suppressed because it is too large Load Diff
@@ -8,7 +8,6 @@ edition = "2021"
async-trait = "0.1.57"
futures = "0.3.21"
futures-timer = "3.0.2"
parking_lot = "0.12.1"
tracing = "0.1.36"
# Substrate
@@ -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<Client> {
full_client: Arc<Client>,
backend: Arc<FullBackend>,
sync_oracle: Arc<Mutex<Box<dyn SyncOracle + Send + Sync>>>,
sync_oracle: Arc<dyn SyncOracle + Send + Sync>,
overseer_handle: Option<Handle>,
}
@@ -59,7 +58,7 @@ impl<Client> RelayChainInProcessInterface<Client> {
pub fn new(
full_client: Arc<Client>,
backend: Arc<FullBackend>,
sync_oracle: Arc<Mutex<Box<dyn SyncOracle + Send + Sync>>>,
sync_oracle: Arc<dyn SyncOracle + Send + Sync>,
overseer_handle: Option<Handle>,
) -> Self {
Self { full_client, backend, sync_oracle, overseer_handle }
@@ -169,8 +168,7 @@ where
}
async fn is_major_syncing(&self) -> RelayChainResult<bool> {
let mut network = self.sync_oracle.lock();
Ok(network.is_major_syncing())
Ok(self.sync_oracle.is_major_syncing())
}
fn overseer_handle(&self) -> RelayChainResult<Option<Handle>> {
@@ -289,7 +287,7 @@ where
struct RelayChainInProcessInterfaceBuilder {
polkadot_client: polkadot_client::Client,
backend: Arc<FullBackend>,
sync_oracle: Arc<Mutex<Box<dyn SyncOracle + Send + Sync>>>,
sync_oracle: Arc<dyn SyncOracle + Send + Sync>,
overseer_handle: Option<Handle>,
}
@@ -375,8 +373,7 @@ pub fn build_inprocess_relay_chain(
hwbench,
)?;
let sync_oracle: Box<dyn SyncOracle + Send + Sync> = Box::new(full_node.network.clone());
let sync_oracle = Arc::new(Mutex::new(sync_oracle));
let sync_oracle: Arc<dyn SyncOracle + Send + Sync> = 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<dyn SyncOracle + Sync + Send> = Box::new(DummyNetwork {});
let dummy_network: Arc<dyn SyncOracle + Sync + Send> = 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),
)
}
@@ -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"] }
@@ -28,6 +28,7 @@ use cumulus_relay_chain_rpc_interface::{create_client_and_start_worker, RelayCha
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;
+1
View File
@@ -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" }
@@ -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};
+1 -1
View File
@@ -14,7 +14,6 @@ clap = { version = "3.2.16", features = ["derive", "deprecated"] }
codec = { package = "parity-scale-codec", version = "3.0.0" }
criterion = { version = "0.3.6", features = [ "async_tokio" ] }
jsonrpsee = { version = "0.15.1", features = ["server"] }
parking_lot = "0.12.1"
rand = "0.8.5"
serde = { version = "1.0.141", 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" }
+2 -2
View File
@@ -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::{create_client_and_start_worker, 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::{
BlocksPruning, DatabaseSource, KeystoreConfig, MultiaddrWithPeerId, NetworkConfiguration,
@@ -200,7 +200,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<_>)
}