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

Commit

Permalink
Trivial networking changes for Substrate PR #11940 (#1486)
Browse files Browse the repository at this point in the history
* Trivial networking changes for Substrate PR paritytech/substrate#11940

* Apply formatting rules

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

Co-authored-by: parity-processbot <>
  • Loading branch information
nazar-pc authored and pepoviola committed Aug 10, 2022
1 parent 2c85907 commit c8a6fe0
Show file tree
Hide file tree
Showing 9 changed files with 276 additions and 274 deletions.
511 changes: 260 additions & 251 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion client/relay-chain-inprocess-interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 9 additions & 19 deletions client/relay-chain-inprocess-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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>,
}

Expand All @@ -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 }
Expand Down Expand Up @@ -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>> {
Expand Down Expand Up @@ -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>,
}

Expand Down Expand Up @@ -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(),
Expand All @@ -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;
Expand All @@ -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")
}
}
Expand All @@ -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),
)
}

Expand Down
1 change: 1 addition & 0 deletions parachain-template/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
1 change: 1 addition & 0 deletions parachain-template/node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions polkadot-parachain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
1 change: 1 addition & 0 deletions polkadot-parachain/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
2 changes: 1 addition & 1 deletion test/service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand All @@ -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" }
Expand Down
4 changes: 2 additions & 2 deletions test/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<_>)
}
Expand Down

0 comments on commit c8a6fe0

Please sign in to comment.