diff --git a/Cargo.lock b/Cargo.lock index 798a66bedfaa0..506c9ac70b559 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3894,6 +3894,22 @@ 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.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + [[package]] name = "crossbeam-deque" version = "0.8.3" @@ -6842,6 +6858,20 @@ dependencies = [ "sp-staking", ] +[[package]] +name = "generator" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d18470a76cb7f8ff746cf1f7470914f900252ec36bbc40b569d74b1258446827" +dependencies = [ + "cc", + "cfg-if", + "libc", + "log", + "rustversion", + "windows 0.61.1", +] + [[package]] name = "generic-array" version = "0.12.4" @@ -7251,9 +7281,9 @@ checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" [[package]] name = "hickory-proto" -version = "0.24.1" +version = "0.25.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07698b8420e2f0d6447a436ba999ec85d8fbf2a398bbd737b82cac4a2e96e512" +checksum = "f8a6fe56c0038198998a6f217ca4e7ef3a5e51f46163bd6dd60b5c71ca6c6502" dependencies = [ "async-trait", "cfg-if", @@ -7262,11 +7292,12 @@ dependencies = [ "futures-channel", "futures-io", "futures-util", - "idna 0.4.0", + "idna 1.0.3", "ipnet", "once_cell", - "rand 0.8.5", - "thiserror 1.0.65", + "rand 0.9.0", + "ring 0.17.7", + "thiserror 2.0.12", "tinyvec", "tokio", "tracing", @@ -7275,21 +7306,21 @@ dependencies = [ [[package]] name = "hickory-resolver" -version = "0.24.2" +version = "0.25.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a2e2aba9c389ce5267d31cf1e4dace82390ae276b0b364ea55630b1fa1b44b4" +checksum = "dc62a9a99b0bfb44d2ab95a7208ac952d31060efc16241c87eaf36406fecf87a" dependencies = [ "cfg-if", "futures-util", "hickory-proto", "ipconfig", - "lru-cache", + "moka", "once_cell", "parking_lot 0.12.3", - "rand 0.8.5", + "rand 0.9.0", "resolv-conf", "smallvec", - "thiserror 1.0.65", + "thiserror 2.0.12", "tokio", "tracing", ] @@ -7462,7 +7493,7 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", - "socket2 0.4.9", + "socket2 0.5.9", "tokio", "tower-service", "tracing", @@ -9470,9 +9501,9 @@ checksum = "4ee93343901ab17bd981295f2cf0026d4ad018c7c31ba84549a4ddbb47a45104" [[package]] name = "litep2p" -version = "0.9.4" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d71056c23c896bb0e18113b2d2f1989be95135e6bdeedb0b757422ee21a073eb" +checksum = "14fb10e63363204b89d91e1292df83322fd9de5d7fa76c3d5c78ddc2f8f3efa9" dependencies = [ "async-trait", "bs58", @@ -9510,7 +9541,7 @@ dependencies = [ "url", "x25519-dalek", "x509-parser 0.17.0", - "yamux 0.13.4", + "yamux 0.13.5", "yasna", "zeroize", ] @@ -9541,6 +9572,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 0.3.18", +] + [[package]] name = "lru" version = "0.11.0" @@ -9988,6 +10032,25 @@ dependencies = [ "syn 2.0.87", ] +[[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" @@ -10703,9 +10766,13 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.19.0" +version = "1.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" +dependencies = [ + "critical-section", + "portable-atomic", +] [[package]] name = "oorandom" @@ -16637,9 +16704,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" @@ -24518,6 +24585,12 @@ dependencies = [ "libc", ] +[[package]] +name = "tagptr" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b2093cf4c8eb1e67749a6762251bc9cd836b6fc171623bd0a9d324d37af2417" + [[package]] name = "tap" version = "1.0.1" @@ -26763,6 +26836,28 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows" +version = "0.61.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5ee8f3d025738cb02bad7868bbb5f8a6327501e870bf51f1b455b0a2454a419" +dependencies = [ + "windows-collections", + "windows-core 0.61.2", + "windows-future", + "windows-link", + "windows-numerics", +] + +[[package]] +name = "windows-collections" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3beeceb5e5cfd9eb1d76b381630e82c4241ccd0d27f1a39ed41b2760b255c5e8" +dependencies = [ + "windows-core 0.61.2", +] + [[package]] name = "windows-core" version = "0.51.1" @@ -26781,6 +26876,86 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows-core" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0fdd3ddb90610c7638aa2b3a3ab2904fb9e5cdbecc643ddb3647212781c4ae3" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-future" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc6a41e98427b19fe4b73c550f060b59fa592d7d686537eebf9385621bfbad8e" +dependencies = [ + "windows-core 0.61.2", + "windows-link", + "windows-threading", +] + +[[package]] +name = "windows-implement" +version = "0.60.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a47fddd13af08290e67f4acabf4b459f647552718f683a7b415d290ac744a836" +dependencies = [ + "proc-macro2 1.0.86", + "quote 1.0.37", + "syn 2.0.87", +] + +[[package]] +name = "windows-interface" +version = "0.59.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd9211b69f8dcdfa817bfd14bf1c97c9188afa36f4750130fcdf3f400eca9fa8" +dependencies = [ + "proc-macro2 1.0.86", + "quote 1.0.37", + "syn 2.0.87", +] + +[[package]] +name = "windows-link" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76840935b766e1b0a05c0066835fb9ec80071d4c09a16f6bd5f7e655e3c14c38" + +[[package]] +name = "windows-numerics" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9150af68066c4c5c07ddc0ce30421554771e528bde427614c61038bc2c92c2b1" +dependencies = [ + "windows-core 0.61.2", + "windows-link", +] + +[[package]] +name = "windows-result" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56f42bd332cc6c8eac5af113fc0c1fd6a8fd2aa08a0119358686e5160d0586c6" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-strings" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56e6c93f3a0c3b36176cb1327a4958a0353d5d166c2a35cb268ace15e91d3b57" +dependencies = [ + "windows-link", +] + [[package]] name = "windows-sys" version = "0.45.0" @@ -26863,6 +27038,15 @@ dependencies = [ "windows_x86_64_msvc 0.52.6", ] +[[package]] +name = "windows-threading" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b66463ad2e0ea3bbf808b7f1d371311c80e115c0b71d60efc142cafbcfb057a6" +dependencies = [ + "windows-link", +] + [[package]] name = "windows_aarch64_gnullvm" version = "0.42.2" @@ -27347,16 +27531,16 @@ dependencies = [ [[package]] name = "yamux" -version = "0.13.4" +version = "0.13.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17610762a1207ee816c6fadc29220904753648aba0a9ed61c7b8336e80a559c4" +checksum = "3da1acad1c2dc53f0dde419115a38bd8221d8c3e47ae9aeceaf453266d29307e" dependencies = [ "futures", "log", "nohash-hasher", "parking_lot 0.12.3", "pin-project", - "rand 0.8.5", + "rand 0.9.0", "static_assertions", "web-time", ] diff --git a/Cargo.toml b/Cargo.toml index 43b91d02742a6..aa0e6b3ad2825 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -846,7 +846,7 @@ 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 } -litep2p = { version = "0.9.4", features = ["websocket"] } +litep2p = { version = "0.9.5", features = ["websocket"] } log = { version = "0.4.22", default-features = false } macro_magic = { version = "0.5.1" } maplit = { version = "1.0.2" } @@ -882,7 +882,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 = "38.1.0" } pallet-asset-conversion = { path = "substrate/frame/asset-conversion", default-features = false, version = "21.1.0" } @@ -1334,7 +1334,7 @@ tikv-jemalloc-ctl = { version = "0.5.0" } tikv-jemallocator = { version = "0.5.0" } time = { version = "0.3" } tiny-keccak = { version = "2.0.2" } -tokio = { version = "1.40.0", default-features = false } +tokio = { version = "1.45.0", default-features = false } tokio-retry = { version = "0.3.0" } tokio-stream = { version = "0.1.14" } tokio-test = { version = "0.4.4" } diff --git a/cumulus/client/relay-chain-minimal-node/src/lib.rs b/cumulus/client/relay-chain-minimal-node/src/lib.rs index 3386fd9160cdd..a3d858ea40c92 100644 --- a/cumulus/client/relay-chain-minimal-node/src/lib.rs +++ b/cumulus/client/relay-chain-minimal-node/src/lib.rs @@ -30,7 +30,7 @@ use polkadot_node_network_protocol::{ use polkadot_core_primitives::{Block as RelayBlock, Hash as RelayHash}; use polkadot_node_subsystem_util::metrics::prometheus::Registry; use polkadot_primitives::CollatorPair; -use polkadot_service::{overseer::OverseerGenArgs, IdentifyNetworkBackend, IsParachainNode}; +use polkadot_service::{overseer::OverseerGenArgs, IsParachainNode}; use sc_authority_discovery::Service as AuthorityDiscoveryService; use sc_network::{ @@ -97,12 +97,7 @@ async fn build_interface( ) -> RelayChainResult<(Arc<(dyn RelayChainInterface + 'static)>, Option)> { let collator_pair = CollatorPair::generate().0; let blockchain_rpc_client = Arc::new(BlockChainRpcClient::new(client.clone())); - - // If the network backend is unspecified, use the default for the given chain. - let default_backend = polkadot_config.chain_spec.network_backend(); - let network_backend = polkadot_config.network.network_backend.unwrap_or(default_backend); - - let collator_node = match network_backend { + let collator_node = match polkadot_config.network.network_backend { sc_network::config::NetworkBackendType::Libp2p => new_minimal_relay_chain::>( polkadot_config, diff --git a/cumulus/polkadot-omni-node/lib/src/common/spec.rs b/cumulus/polkadot-omni-node/lib/src/common/spec.rs index 6b9e3f422aa59..8397cb778dcf4 100644 --- a/cumulus/polkadot-omni-node/lib/src/common/spec.rs +++ b/cumulus/polkadot-omni-node/lib/src/common/spec.rs @@ -31,7 +31,6 @@ use cumulus_client_service::{ use cumulus_primitives_core::{BlockT, ParaId}; use cumulus_relay_chain_interface::{OverseerHandle, RelayChainInterface}; use parachains_common::Hash; -use polkadot_cli::service::IdentifyNetworkBackend; use polkadot_primitives::CollatorPair; use prometheus_endpoint::Registry; use sc_consensus::DefaultImportQueue; @@ -384,10 +383,7 @@ where hwbench: Option, node_extra_args: NodeExtraArgs, ) -> Pin>>> { - // If the network backend is unspecified, use the default for the given chain. - let default_backend = parachain_config.chain_spec.network_backend(); - let network_backend = parachain_config.network.network_backend.unwrap_or(default_backend); - match network_backend { + match parachain_config.network.network_backend { sc_network::config::NetworkBackendType::Libp2p => ::start_node::>( parachain_config, diff --git a/cumulus/polkadot-omni-node/lib/src/nodes/mod.rs b/cumulus/polkadot-omni-node/lib/src/nodes/mod.rs index 6a9fbadcc2b69..ddf5e198ef683 100644 --- a/cumulus/polkadot-omni-node/lib/src/nodes/mod.rs +++ b/cumulus/polkadot-omni-node/lib/src/nodes/mod.rs @@ -20,7 +20,6 @@ mod manual_seal; use crate::common::spec::{DynNodeSpec, NodeSpec as NodeSpecT}; use cumulus_primitives_core::ParaId; use manual_seal::ManualSealNode; -use polkadot_cli::service::IdentifyNetworkBackend; use sc_service::{Configuration, TaskManager}; /// The current node version for cumulus official binaries, which takes the basic @@ -53,11 +52,7 @@ where block_time: u64, ) -> sc_service::error::Result { let node = ManualSealNode::::new(); - - // If the network backend is unspecified, use the default for the given chain. - let default_backend = config.chain_spec.network_backend(); - let network_backend = config.network.network_backend.unwrap_or(default_backend); - match network_backend { + match config.network.network_backend { sc_network::config::NetworkBackendType::Libp2p => node.start_node::>(config, para_id, block_time), sc_network::config::NetworkBackendType::Litep2p => diff --git a/cumulus/test/service/src/lib.rs b/cumulus/test/service/src/lib.rs index 6b50cee05b116..419bfd95eca59 100644 --- a/cumulus/test/service/src/lib.rs +++ b/cumulus/test/service/src/lib.rs @@ -69,7 +69,7 @@ use frame_system_rpc_runtime_api::AccountNonceApi; use polkadot_node_subsystem::{errors::RecoveryError, messages::AvailabilityRecoveryMessage}; use polkadot_overseer::Handle as OverseerHandle; use polkadot_primitives::{CandidateHash, CollatorPair, Hash as PHash, PersistedValidationData}; -use polkadot_service::{IdentifyNetworkBackend, ProvideRuntimeApi}; +use polkadot_service::ProvideRuntimeApi; use sc_consensus::ImportQueue; use sc_network::{ config::{FullNetworkConfiguration, TransportConfig}, @@ -760,13 +760,8 @@ impl TestNodeBuilder { relay_chain_config.network.node_name = format!("{} (relay chain)", relay_chain_config.network.node_name); - let multiaddr = parachain_config.network.listen_addresses[0].clone(); - - // If the network backend is unspecified, use the default for the given chain. - let default_backend = relay_chain_config.chain_spec.network_backend(); - let network_backend = relay_chain_config.network.network_backend.unwrap_or(default_backend); let (task_manager, client, network, rpc_handlers, transaction_pool, backend) = - match network_backend { + match relay_chain_config.network.network_backend { sc_network::config::NetworkBackendType::Libp2p => start_node_impl::<_, sc_network::NetworkWorker<_, _>>( parachain_config, @@ -801,6 +796,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 } @@ -809,10 +805,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, @@ -855,11 +854,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(), @@ -1044,6 +1042,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 df331577af5f0..caa672e611f7c 100644 --- a/cumulus/test/service/src/main.rs +++ b/cumulus/test/service/src/main.rs @@ -21,7 +21,6 @@ use std::sync::Arc; use cli::{RelayChainCli, Subcommand, TestCollatorCli}; use cumulus_primitives_core::relay_chain::CollatorPair; use cumulus_test_service::{chain_spec, new_partial, AnnounceBlockFn}; -use polkadot_service::IdentifyNetworkBackend; use sc_cli::{CliConfiguration, SubstrateCli}; use sp_core::Pair; @@ -104,13 +103,9 @@ fn main() -> Result<(), sc_cli::Error> { }) .unwrap_or(cumulus_test_service::Consensus::Aura); - // If the network backend is unspecified, use the default for the given chain. - let default_backend = relay_chain_config.chain_spec.network_backend(); - let network_backend = - relay_chain_config.network.network_backend.unwrap_or(default_backend); let (mut task_manager, _, _, _, _, _) = tokio_runtime .block_on(async move { - match network_backend { + match relay_chain_config.network.network_backend { 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 4760138058eb7..1d472c4df6a15 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/service/src/lib.rs b/polkadot/node/service/src/lib.rs index dae21d5fa68b7..70fd60d987b6e 100644 --- a/polkadot/node/service/src/lib.rs +++ b/polkadot/node/service/src/lib.rs @@ -327,23 +327,6 @@ impl IdentifyVariant for Box { } } -/// A trait to identify the network backend based on the chain spec. -pub trait IdentifyNetworkBackend { - /// Returns the default network backend. - fn network_backend(&self) -> sc_network::config::NetworkBackendType; -} - -impl IdentifyNetworkBackend for Box { - fn network_backend(&self) -> sc_network::config::NetworkBackendType { - // By default litep2p is enabled only on Kusama. - if self.is_kusama() { - sc_network::config::NetworkBackendType::Litep2p - } else { - sc_network::config::NetworkBackendType::Libp2p - } - } -} - #[cfg(feature = "full-node")] pub fn open_database(db_source: &DatabaseSource) -> Result, Error> { let parachains_db = match db_source { @@ -1456,11 +1439,7 @@ pub fn build_full( capacity }); - // If the network backend is unspecified, use the default for the given chain. - let default_backend = config.chain_spec.network_backend(); - let network_backend = config.network.network_backend.unwrap_or(default_backend); - - match network_backend { + match config.network.network_backend { sc_network::config::NetworkBackendType::Libp2p => new_full::<_, sc_network::NetworkWorker>(config, params), sc_network::config::NetworkBackendType::Litep2p => diff --git a/polkadot/node/test/service/src/lib.rs b/polkadot/node/test/service/src/lib.rs index 68c9c1e920cfa..6e4fd7215da4f 100644 --- a/polkadot/node/test/service/src/lib.rs +++ b/polkadot/node/test/service/src/lib.rs @@ -29,8 +29,7 @@ use polkadot_primitives::{Balance, CollatorPair, HeadData, Id as ParaId, Validat use polkadot_runtime_common::BlockHashCount; use polkadot_runtime_parachains::paras::{ParaGenesisArgs, ParaKind}; use polkadot_service::{ - Error, FullClient, IdentifyNetworkBackend, IsParachainNode, NewFull, OverseerGen, - PrometheusConfig, + Error, FullClient, IsParachainNode, NewFull, OverseerGen, PrometheusConfig, }; use polkadot_test_runtime::{ ParasCall, ParasSudoWrapperCall, Runtime, SignedPayload, SudoCall, TxExtension, @@ -41,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::{ @@ -81,11 +82,7 @@ pub fn new_full( ) -> Result { let workers_path = Some(workers_path.unwrap_or_else(get_relative_workers_path_for_test)); - // If the network backend is unspecified, use the default for the given chain. - let default_backend = config.chain_spec.network_backend(); - let network_backend = config.network.network_backend.unwrap_or(default_backend); - - match network_backend { + match config.network.network_backend { sc_network::config::NetworkBackendType::Libp2p => polkadot_service::new_full::<_, sc_network::NetworkWorker<_, _>>( config, @@ -153,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 @@ -186,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(), @@ -243,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, @@ -259,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 } @@ -276,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(), @@ -284,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), @@ -295,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/bin/node/cli/src/service.rs b/substrate/bin/node/cli/src/service.rs index 78ebddb3f9cc9..008cac4ef8a88 100644 --- a/substrate/bin/node/cli/src/service.rs +++ b/substrate/bin/node/cli/src/service.rs @@ -817,7 +817,7 @@ pub fn new_full(config: Configuration, cli: Cli) -> Result { let task_manager = new_full_base::>( config, diff --git a/substrate/client/cli/src/params/network_params.rs b/substrate/client/cli/src/params/network_params.rs index 695894272df63..5931839265b27 100644 --- a/substrate/client/cli/src/params/network_params.rs +++ b/substrate/client/cli/src/params/network_params.rs @@ -172,16 +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", + default_value_t = NetworkBackendType::Litep2p, ignore_case = true, verbatim_doc_comment )] - pub network_backend: Option, + pub network_backend: NetworkBackendType, } impl NetworkParams { @@ -277,7 +282,7 @@ impl NetworkParams { yamux_window_size: None, ipfs_server: self.ipfs_server, sync_mode: self.sync.into(), - network_backend: self.network_backend.map(Into::into), + network_backend: self.network_backend.into(), } } } diff --git a/substrate/client/network/src/config.rs b/substrate/client/network/src/config.rs index 71780004fd9c3..217ed60a0dad1 100644 --- a/substrate/client/network/src/config.rs +++ b/substrate/client/network/src/config.rs @@ -672,7 +672,7 @@ pub struct NetworkConfiguration { pub yamux_window_size: Option, /// Networking backend used for P2P communication. - pub network_backend: Option, + pub network_backend: NetworkBackendType, } impl NetworkConfiguration { @@ -705,7 +705,7 @@ impl NetworkConfiguration { .expect("value is a constant; constant is non-zero; qed."), yamux_window_size: None, ipfs_server: false, - network_backend: None, + network_backend: NetworkBackendType::Litep2p, } } @@ -933,12 +933,19 @@ impl> FullNetworkConfig /// Network backend type. #[derive(Debug, Clone, Default, Copy)] pub enum NetworkBackendType { - /// Use libp2p for P2P networking. - #[default] - Libp2p, - /// 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 690d5a31e6ad6..d30fdfdc3650f 100644 --- a/substrate/client/network/src/litep2p/shim/request_response/mod.rs +++ b/substrate/client/network/src/litep2p/shim/request_response/mod.rs @@ -433,7 +433,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 ee4f4e7622e74..8fd58a4de05d8 100644 --- a/substrate/client/service/src/lib.rs +++ b/substrate/client/service/src/lib.rs @@ -522,7 +522,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)) }, }; diff --git a/templates/minimal/node/src/command.rs b/templates/minimal/node/src/command.rs index ca2cc1804f130..5cb0694d98282 100644 --- a/templates/minimal/node/src/command.rs +++ b/templates/minimal/node/src/command.rs @@ -117,7 +117,7 @@ pub fn run() -> sc_cli::Result<()> { None => { let runner = cli.create_runner(&cli.run)?; runner.run_node_until_exit(|config| async move { - match config.network.network_backend.unwrap_or_default() { + match config.network.network_backend { sc_network::config::NetworkBackendType::Libp2p => service::new_full::>(config, cli.consensus) .map_err(sc_cli::Error::Service), diff --git a/templates/solochain/node/src/command.rs b/templates/solochain/node/src/command.rs index 54540db7c2426..1c23e395ede93 100644 --- a/templates/solochain/node/src/command.rs +++ b/templates/solochain/node/src/command.rs @@ -178,7 +178,7 @@ pub fn run() -> sc_cli::Result<()> { None => { let runner = cli.create_runner(&cli.run)?; runner.run_node_until_exit(|config| async move { - match config.network.network_backend.unwrap_or_default() { + match config.network.network_backend { sc_network::config::NetworkBackendType::Libp2p => service::new_full::< sc_network::NetworkWorker< solochain_template_runtime::opaque::Block,