Skip to content

Commit 4bf0998

Browse files
lexnvbkchr
andauthored
backport/2412: network: Make litep2p the default backend in Kusama (#7866) (#7887)
Backport for: - #7866 cc @EgorPopelyaev 🙏 Signed-off-by: Alexandru Vasile <[email protected]> Co-authored-by: Bastian Köcher <[email protected]>
1 parent 35df911 commit 4bf0998

File tree

16 files changed

+101
-22
lines changed

16 files changed

+101
-22
lines changed

Cargo.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ linked-hash-map = { version = "0.5.4" }
846846
linked_hash_set = { version = "0.1.4" }
847847
linregress = { version = "0.5.1" }
848848
lite-json = { version = "0.2.0", default-features = false }
849-
litep2p = { version = "0.9.1", features = ["websocket"] }
849+
litep2p = { version = "0.9.3", features = ["websocket"] }
850850
log = { version = "0.4.22", default-features = false }
851851
macro_magic = { version = "0.5.1" }
852852
maplit = { version = "1.0.2" }

cumulus/client/relay-chain-minimal-node/src/lib.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use polkadot_node_network_protocol::{
3030
use polkadot_core_primitives::{Block as RelayBlock, Hash as RelayHash};
3131
use polkadot_node_subsystem_util::metrics::prometheus::Registry;
3232
use polkadot_primitives::CollatorPair;
33-
use polkadot_service::{overseer::OverseerGenArgs, IsParachainNode};
33+
use polkadot_service::{overseer::OverseerGenArgs, IdentifyNetworkBackend, IsParachainNode};
3434

3535
use sc_authority_discovery::Service as AuthorityDiscoveryService;
3636
use sc_network::{
@@ -97,7 +97,12 @@ async fn build_interface(
9797
) -> RelayChainResult<(Arc<(dyn RelayChainInterface + 'static)>, Option<CollatorPair>)> {
9898
let collator_pair = CollatorPair::generate().0;
9999
let blockchain_rpc_client = Arc::new(BlockChainRpcClient::new(client.clone()));
100-
let collator_node = match polkadot_config.network.network_backend {
100+
101+
// If the network backend is unspecified, use the default for the given chain.
102+
let default_backend = polkadot_config.chain_spec.network_backend();
103+
let network_backend = polkadot_config.network.network_backend.unwrap_or(default_backend);
104+
105+
let collator_node = match network_backend {
101106
sc_network::config::NetworkBackendType::Libp2p =>
102107
new_minimal_relay_chain::<RelayBlock, sc_network::NetworkWorker<RelayBlock, RelayHash>>(
103108
polkadot_config,

cumulus/polkadot-omni-node/lib/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ substrate-state-trie-migration-rpc.workspace = true
102102
substrate-state-trie-migration-rpc.default-features = true
103103
polkadot-cli.workspace = true
104104
polkadot-cli.default-features = true
105+
polkadot-cli.features = ["service"]
105106
polkadot-primitives.workspace = true
106107
polkadot-primitives.default-features = true
107108
cumulus-client-cli.workspace = true

cumulus/polkadot-omni-node/lib/src/common/spec.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use cumulus_client_service::{
3131
use cumulus_primitives_core::{BlockT, ParaId};
3232
use cumulus_relay_chain_interface::{OverseerHandle, RelayChainInterface};
3333
use parachains_common::Hash;
34+
use polkadot_cli::service::IdentifyNetworkBackend;
3435
use polkadot_primitives::CollatorPair;
3536
use prometheus_endpoint::Registry;
3637
use sc_consensus::DefaultImportQueue;
@@ -383,7 +384,10 @@ where
383384
hwbench: Option<HwBench>,
384385
node_extra_args: NodeExtraArgs,
385386
) -> Pin<Box<dyn Future<Output = sc_service::error::Result<TaskManager>>>> {
386-
match parachain_config.network.network_backend {
387+
// If the network backend is unspecified, use the default for the given chain.
388+
let default_backend = parachain_config.chain_spec.network_backend();
389+
let network_backend = parachain_config.network.network_backend.unwrap_or(default_backend);
390+
match network_backend {
387391
sc_network::config::NetworkBackendType::Libp2p =>
388392
<Self as NodeSpec>::start_node::<sc_network::NetworkWorker<_, _>>(
389393
parachain_config,

cumulus/polkadot-omni-node/lib/src/nodes/mod.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ mod manual_seal;
2020
use crate::common::spec::{DynNodeSpec, NodeSpec as NodeSpecT};
2121
use cumulus_primitives_core::ParaId;
2222
use manual_seal::ManualSealNode;
23+
use polkadot_cli::service::IdentifyNetworkBackend;
2324
use sc_service::{Configuration, TaskManager};
2425

2526
/// The current node version for cumulus official binaries, which takes the basic
@@ -52,7 +53,11 @@ where
5253
block_time: u64,
5354
) -> sc_service::error::Result<TaskManager> {
5455
let node = ManualSealNode::<T>::new();
55-
match config.network.network_backend {
56+
57+
// If the network backend is unspecified, use the default for the given chain.
58+
let default_backend = config.chain_spec.network_backend();
59+
let network_backend = config.network.network_backend.unwrap_or(default_backend);
60+
match network_backend {
5661
sc_network::config::NetworkBackendType::Libp2p =>
5762
node.start_node::<sc_network::NetworkWorker<_, _>>(config, para_id, block_time),
5863
sc_network::config::NetworkBackendType::Litep2p =>

cumulus/test/service/src/lib.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ use frame_system_rpc_runtime_api::AccountNonceApi;
6969
use polkadot_node_subsystem::{errors::RecoveryError, messages::AvailabilityRecoveryMessage};
7070
use polkadot_overseer::Handle as OverseerHandle;
7171
use polkadot_primitives::{CandidateHash, CollatorPair, Hash as PHash, PersistedValidationData};
72-
use polkadot_service::ProvideRuntimeApi;
72+
use polkadot_service::{IdentifyNetworkBackend, ProvideRuntimeApi};
7373
use sc_consensus::ImportQueue;
7474
use sc_network::{
7575
config::{FullNetworkConfiguration, TransportConfig},
@@ -761,8 +761,12 @@ impl TestNodeBuilder {
761761
format!("{} (relay chain)", relay_chain_config.network.node_name);
762762

763763
let multiaddr = parachain_config.network.listen_addresses[0].clone();
764+
765+
// If the network backend is unspecified, use the default for the given chain.
766+
let default_backend = relay_chain_config.chain_spec.network_backend();
767+
let network_backend = relay_chain_config.network.network_backend.unwrap_or(default_backend);
764768
let (task_manager, client, network, rpc_handlers, transaction_pool, backend) =
765-
match relay_chain_config.network.network_backend {
769+
match network_backend {
766770
sc_network::config::NetworkBackendType::Libp2p =>
767771
start_node_impl::<_, sc_network::NetworkWorker<_, _>>(
768772
parachain_config,

cumulus/test/service/src/main.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use std::sync::Arc;
2121
use cli::{RelayChainCli, Subcommand, TestCollatorCli};
2222
use cumulus_primitives_core::relay_chain::CollatorPair;
2323
use cumulus_test_service::{chain_spec, new_partial, AnnounceBlockFn};
24+
use polkadot_service::IdentifyNetworkBackend;
2425
use sc_cli::{CliConfiguration, SubstrateCli};
2526
use sp_core::Pair;
2627

@@ -103,9 +104,13 @@ fn main() -> Result<(), sc_cli::Error> {
103104
})
104105
.unwrap_or(cumulus_test_service::Consensus::Aura);
105106

107+
// If the network backend is unspecified, use the default for the given chain.
108+
let default_backend = relay_chain_config.chain_spec.network_backend();
109+
let network_backend =
110+
relay_chain_config.network.network_backend.unwrap_or(default_backend);
106111
let (mut task_manager, _, _, _, _, _) = tokio_runtime
107112
.block_on(async move {
108-
match relay_chain_config.network.network_backend {
113+
match network_backend {
109114
sc_network::config::NetworkBackendType::Libp2p =>
110115
cumulus_test_service::start_node_impl::<
111116
_,

polkadot/node/service/src/lib.rs

+22-1
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,23 @@ impl IdentifyVariant for Box<dyn ChainSpec> {
327327
}
328328
}
329329

330+
/// A trait to identify the network backend based on the chain spec.
331+
pub trait IdentifyNetworkBackend {
332+
/// Returns the default network backend.
333+
fn network_backend(&self) -> sc_network::config::NetworkBackendType;
334+
}
335+
336+
impl IdentifyNetworkBackend for Box<dyn ChainSpec> {
337+
fn network_backend(&self) -> sc_network::config::NetworkBackendType {
338+
// By default litep2p is enabled only on Kusama.
339+
if self.is_kusama() {
340+
sc_network::config::NetworkBackendType::Litep2p
341+
} else {
342+
sc_network::config::NetworkBackendType::Libp2p
343+
}
344+
}
345+
}
346+
330347
#[cfg(feature = "full-node")]
331348
pub fn open_database(db_source: &DatabaseSource) -> Result<Arc<dyn Database>, Error> {
332349
let parachains_db = match db_source {
@@ -1439,7 +1456,11 @@ pub fn build_full<OverseerGenerator: OverseerGen>(
14391456
capacity
14401457
});
14411458

1442-
match config.network.network_backend {
1459+
// If the network backend is unspecified, use the default for the given chain.
1460+
let default_backend = config.chain_spec.network_backend();
1461+
let network_backend = config.network.network_backend.unwrap_or(default_backend);
1462+
1463+
match network_backend {
14431464
sc_network::config::NetworkBackendType::Libp2p =>
14441465
new_full::<_, sc_network::NetworkWorker<Block, Hash>>(config, params),
14451466
sc_network::config::NetworkBackendType::Litep2p =>

polkadot/node/test/service/src/lib.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ use polkadot_primitives::{Balance, CollatorPair, HeadData, Id as ParaId, Validat
2929
use polkadot_runtime_common::BlockHashCount;
3030
use polkadot_runtime_parachains::paras::{ParaGenesisArgs, ParaKind};
3131
use polkadot_service::{
32-
Error, FullClient, IsParachainNode, NewFull, OverseerGen, PrometheusConfig,
32+
Error, FullClient, IdentifyNetworkBackend, IsParachainNode, NewFull, OverseerGen,
33+
PrometheusConfig,
3334
};
3435
use polkadot_test_runtime::{
3536
ParasCall, ParasSudoWrapperCall, Runtime, SignedPayload, SudoCall, TxExtension,
@@ -80,7 +81,11 @@ pub fn new_full<OverseerGenerator: OverseerGen>(
8081
) -> Result<NewFull, Error> {
8182
let workers_path = Some(workers_path.unwrap_or_else(get_relative_workers_path_for_test));
8283

83-
match config.network.network_backend {
84+
// If the network backend is unspecified, use the default for the given chain.
85+
let default_backend = config.chain_spec.network_backend();
86+
let network_backend = config.network.network_backend.unwrap_or(default_backend);
87+
88+
match network_backend {
8489
sc_network::config::NetworkBackendType::Libp2p =>
8590
polkadot_service::new_full::<_, sc_network::NetworkWorker<_, _>>(
8691
config,

prdoc/pr_7866.prdoc

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
title: Make litep2p the default backend in Kusama
2+
3+
doc:
4+
- audience: Node Operator
5+
description: |
6+
This PR makes the litep2p backend the default network backend in Kusama, but also for system chains.
7+
We performed a gradual rollout in Kusama by asking validators to manually switch to litep2p.
8+
The rollout went smoothly, with 250 validators running litep2p without issues. This PR represents the next step in testing the backend at scale.
9+
10+
- audience: Node Dev
11+
description: |
12+
A new trait `IdentifyNetworkBackend` is introduced for the polkadot-service. The purpose of the trait
13+
is to specify the default network backend for individual chains. For Kusama based chains, the default
14+
is now litep2p. For other chains, the default remains unchanged to libp2p.
15+
The network backend field of the network configuration is made optional to accomodate for this change.
16+
17+
crates:
18+
- name: sc-network
19+
bump: minor
20+
- name: sc-network-types
21+
bump: minor
22+
- name: polkadot-service
23+
bump: minor
24+
- name: sc-cli
25+
bump: patch
26+
- name: cumulus-relay-chain-minimal-node
27+
bump: patch
28+
- name: polkadot-omni-node-lib
29+
bump: patch

substrate/bin/node/cli/src/service.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ pub fn new_full(config: Configuration, cli: Cli) -> Result<TaskManager, ServiceE
817817
let mixnet_config = cli.mixnet_params.config(config.role.is_authority());
818818
let database_path = config.database.path().map(Path::to_path_buf);
819819

820-
let task_manager = match config.network.network_backend {
820+
let task_manager = match config.network.network_backend.unwrap_or_default() {
821821
sc_network::config::NetworkBackendType::Libp2p => {
822822
let task_manager = new_full_base::<sc_network::NetworkWorker<_, _>>(
823823
config,

substrate/client/cli/src/params/network_params.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,10 @@ pub struct NetworkParams {
178178
long,
179179
value_enum,
180180
value_name = "NETWORK_BACKEND",
181-
default_value_t = NetworkBackendType::Libp2p,
182181
ignore_case = true,
183182
verbatim_doc_comment
184183
)]
185-
pub network_backend: NetworkBackendType,
184+
pub network_backend: Option<NetworkBackendType>,
186185
}
187186

188187
impl NetworkParams {
@@ -278,7 +277,7 @@ impl NetworkParams {
278277
yamux_window_size: None,
279278
ipfs_server: self.ipfs_server,
280279
sync_mode: self.sync.into(),
281-
network_backend: self.network_backend.into(),
280+
network_backend: self.network_backend.map(Into::into),
282281
}
283282
}
284283
}

substrate/client/network/src/config.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ pub struct NetworkConfiguration {
672672
pub yamux_window_size: Option<u32>,
673673

674674
/// Networking backend used for P2P communication.
675-
pub network_backend: NetworkBackendType,
675+
pub network_backend: Option<NetworkBackendType>,
676676
}
677677

678678
impl NetworkConfiguration {
@@ -705,7 +705,7 @@ impl NetworkConfiguration {
705705
.expect("value is a constant; constant is non-zero; qed."),
706706
yamux_window_size: None,
707707
ipfs_server: false,
708-
network_backend: NetworkBackendType::Libp2p,
708+
network_backend: None,
709709
}
710710
}
711711

@@ -931,9 +931,10 @@ impl<B: BlockT + 'static, H: ExHashT, N: NetworkBackend<B, H>> FullNetworkConfig
931931
}
932932

933933
/// Network backend type.
934-
#[derive(Debug, Clone)]
934+
#[derive(Debug, Clone, Default, Copy)]
935935
pub enum NetworkBackendType {
936936
/// Use libp2p for P2P networking.
937+
#[default]
937938
Libp2p,
938939

939940
/// Use litep2p for P2P networking.

templates/minimal/node/src/command.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ pub fn run() -> sc_cli::Result<()> {
117117
None => {
118118
let runner = cli.create_runner(&cli.run)?;
119119
runner.run_node_until_exit(|config| async move {
120-
match config.network.network_backend {
120+
match config.network.network_backend.unwrap_or_default() {
121121
sc_network::config::NetworkBackendType::Libp2p =>
122122
service::new_full::<sc_network::NetworkWorker<_, _>>(config, cli.consensus)
123123
.map_err(sc_cli::Error::Service),

templates/solochain/node/src/command.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ pub fn run() -> sc_cli::Result<()> {
178178
None => {
179179
let runner = cli.create_runner(&cli.run)?;
180180
runner.run_node_until_exit(|config| async move {
181-
match config.network.network_backend {
181+
match config.network.network_backend.unwrap_or_default() {
182182
sc_network::config::NetworkBackendType::Libp2p => service::new_full::<
183183
sc_network::NetworkWorker<
184184
solochain_template_runtime::opaque::Block,

0 commit comments

Comments
 (0)