From 6ad30fb5cbfb6fa7876ebaa325ec95c99fda0e9d Mon Sep 17 00:00:00 2001 From: Aaro Altonen Date: Fri, 5 May 2023 14:46:03 +0300 Subject: [PATCH] Companion for paritytech/substrate#14080 --- client/relay-chain-minimal-node/src/lib.rs | 34 +++++++++++-------- .../relay-chain-minimal-node/src/network.rs | 5 +-- client/service/src/lib.rs | 3 ++ parachain-template/node/src/service.rs | 2 ++ polkadot-parachain/src/service.rs | 8 ++++- test/service/src/lib.rs | 6 +++- 6 files changed, 40 insertions(+), 18 deletions(-) diff --git a/client/relay-chain-minimal-node/src/lib.rs b/client/relay-chain-minimal-node/src/lib.rs index 102a8582745..6def072913b 100644 --- a/client/relay-chain-minimal-node/src/lib.rs +++ b/client/relay-chain-minimal-node/src/lib.rs @@ -29,7 +29,7 @@ use polkadot_node_subsystem_util::metrics::prometheus::Registry; use polkadot_primitives::CollatorPair; use sc_authority_discovery::Service as AuthorityDiscoveryService; -use sc_network::{Event, NetworkEventStream, NetworkService}; +use sc_network::{config::FullNetworkConfiguration, Event, NetworkEventStream, NetworkService}; use sc_service::{Configuration, TaskManager}; use sp_runtime::{app_crypto::Pair, traits::Block as BlockT}; @@ -119,11 +119,12 @@ pub async fn build_minimal_relay_chain_node( /// - AvailabilityDistribution #[sc_tracing::logging::prefix_logs_with("Relaychain")] async fn new_minimal_relay_chain( - mut config: Configuration, + config: Configuration, collator_pair: CollatorPair, relay_chain_rpc_client: Arc, ) -> Result { let role = config.role.clone(); + let mut net_config = sc_network::config::FullNetworkConfiguration::new(&config.network); let task_manager = { let registry = config.prometheus_config.as_ref().map(|cfg| &cfg.registry); @@ -141,22 +142,27 @@ async fn new_minimal_relay_chain( let peer_set_protocol_names = PeerSetProtocolNames::new(genesis_hash, config.chain_spec.fork_id()); let is_authority = if role.is_authority() { IsAuthority::Yes } else { IsAuthority::No }; - config - .network - .extra_sets - .extend(peer_sets_info(is_authority, &peer_set_protocol_names)); + + for config in peer_sets_info(is_authority, &peer_set_protocol_names) { + net_config.add_notification_protocol(config); + } let request_protocol_names = ReqProtocolNames::new(genesis_hash, config.chain_spec.fork_id()); let (collation_req_receiver, available_data_req_receiver) = - build_request_response_protocol_receivers(&request_protocol_names, &mut config); + build_request_response_protocol_receivers(&request_protocol_names, &mut net_config); let best_header = relay_chain_rpc_client .chain_get_header(None) .await? .ok_or_else(|| RelayChainError::RpcCallError("Unable to fetch best header".to_string()))?; - let (network, network_starter, sync_oracle) = - build_collator_network(&config, task_manager.spawn_handle(), genesis_hash, best_header) - .map_err(|e| RelayChainError::Application(Box::new(e) as Box<_>))?; + let (network, network_starter, sync_oracle) = build_collator_network( + &config, + net_config, + task_manager.spawn_handle(), + genesis_hash, + best_header, + ) + .map_err(|e| RelayChainError::Application(Box::new(e) as Box<_>))?; let authority_discovery_service = build_authority_discovery_service( &task_manager, @@ -190,18 +196,18 @@ async fn new_minimal_relay_chain( fn build_request_response_protocol_receivers( request_protocol_names: &ReqProtocolNames, - config: &mut Configuration, + config: &mut FullNetworkConfiguration, ) -> ( IncomingRequestReceiver, IncomingRequestReceiver, ) { let (collation_req_receiver, cfg) = IncomingRequest::get_config_receiver(request_protocol_names); - config.network.request_response_protocols.push(cfg); + config.add_request_response_protocol(cfg); let (available_data_req_receiver, cfg) = IncomingRequest::get_config_receiver(request_protocol_names); - config.network.request_response_protocols.push(cfg); + config.add_request_response_protocol(cfg); let cfg = Protocol::ChunkFetchingV1.get_outbound_only_config(request_protocol_names); - config.network.request_response_protocols.push(cfg); + config.add_request_response_protocol(cfg); (collation_req_receiver, available_data_req_receiver) } diff --git a/client/relay-chain-minimal-node/src/network.rs b/client/relay-chain-minimal-node/src/network.rs index 5225fa053cc..022e7e696b7 100644 --- a/client/relay-chain-minimal-node/src/network.rs +++ b/client/relay-chain-minimal-node/src/network.rs @@ -24,6 +24,7 @@ use sc_network::{ NetworkService, }; +use sc_network::config::FullNetworkConfiguration; use sc_network_common::{role::Roles, sync::message::BlockAnnouncesHandshake}; use sc_service::{error::Error, Configuration, NetworkStarter, SpawnTaskHandle}; use sc_utils::mpsc::tracing_unbounded; @@ -33,6 +34,7 @@ use std::{iter, sync::Arc}; /// Build the network service, the network status sinks and an RPC sender. pub(crate) fn build_collator_network( config: &Configuration, + network_config: FullNetworkConfiguration, spawn_handle: SpawnTaskHandle, genesis_hash: Hash, best_header: Header, @@ -61,12 +63,11 @@ pub(crate) fn build_collator_network( }) }, fork_id: None, - network_config: config.network.clone(), + network_config, genesis_hash, protocol_id, metrics_registry: config.prometheus_config.as_ref().map(|config| config.registry.clone()), block_announce_config, - request_response_protocol_configs: Vec::new(), tx, }; diff --git a/client/service/src/lib.rs b/client/service/src/lib.rs index 894db91ba8f..3b20436cd04 100644 --- a/client/service/src/lib.rs +++ b/client/service/src/lib.rs @@ -301,6 +301,7 @@ pub struct BuildNetworkParams< Client::Api: sp_transaction_pool::runtime_api::TaggedTransactionQueue, { pub parachain_config: &'a Configuration, + pub net_config: sc_network::config::FullNetworkConfiguration, pub client: Arc, pub transaction_pool: Arc>, pub para_id: ParaId, @@ -313,6 +314,7 @@ pub struct BuildNetworkParams< pub async fn build_network<'a, Block, Client, RCInterface, IQ>( BuildNetworkParams { parachain_config, + net_config, client, transaction_pool, para_id, @@ -364,6 +366,7 @@ where sc_service::build_network(sc_service::BuildNetworkParams { config: parachain_config, + net_config, client, transaction_pool, spawn_handle, diff --git a/parachain-template/node/src/service.rs b/parachain-template/node/src/service.rs index 4c9e1febf70..fb311a48b48 100644 --- a/parachain-template/node/src/service.rs +++ b/parachain-template/node/src/service.rs @@ -157,6 +157,7 @@ async fn start_node_impl( let params = new_partial(¶chain_config)?; let (block_import, mut telemetry, telemetry_worker_handle) = params.other; + let net_config = sc_network::config::FullNetworkConfiguration::new(¶chain_config.network); let client = params.client.clone(); let backend = params.backend.clone(); @@ -182,6 +183,7 @@ async fn start_node_impl( let (network, system_rpc_tx, tx_handler_controller, start_network, sync_service) = build_network(BuildNetworkParams { parachain_config: ¶chain_config, + net_config, client: client.clone(), transaction_pool: transaction_pool.clone(), para_id, diff --git a/polkadot-parachain/src/service.rs b/polkadot-parachain/src/service.rs index 803d0987844..da0e9d5c97b 100644 --- a/polkadot-parachain/src/service.rs +++ b/polkadot-parachain/src/service.rs @@ -43,7 +43,7 @@ use sc_consensus::{ BlockImportParams, ImportQueue, }; use sc_executor::{HeapAllocStrategy, WasmExecutor, DEFAULT_HEAP_ALLOC_STRATEGY}; -use sc_network::NetworkBlock; +use sc_network::{config::FullNetworkConfiguration, NetworkBlock}; use sc_network_sync::SyncingService; use sc_service::{Configuration, PartialComponents, TFullBackend, TFullClient, TaskManager}; use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker, TelemetryWorkerHandle}; @@ -393,10 +393,12 @@ where let prometheus_registry = parachain_config.prometheus_registry().cloned(); let transaction_pool = params.transaction_pool.clone(); let import_queue_service = params.import_queue.service(); + let net_config = FullNetworkConfiguration::new(¶chain_config.network); let (network, system_rpc_tx, tx_handler_controller, start_network, sync_service) = build_network(BuildNetworkParams { parachain_config: ¶chain_config, + net_config, client: client.clone(), transaction_pool: transaction_pool.clone(), para_id, @@ -582,10 +584,12 @@ where let prometheus_registry = parachain_config.prometheus_registry().cloned(); let transaction_pool = params.transaction_pool.clone(); let import_queue_service = params.import_queue.service(); + let net_config = FullNetworkConfiguration::new(¶chain_config.network); let (network, system_rpc_tx, tx_handler_controller, start_network, sync_service) = build_network(BuildNetworkParams { parachain_config: ¶chain_config, + net_config, client: client.clone(), transaction_pool: transaction_pool.clone(), para_id, @@ -1355,10 +1359,12 @@ where let prometheus_registry = parachain_config.prometheus_registry().cloned(); let transaction_pool = params.transaction_pool.clone(); let import_queue_service = params.import_queue.service(); + let net_config = FullNetworkConfiguration::new(¶chain_config.network); let (network, system_rpc_tx, tx_handler_controller, start_network, sync_service) = build_network(BuildNetworkParams { parachain_config: ¶chain_config, + net_config, client: client.clone(), transaction_pool: transaction_pool.clone(), para_id, diff --git a/test/service/src/lib.rs b/test/service/src/lib.rs index 662f04487aa..b8e3120e877 100644 --- a/test/service/src/lib.rs +++ b/test/service/src/lib.rs @@ -54,7 +54,8 @@ use polkadot_service::ProvideRuntimeApi; use sc_client_api::execution_extensions::ExecutionStrategies; use sc_consensus::ImportQueue; use sc_network::{ - config::TransportConfig, multiaddr, NetworkBlock, NetworkService, NetworkStateInfo, + config::{FullNetworkConfiguration, TransportConfig}, + multiaddr, NetworkBlock, NetworkService, NetworkStateInfo, }; use sc_service::{ config::{ @@ -323,9 +324,12 @@ where .map_err(|e| sc_service::Error::Application(Box::new(e) as Box<_>))?; let import_queue_service = params.import_queue.service(); + let net_config = FullNetworkConfiguration::new(¶chain_config.network); + let (network, system_rpc_tx, tx_handler_controller, start_network, sync_service) = build_network(BuildNetworkParams { parachain_config: ¶chain_config, + net_config, client: client.clone(), transaction_pool: transaction_pool.clone(), para_id,