diff --git a/Cargo.lock b/Cargo.lock index 30a6283d16d89..6a1c623c13afc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3636,6 +3636,21 @@ dependencies = [ "itertools 0.10.5", ] +[[package]] +name = "critical-section" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "790eea4361631c5e7d22598ecd5723ff611904e3344ce8720784c93e3d83d40b" + +[[package]] +name = "crossbeam-channel" +version = "0.5.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82b8f8f868b36967f9606790d1903570de9ceaf870a7bf9fbbd3016d636a2cb2" +dependencies = [ + "crossbeam-utils", +] + [[package]] name = "crossbeam-deque" version = "0.8.3" @@ -6366,6 +6381,19 @@ dependencies = [ "sp-staking", ] +[[package]] +name = "generator" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc6bd114ceda131d3b1d665eba35788690ad37f5916457286b32ab6fd3c438dd" +dependencies = [ + "cfg-if", + "libc", + "log", + "rustversion", + "windows 0.58.0", +] + [[package]] name = "generic-array" version = "0.12.4" @@ -6706,6 +6734,101 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" [[package]] +<<<<<<< HEAD +======= +name = "hickory-proto" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07698b8420e2f0d6447a436ba999ec85d8fbf2a398bbd737b82cac4a2e96e512" +dependencies = [ + "async-trait", + "cfg-if", + "data-encoding", + "enum-as-inner", + "futures-channel", + "futures-io", + "futures-util", + "idna 0.4.0", + "ipnet", + "once_cell", + "rand 0.8.5", + "socket2 0.5.9", + "thiserror 1.0.65", + "tinyvec", + "tokio", + "tracing", + "url", +] + +[[package]] +name = "hickory-proto" +version = "0.25.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8a6fe56c0038198998a6f217ca4e7ef3a5e51f46163bd6dd60b5c71ca6c6502" +dependencies = [ + "async-trait", + "cfg-if", + "data-encoding", + "enum-as-inner", + "futures-channel", + "futures-io", + "futures-util", + "idna 1.0.3", + "ipnet", + "once_cell", + "rand 0.9.0", + "ring 0.17.8", + "thiserror 2.0.12", + "tinyvec", + "tokio", + "tracing", + "url", +] + +[[package]] +name = "hickory-resolver" +version = "0.24.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a2e2aba9c389ce5267d31cf1e4dace82390ae276b0b364ea55630b1fa1b44b4" +dependencies = [ + "cfg-if", + "futures-util", + "hickory-proto 0.24.1", + "ipconfig", + "lru-cache", + "once_cell", + "parking_lot 0.12.3", + "rand 0.8.5", + "resolv-conf", + "smallvec", + "thiserror 1.0.65", + "tokio", + "tracing", +] + +[[package]] +name = "hickory-resolver" +version = "0.25.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc62a9a99b0bfb44d2ab95a7208ac952d31060efc16241c87eaf36406fecf87a" +dependencies = [ + "cfg-if", + "futures-util", + "hickory-proto 0.25.2", + "ipconfig", + "moka", + "once_cell", + "parking_lot 0.12.3", + "rand 0.9.0", + "resolv-conf", + "smallvec", + "thiserror 2.0.12", + "tokio", + "tracing", +] + +[[package]] +>>>>>>> f6d18b73 (client/net: Use litep2p as the default network backend (#8461)) name = "hkdf" version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -7819,6 +7942,10 @@ checksum = "e6a18db73084b4da2871438f6239fef35190b05023de7656e877c18a00541a3b" dependencies = [ "async-trait", "futures", +<<<<<<< HEAD +======= + "hickory-resolver 0.24.2", +>>>>>>> f6d18b73 (client/net: Use litep2p as the default network backend (#8461)) "libp2p-core", "libp2p-identity", "log", @@ -7905,6 +8032,10 @@ checksum = "42a2567c305232f5ef54185e9604579a894fd0674819402bb0ac0246da82f52a" dependencies = [ "data-encoding", "futures", +<<<<<<< HEAD +======= + "hickory-proto 0.24.1", +>>>>>>> f6d18b73 (client/net: Use litep2p as the default network backend (#8461)) "if-watch", "libp2p-core", "libp2p-identity", @@ -8151,9 +8282,16 @@ checksum = "8eedcb62824c4300efb9cfd4e2a6edaf3ca097b9e68b36dabe45a44469fd6a85" dependencies = [ "futures", "libp2p-core", +<<<<<<< HEAD "log", "thiserror", "yamux", +======= + "thiserror 1.0.65", + "tracing", + "yamux 0.12.1", + "yamux 0.13.5", +>>>>>>> f6d18b73 (client/net: Use litep2p as the default network backend (#8461)) ] [[package]] @@ -8314,9 +8452,15 @@ dependencies = [ [[package]] name = "litep2p" +<<<<<<< HEAD version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0f46c51c205264b834ceed95c8b195026e700494bc3991aaba3b4ea9e20626d9" +======= +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14fb10e63363204b89d91e1292df83322fd9de5d7fa76c3d5c78ddc2f8f3efa9" +>>>>>>> f6d18b73 (client/net: Use litep2p as the default network backend (#8461)) dependencies = [ "async-trait", "bs58 0.4.0", @@ -8325,8 +8469,13 @@ dependencies = [ "ed25519-dalek", "futures", "futures-timer", +<<<<<<< HEAD "hex-literal", "indexmap 2.2.3", +======= + "hickory-resolver 0.25.2", + "indexmap 2.9.0", +>>>>>>> f6d18b73 (client/net: Use litep2p as the default network backend (#8461)) "libc", "mockall 0.12.1", "multiaddr 0.17.1", @@ -8362,7 +8511,12 @@ dependencies = [ "url", "webpki", "x25519-dalek", +<<<<<<< HEAD "x509-parser 0.16.0", +======= + "x509-parser 0.17.0", + "yamux 0.13.5", +>>>>>>> f6d18b73 (client/net: Use litep2p as the default network backend (#8461)) "yasna", "zeroize", ] @@ -8387,6 +8541,19 @@ dependencies = [ "value-bag", ] +[[package]] +name = "loom" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "419e0dc8046cb947daa77eb95ae174acfbddb7673b4151f56d1eed8e93fbfaca" +dependencies = [ + "cfg-if", + "generator", + "scoped-tls", + "tracing", + "tracing-subscriber", +] + [[package]] name = "lru" version = "0.8.1" @@ -8844,6 +9011,25 @@ dependencies = [ "syn 2.0.65", ] +[[package]] +name = "moka" +version = "0.12.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9321642ca94a4282428e6ea4af8cc2ca4eac48ac7a6a4ea8f33f76d0ce70926" +dependencies = [ + "crossbeam-channel", + "crossbeam-epoch", + "crossbeam-utils", + "loom", + "parking_lot 0.12.3", + "portable-atomic", + "rustc_version 0.4.0", + "smallvec", + "tagptr", + "thiserror 1.0.65", + "uuid", +] + [[package]] name = "multi-stash" version = "0.2.0" @@ -9523,9 +9709,19 @@ dependencies = [ [[package]] name = "once_cell" +<<<<<<< HEAD version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +======= +version = "1.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" +dependencies = [ + "critical-section", + "portable-atomic", +] +>>>>>>> f6d18b73 (client/net: Use litep2p as the default network backend (#8461)) [[package]] name = "oorandom" @@ -15350,9 +15546,9 @@ dependencies = [ [[package]] name = "portable-atomic" -version = "1.4.2" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f32154ba0af3a075eefa1eda8bb414ee928f62303a54ea85b8d6638ff1a6ee9e" +checksum = "350e9b48cbc6b0e028b0473b114454c6316e57336ee184ceab6e53f72c178b3e" [[package]] name = "portpicker" @@ -21756,6 +21952,25 @@ dependencies = [ ] [[package]] +<<<<<<< HEAD +======= +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tagptr" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b2093cf4c8eb1e67749a6762251bc9cd836b6fc171623bd0a9d324d37af2417" + +[[package]] +>>>>>>> f6d18b73 (client/net: Use litep2p as the default network backend (#8461)) name = "tap" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -22151,9 +22366,15 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" +<<<<<<< HEAD version = "1.37.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +======= +version = "1.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2513ca694ef9ede0fb23fe71a4ee4107cb102b9dc1930f6d0fd77aae068ae165" +>>>>>>> f6d18b73 (client/net: Use litep2p as the default network backend (#8461)) dependencies = [ "backtrace", "bytes", @@ -23695,6 +23916,16 @@ dependencies = [ "windows-targets 0.52.0", ] +[[package]] +name = "windows" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd04d41d93c4992d421894c18c8b43496aa748dd4c081bac0dc93eb0489272b6" +dependencies = [ + "windows-core 0.58.0", + "windows-targets 0.52.6", +] + [[package]] name = "windows-core" version = "0.51.1" @@ -23714,8 +23945,48 @@ dependencies = [ ] [[package]] +<<<<<<< HEAD name = "windows-sys" version = "0.42.0" +======= +name = "windows-core" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ba6d44ec8c2591c134257ce647b7ea6b20335bf6379a27dac5f1641fcf59f99" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-implement" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bbd5b46c938e506ecbce286b6628a02171d56153ba733b6c741fc627ec9579b" +dependencies = [ + "proc-macro2 1.0.95", + "quote 1.0.40", + "syn 2.0.98", +] + +[[package]] +name = "windows-interface" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053c4c462dc91d3b1504c6fe5a726dd15e216ba718e84a0e46a88fbe5ded3515" +dependencies = [ + "proc-macro2 1.0.95", + "quote 1.0.40", + "syn 2.0.98", +] + +[[package]] +name = "windows-link" +version = "0.1.0" +>>>>>>> f6d18b73 (client/net: Use litep2p as the default network backend (#8461)) source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" dependencies = [ @@ -24241,6 +24512,25 @@ dependencies = [ ] [[package]] +<<<<<<< HEAD +======= +name = "yamux" +version = "0.13.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3da1acad1c2dc53f0dde419115a38bd8221d8c3e47ae9aeceaf453266d29307e" +dependencies = [ + "futures", + "log", + "nohash-hasher", + "parking_lot 0.12.3", + "pin-project", + "rand 0.9.0", + "static_assertions", + "web-time", +] + +[[package]] +>>>>>>> f6d18b73 (client/net: Use litep2p as the default network backend (#8461)) name = "yansi" version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" diff --git a/Cargo.toml b/Cargo.toml index efa738d5accb3..bae2b60a4f5a3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" } @@ -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" } @@ -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" } diff --git a/cumulus/client/relay-chain-inprocess-interface/src/lib.rs b/cumulus/client/relay-chain-inprocess-interface/src/lib.rs index c796dc5f7c382..4176e749061eb 100644 --- a/cumulus/client/relay-chain-inprocess-interface/src/lib.rs +++ b/cumulus/client/relay-chain-inprocess-interface/src/lib.rs @@ -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 diff --git a/cumulus/client/relay-chain-minimal-node/src/lib.rs b/cumulus/client/relay-chain-minimal-node/src/lib.rs index e65a78f16d79b..e4a83753e71c8 100644 --- a/cumulus/client/relay-chain-minimal-node/src/lib.rs +++ b/cumulus/client/relay-chain-minimal-node/src/lib.rs @@ -96,6 +96,10 @@ async fn build_interface( client: RelayChainRpcClient, ) -> RelayChainResult<(Arc<(dyn RelayChainInterface + 'static)>, Option)> { 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::>( diff --git a/cumulus/polkadot-omni-node/lib/src/nodes/mod.rs b/cumulus/polkadot-omni-node/lib/src/nodes/mod.rs new file mode 100644 index 0000000000000..b951c4ed5f48f --- /dev/null +++ b/cumulus/polkadot-omni-node/lib/src/nodes/mod.rs @@ -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 `..`. 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; +} + +impl 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 { + let node = ManualSealNode::::new(); + match config.network.network_backend { + sc_network::config::NetworkBackendType::Libp2p => + node.start_node::>(config, para_id, block_time), + sc_network::config::NetworkBackendType::Litep2p => + node.start_node::(config, para_id, block_time), + } + } +} diff --git a/cumulus/test/service/src/lib.rs b/cumulus/test/service/src/lib.rs index a600dcce3d66e..915f2aab1c726 100644 --- a/cumulus/test/service/src/lib.rs +++ b/cumulus/test/service/src/lib.rs @@ -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 => @@ -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 } @@ -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, @@ -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(), @@ -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 }) } diff --git a/cumulus/test/service/src/main.rs b/cumulus/test/service/src/main.rs index 9357978b769a4..324a2fd3626e3 100644 --- a/cumulus/test/service/src/main.rs +++ b/cumulus/test/service/src/main.rs @@ -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::< _, diff --git a/polkadot/node/metrics/src/tests.rs b/polkadot/node/metrics/src/tests.rs index e720924feb60c..ac0743ecbad9f 100644 --- a/polkadot/node/metrics/src/tests.rs +++ b/polkadot/node/metrics/src/tests.rs @@ -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; diff --git a/polkadot/node/test/service/src/lib.rs b/polkadot/node/test/service/src/lib.rs index b12387884861f..2e3c9d83b8e00 100644 --- a/polkadot/node/test/service/src/lib.rs +++ b/polkadot/node/test/service/src/lib.rs @@ -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::{ @@ -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 @@ -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(), @@ -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) -> 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, ) -> PolkadotTestNode { - let multiaddr = config.network.listen_addresses[0].clone(); let NewFull { task_manager, client, network, rpc_handlers, overseer_handle, .. } = new_full( config, IsParachainNode::No, @@ -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 } @@ -271,7 +304,7 @@ 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(), @@ -279,7 +312,6 @@ pub fn run_collator_node( 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), @@ -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 } diff --git a/polkadot/node/test/service/tests/build-blocks.rs b/polkadot/node/test/service/tests/build-blocks.rs index d5c6ab0b5ba66..07940d8e4f6a7 100644 --- a/polkadot/node/test/service/tests/build-blocks.rs +++ b/polkadot/node/test/service/tests/build-blocks.rs @@ -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( || {}, @@ -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(); diff --git a/polkadot/node/test/service/tests/call-function.rs b/polkadot/node/test/service/tests/call-function.rs index 39d162eb37697..693288c675d59 100644 --- a/polkadot/node/test/service/tests/call-function.rs +++ b/polkadot/node/test/service/tests/call-function.rs @@ -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 { diff --git a/polkadot/parachain/test-parachains/adder/collator/tests/integration.rs b/polkadot/parachain/test-parachains/adder/collator/tests/integration.rs index 85abf8bf36b97..f461e5420cff1 100644 --- a/polkadot/parachain/test-parachains/adder/collator/tests/integration.rs +++ b/polkadot/parachain/test-parachains/adder/collator/tests/integration.rs @@ -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( || {}, @@ -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(); @@ -72,7 +73,8 @@ async fn collating_using_adder_collator() { || {}, vec![alice.addr.clone(), bob.addr.clone()], collator.collator_key(), - ); + ) + .await; charlie .register_collator( diff --git a/polkadot/parachain/test-parachains/undying/collator/tests/integration.rs b/polkadot/parachain/test-parachains/undying/collator/tests/integration.rs index 8be535b9bb4cc..fa0ccce3fe34b 100644 --- a/polkadot/parachain/test-parachains/undying/collator/tests/integration.rs +++ b/polkadot/parachain/test-parachains/undying/collator/tests/integration.rs @@ -43,7 +43,8 @@ async fn collating_using_undying_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( || {}, @@ -54,7 +55,7 @@ async fn collating_using_undying_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_undying_collator::Collator::new(1_000, 1); @@ -71,7 +72,8 @@ async fn collating_using_undying_collator() { || {}, vec![alice.addr.clone(), bob.addr.clone()], collator.collator_key(), - ); + ) + .await; charlie .register_collator( diff --git a/prdoc/pr_8461.prdoc b/prdoc/pr_8461.prdoc new file mode 100644 index 0000000000000..49663422035de --- /dev/null +++ b/prdoc/pr_8461.prdoc @@ -0,0 +1,29 @@ +title: Use litep2p as the default network backend + +doc: + - audience: [Node Dev, Node Operator] + description: | + This PR makes the litep2p backend the default backend. + Litep2p is a lightweight alternative to libp2p, that is designed to be more + efficient and easier to use. At the same time, litep2p brings performance + improvements and reduces the CPU usage significantly. + Libp2p is the old network backend, that may still be used for compatibility + reasons until the whole ecosystem is migrated to litep2p. + +crates: + - name: sc-network + bump: minor + - name: sc-cli + bump: patch + - name: sc-network-types + bump: minor + - name: polkadot-service + bump: minor + - name: sc-offchain + bump: patch + - name: cumulus-relay-chain-minimal-node + bump: patch + - name: cumulus-relay-chain-inprocess-interface + bump: patch + - name: polkadot-omni-node-lib + bump: patch diff --git a/substrate/client/cli/src/params/network_params.rs b/substrate/client/cli/src/params/network_params.rs index 748b84a50d2ae..4714f63aba8ce 100644 --- a/substrate/client/cli/src/params/network_params.rs +++ b/substrate/client/cli/src/params/network_params.rs @@ -172,13 +172,21 @@ pub struct NetworkParams { /// Network backend used for P2P networking. /// - /// litep2p network backend is considered experimental and isn't as stable as the libp2p - /// network backend. + /// Litep2p is a lightweight alternative to libp2p, that is designed to be more + /// efficient and easier to use. At the same time, litep2p brings performance + /// improvements and reduces the CPU usage significantly. + /// + /// Libp2p is the old network backend, that may still be used for compatibility + /// reasons until the whole ecosystem is migrated to litep2p. #[arg( long, value_enum, value_name = "NETWORK_BACKEND", +<<<<<<< HEAD default_value_t = NetworkBackendType::Libp2p, +======= + default_value_t = NetworkBackendType::Litep2p, +>>>>>>> f6d18b73 (client/net: Use litep2p as the default network backend (#8461)) ignore_case = true, verbatim_doc_comment )] diff --git a/substrate/client/network/src/config.rs b/substrate/client/network/src/config.rs index 327f79fe6c130..f4f6325254dc9 100644 --- a/substrate/client/network/src/config.rs +++ b/substrate/client/network/src/config.rs @@ -705,7 +705,11 @@ impl NetworkConfiguration { .expect("value is a constant; constant is non-zero; qed."), yamux_window_size: None, ipfs_server: false, +<<<<<<< HEAD network_backend: NetworkBackendType::Libp2p, +======= + network_backend: NetworkBackendType::Litep2p, +>>>>>>> f6d18b73 (client/net: Use litep2p as the default network backend (#8461)) } } @@ -933,11 +937,25 @@ impl> FullNetworkConfig /// Network backend type. #[derive(Debug, Clone)] pub enum NetworkBackendType { +<<<<<<< HEAD /// Use libp2p for P2P networking. Libp2p, +======= +>>>>>>> f6d18b73 (client/net: Use litep2p as the default network backend (#8461)) /// Use litep2p for P2P networking. + /// + /// This is the preferred option for Substrate-based chains. + #[default] Litep2p, + + /// Use libp2p for P2P networking. + /// + /// The libp2p is still used for compatibility reasons until the + /// ecosystem switches entirely to litep2p. The backend will enter + /// a "best-effort" maintenance mode, where only critical issues will + /// get fixed. If you are unsure, please use `NetworkBackendType::Litep2p`. + Libp2p, } #[cfg(test)] diff --git a/substrate/client/network/src/litep2p/shim/request_response/mod.rs b/substrate/client/network/src/litep2p/shim/request_response/mod.rs index e7598debde158..b83742996236b 100644 --- a/substrate/client/network/src/litep2p/shim/request_response/mod.rs +++ b/substrate/client/network/src/litep2p/shim/request_response/mod.rs @@ -406,7 +406,7 @@ impl RequestResponseProtocol { Some(sender) => { log::debug!( target: LOG_TARGET, - "{}: failed to negotiate protocol with {:?}, try fallback request: ({})", + "{}: failed to negotiate protocol with {:?}. Trying the fallback protocol ({})", self.protocol, peer, protocol, diff --git a/substrate/client/service/src/lib.rs b/substrate/client/service/src/lib.rs index 251eef97be844..ea427ac2be1c4 100644 --- a/substrate/client/service/src/lib.rs +++ b/substrate/client/service/src/lib.rs @@ -517,7 +517,7 @@ where let uxt = match Decode::decode(&mut &encoded[..]) { Ok(uxt) => uxt, Err(e) => { - debug!("Transaction invalid: {:?}", e); + debug!(target: sc_transaction_pool::LOG_TARGET, "Transaction invalid: {:?}", e); return Box::pin(futures::future::ready(TransactionImport::Bad)) }, };