Skip to content
Closed
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
294 changes: 292 additions & 2 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,11 @@ linked-hash-map = { version = "0.5.4" }
linked_hash_set = { version = "0.1.4" }
linregress = { version = "0.5.1" }
lite-json = { version = "0.2.0", default-features = false }
<<<<<<< HEAD
litep2p = { version = "0.6.2" }
=======
litep2p = { version = "0.9.5", features = ["websocket"] }
>>>>>>> f6d18b73 (client/net: Use litep2p as the default network backend (#8461))
log = { version = "0.4.22", default-features = false }
macro_magic = { version = "0.5.1" }
maplit = { version = "1.0.2" }
Expand Down Expand Up @@ -867,7 +871,7 @@ num-format = { version = "0.4.3" }
num-rational = { version = "0.4.1" }
num-traits = { version = "0.2.17", default-features = false }
num_cpus = { version = "1.13.1" }
once_cell = { version = "1.19.0" }
once_cell = { version = "1.21.3" }
orchestra = { version = "0.4.0", default-features = false }
pallet-alliance = { path = "substrate/frame/alliance", default-features = false, version = "37.0.0" }
pallet-asset-conversion = { path = "substrate/frame/asset-conversion", default-features = false, version = "20.0.0" }
Expand Down Expand Up @@ -1313,7 +1317,11 @@ tikv-jemalloc-ctl = { version = "0.5.0" }
tikv-jemallocator = { version = "0.5.0" }
time = { version = "0.3" }
tiny-keccak = { version = "2.0.2" }
<<<<<<< HEAD
tokio = { version = "1.37.0", default-features = false }
=======
tokio = { version = "1.45.0", default-features = false }
>>>>>>> f6d18b73 (client/net: Use litep2p as the default network backend (#8461))
tokio-retry = { version = "0.3.0" }
tokio-stream = { version = "0.1.14" }
tokio-test = { version = "0.4.2" }
Expand Down
13 changes: 13 additions & 0 deletions cumulus/client/relay-chain-inprocess-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,20 @@ fn build_polkadot_full_node(
},
)?;

<<<<<<< HEAD
Ok((relay_chain_full_node, maybe_collator_key))
=======
let (relay_chain_full_node, paranode_req_receiver) = match config.network.network_backend {
NetworkBackendType::Libp2p => build_polkadot_with_paranode_protocol::<
sc_network::NetworkWorker<_, _>,
>(config, new_full_params)?,
NetworkBackendType::Litep2p => build_polkadot_with_paranode_protocol::<
sc_network::Litep2pNetworkBackend,
>(config, new_full_params)?,
};

Ok((relay_chain_full_node, maybe_collator_key, paranode_req_receiver))
>>>>>>> f6d18b73 (client/net: Use litep2p as the default network backend (#8461))
}

/// Builds a relay chain interface by constructing a full relay chain node
Expand Down
4 changes: 4 additions & 0 deletions cumulus/client/relay-chain-minimal-node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ async fn build_interface(
client: RelayChainRpcClient,
) -> RelayChainResult<(Arc<(dyn RelayChainInterface + 'static)>, Option<CollatorPair>)> {
let collator_pair = CollatorPair::generate().0;
<<<<<<< HEAD
=======
let blockchain_rpc_client = Arc::new(BlockChainRpcClient::new(client.clone()));
>>>>>>> f6d18b73 (client/net: Use litep2p as the default network backend (#8461))
let collator_node = match polkadot_config.network.network_backend {
sc_network::config::NetworkBackendType::Libp2p =>
new_minimal_relay_chain::<RelayBlock, sc_network::NetworkWorker<RelayBlock, RelayHash>>(
Expand Down
62 changes: 62 additions & 0 deletions cumulus/polkadot-omni-node/lib/src/nodes/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// This file is part of Cumulus.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

pub mod aura;
mod manual_seal;

use crate::common::spec::{DynNodeSpec, NodeSpec as NodeSpecT};
use cumulus_primitives_core::ParaId;
use manual_seal::ManualSealNode;
use sc_service::{Configuration, TaskManager};

/// The current node version for cumulus official binaries, which takes the basic
/// SemVer form `<major>.<minor>.<patch>`. It should correspond to the latest
/// `polkadot` version of a stable release.
pub const NODE_VERSION: &'static str = "1.18.5";

/// Trait that extends the `DynNodeSpec` trait with manual seal related logic.
///
/// We need it in order to be able to access both the `DynNodeSpec` and the manual seal logic
/// through dynamic dispatch.
pub trait DynNodeSpecExt: DynNodeSpec {
fn start_manual_seal_node(
&self,
config: Configuration,
para_id: ParaId,
block_time: u64,
) -> sc_service::error::Result<TaskManager>;
}

impl<T> DynNodeSpecExt for T
where
T: NodeSpecT + DynNodeSpec,
{
#[sc_tracing::logging::prefix_logs_with("Parachain")]
fn start_manual_seal_node(
&self,
config: Configuration,
para_id: ParaId,
block_time: u64,
) -> sc_service::error::Result<TaskManager> {
let node = ManualSealNode::<T>::new();
match config.network.network_backend {
sc_network::config::NetworkBackendType::Libp2p =>
node.start_node::<sc_network::NetworkWorker<_, _>>(config, para_id, block_time),
sc_network::config::NetworkBackendType::Litep2p =>
node.start_node::<sc_network::Litep2pNetworkBackend>(config, para_id, block_time),
}
}
}
26 changes: 16 additions & 10 deletions cumulus/test/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,10 @@ impl TestNodeBuilder {
relay_chain_config.network.node_name =
format!("{} (relay chain)", relay_chain_config.network.node_name);

<<<<<<< HEAD
let multiaddr = parachain_config.network.listen_addresses[0].clone();
=======
>>>>>>> f6d18b73 (client/net: Use litep2p as the default network backend (#8461))
let (task_manager, client, network, rpc_handlers, transaction_pool, backend) =
match relay_chain_config.network.network_backend {
sc_network::config::NetworkBackendType::Libp2p =>
Expand Down Expand Up @@ -792,6 +795,7 @@ impl TestNodeBuilder {
.expect("could not create Cumulus test service"),
};
let peer_id = network.local_peer_id();
let multiaddr = polkadot_test_service::get_listen_address(network.clone()).await;
let addr = MultiaddrWithPeerId { multiaddr, peer_id };

TestNode { task_manager, client, network, addr, rpc_handlers, transaction_pool, backend }
Expand All @@ -800,10 +804,13 @@ impl TestNodeBuilder {

/// Create a Cumulus `Configuration`.
///
/// By default an in-memory socket will be used, therefore you need to provide nodes if you want the
/// node to be connected to other nodes. If `nodes_exclusive` is `true`, the node will only connect
/// to the given `nodes` and not to any other node. The `storage_update_func` can be used to make
/// adjustments to the runtime genesis.
/// By default a TCP socket will be used, therefore you need to provide nodes if you want the
/// node to be connected to other nodes.
///
/// If `nodes_exclusive` is `true`, the node will only connect to the given `nodes` and not to any
/// other node.
///
/// The `storage_update_func` can be used to make adjustments to the runtime genesis.
pub fn node_config(
storage_update_func: impl Fn(),
tokio_handle: tokio::runtime::Handle,
Expand Down Expand Up @@ -846,11 +853,10 @@ pub fn node_config(

network_config.allow_non_globals_in_dht = true;

network_config
.listen_addresses
.push(multiaddr::Protocol::Memory(rand::random()).into());

network_config.transport = TransportConfig::MemoryOnly;
let addr: multiaddr::Multiaddr = "/ip4/127.0.0.1/tcp/0".parse().expect("valid address; qed");
network_config.listen_addresses.push(addr.clone());
network_config.transport =
TransportConfig::Normal { enable_mdns: false, allow_private_ip: true };

Ok(Configuration {
impl_name: "cumulus-test-node".to_string(),
Expand Down Expand Up @@ -1034,6 +1040,6 @@ pub fn run_relay_chain_validator_node(
workers_path.pop();

tokio_handle.block_on(async move {
polkadot_test_service::run_validator_node(config, Some(workers_path))
polkadot_test_service::run_validator_node(config, Some(workers_path)).await
})
}
7 changes: 7 additions & 0 deletions cumulus/test/service/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,17 @@ fn main() -> Result<(), sc_cli::Error> {
cumulus_test_service::Consensus::Null
})
.unwrap_or(cumulus_test_service::Consensus::Aura);
<<<<<<< HEAD

let (mut task_manager, _, _, _, _, _) = tokio_runtime
.block_on(async move {
match polkadot_config.network.network_backend {
=======
let use_slot_based_collator = cli.authoring == AuthoringPolicy::SlotBased;
let (mut task_manager, _, _, _, _, _) = tokio_runtime
.block_on(async move {
match relay_chain_config.network.network_backend {
>>>>>>> f6d18b73 (client/net: Use litep2p as the default network backend (#8461))
sc_network::config::NetworkBackendType::Libp2p =>
cumulus_test_service::start_node_impl::<
_,
Expand Down
4 changes: 2 additions & 2 deletions polkadot/node/metrics/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ async fn runtime_can_publish_metrics() {
builder.init().expect("Failed to set up the logger");

// Start validator Alice.
let alice = run_validator_node(alice_config, None);
let alice = run_validator_node(alice_config, None).await;

let bob_config =
node_config(|| {}, tokio::runtime::Handle::current(), Bob, vec![alice.addr.clone()], true);

// Start validator Bob.
let _bob = run_validator_node(bob_config, None);
let _bob = run_validator_node(bob_config, None).await;

// Wait for Alice to see two finalized blocks.
alice.wait_for_finalized_blocks(2).await;
Expand Down
54 changes: 44 additions & 10 deletions polkadot/node/test/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ use sc_chain_spec::ChainSpec;
use sc_client_api::BlockchainEvents;
use sc_network::{
config::{NetworkConfiguration, TransportConfig},
multiaddr, NetworkStateInfo,
multiaddr,
service::traits::NetworkService,
NetworkStateInfo,
};
use sc_service::{
config::{
Expand Down Expand Up @@ -148,7 +150,7 @@ pub fn test_prometheus_config(port: u16) -> PrometheusConfig {

/// Create a Polkadot `Configuration`.
///
/// By default an in-memory socket will be used, therefore you need to provide boot
/// By default a TCP socket will be used, therefore you need to provide boot
/// nodes if you want the future node to be connected to other nodes.
///
/// The `storage_update_func` function will be executed in an externalities provided environment
Expand Down Expand Up @@ -181,12 +183,13 @@ pub fn node_config(

network_config.allow_non_globals_in_dht = true;

let addr: multiaddr::Multiaddr = multiaddr::Protocol::Memory(rand::random()).into();
// Libp2p needs to know the local address on which it should listen for incoming connections,
// while Litep2p will use `/ip4/127.0.0.1/tcp/0` by default.
let addr: multiaddr::Multiaddr = "/ip4/127.0.0.1/tcp/0".parse().expect("valid address; qed");
network_config.listen_addresses.push(addr.clone());

network_config.public_addresses.push(addr);

network_config.transport = TransportConfig::MemoryOnly;
network_config.transport =
TransportConfig::Normal { enable_mdns: false, allow_private_ip: true };

Configuration {
impl_name: "polkadot-test-node".to_string(),
Expand Down Expand Up @@ -238,12 +241,40 @@ pub fn node_config(
}
}

/// Get the listen multiaddr from the network service.
///
/// The address is used to connect to the node.
pub async fn get_listen_address(network: Arc<dyn NetworkService>) -> sc_network::Multiaddr {
loop {
// Litep2p provides instantly the listen address of the TCP protocol and
// ditched the `/0` port used by the `node_config` function.
//
// Libp2p backend needs to be polled in a separate tokio task a few times
// before the listen address is available. The address is made available
// through the `SwarmEvent::NewListenAddr` event.
let listen_addresses = network.listen_addresses();

// The network backend must produce a valid TCP port.
match listen_addresses.into_iter().find(|addr| {
addr.iter().any(|protocol| match protocol {
multiaddr::Protocol::Tcp(port) => port > 0,
_ => false,
})
}) {
Some(multiaddr) => return multiaddr,
None => {
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
continue;
},
}
}
}

/// Run a test validator node that uses the test runtime and specified `config`.
pub fn run_validator_node(
pub async fn run_validator_node(
config: Configuration,
worker_program_path: Option<PathBuf>,
) -> PolkadotTestNode {
let multiaddr = config.network.listen_addresses[0].clone();
let NewFull { task_manager, client, network, rpc_handlers, overseer_handle, .. } = new_full(
config,
IsParachainNode::No,
Expand All @@ -254,6 +285,8 @@ pub fn run_validator_node(

let overseer_handle = overseer_handle.expect("test node must have an overseer handle");
let peer_id = network.local_peer_id();
let multiaddr = get_listen_address(network).await;

let addr = MultiaddrWithPeerId { multiaddr, peer_id };

PolkadotTestNode { task_manager, client, overseer_handle, addr, rpc_handlers }
Expand All @@ -271,15 +304,14 @@ pub fn run_validator_node(
///
/// The collator functionality still needs to be registered at the node! This can be done using
/// [`PolkadotTestNode::register_collator`].
pub fn run_collator_node(
pub async fn run_collator_node(
tokio_handle: tokio::runtime::Handle,
key: Sr25519Keyring,
storage_update_func: impl Fn(),
boot_nodes: Vec<MultiaddrWithPeerId>,
collator_pair: CollatorPair,
) -> PolkadotTestNode {
let config = node_config(storage_update_func, tokio_handle, key, boot_nodes, false);
let multiaddr = config.network.listen_addresses[0].clone();
let NewFull { task_manager, client, network, rpc_handlers, overseer_handle, .. } = new_full(
config,
IsParachainNode::Collator(collator_pair),
Expand All @@ -290,6 +322,8 @@ pub fn run_collator_node(

let overseer_handle = overseer_handle.expect("test node must have an overseer handle");
let peer_id = network.local_peer_id();

let multiaddr = get_listen_address(network).await;
let addr = MultiaddrWithPeerId { multiaddr, peer_id };

PolkadotTestNode { task_manager, client, overseer_handle, addr, rpc_handlers }
Expand Down
4 changes: 2 additions & 2 deletions polkadot/node/test/service/tests/build-blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async fn ensure_test_service_build_blocks() {
Vec::new(),
true,
);
let mut alice = run_validator_node(alice_config, None);
let mut alice = run_validator_node(alice_config, None).await;

let bob_config = node_config(
|| {},
Expand All @@ -39,7 +39,7 @@ async fn ensure_test_service_build_blocks() {
vec![alice.addr.clone()],
true,
);
let mut bob = run_validator_node(bob_config, None);
let mut bob = run_validator_node(bob_config, None).await;

{
let t1 = future::join(alice.wait_for_blocks(3), bob.wait_for_blocks(3)).fuse();
Expand Down
2 changes: 1 addition & 1 deletion polkadot/node/test/service/tests/call-function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async fn call_function_actually_work() {
let alice_config =
node_config(|| {}, tokio::runtime::Handle::current(), Alice, Vec::new(), true);

let alice = run_validator_node(alice_config, None);
let alice = run_validator_node(alice_config, None).await;

let function =
polkadot_test_runtime::RuntimeCall::Balances(pallet_balances::Call::transfer_allow_death {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ async fn collating_using_adder_collator() {
workers_path.pop();

// start alice
let alice = polkadot_test_service::run_validator_node(alice_config, Some(workers_path.clone()));
let alice =
polkadot_test_service::run_validator_node(alice_config, Some(workers_path.clone())).await;

let bob_config = polkadot_test_service::node_config(
|| {},
Expand All @@ -55,7 +56,7 @@ async fn collating_using_adder_collator() {
);

// start bob
let bob = polkadot_test_service::run_validator_node(bob_config, Some(workers_path));
let bob = polkadot_test_service::run_validator_node(bob_config, Some(workers_path)).await;

let collator = test_parachain_adder_collator::Collator::new();

Expand All @@ -72,7 +73,8 @@ async fn collating_using_adder_collator() {
|| {},
vec![alice.addr.clone(), bob.addr.clone()],
collator.collator_key(),
);
)
.await;

charlie
.register_collator(
Expand Down
Loading
Loading