Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 7356c00

Browse files
committed
1 parent d7f767f commit 7356c00

File tree

5 files changed

+38
-24
lines changed

5 files changed

+38
-24
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/relay-chain-minimal-node/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,4 @@ tracing = "0.1.37"
4343
async-trait = "0.1.72"
4444
futures = "0.3.28"
4545
tokio = { version = "1.29.1", features = ["macros"] }
46+
parking_lot = "0.12.0"

client/relay-chain-minimal-node/src/collator_overseer.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
use futures::{select, StreamExt};
1818
use lru::LruCache;
19-
use std::sync::Arc;
19+
use parking_lot::Mutex;
20+
use std::{collections::HashMap, sync::Arc};
2021

2122
use polkadot_availability_recovery::AvailabilityRecoverySubsystem;
2223
use polkadot_collator_protocol::{CollatorProtocolSubsystem, ProtocolSide};
@@ -27,7 +28,7 @@ use polkadot_network_bridge::{
2728
use polkadot_node_collation_generation::CollationGenerationSubsystem;
2829
use polkadot_node_core_runtime_api::RuntimeApiSubsystem;
2930
use polkadot_node_network_protocol::{
30-
peer_set::PeerSetProtocolNames,
31+
peer_set::{PeerSet, PeerSetProtocolNames},
3132
request_response::{
3233
v1::{AvailableDataFetchingRequest, CollationFetchingRequest},
3334
IncomingRequestReceiver, ReqProtocolNames,
@@ -41,7 +42,7 @@ use polkadot_overseer::{
4142
use polkadot_primitives::CollatorPair;
4243

4344
use sc_authority_discovery::Service as AuthorityDiscoveryService;
44-
use sc_network::NetworkStateInfo;
45+
use sc_network::{service::traits::NotificationService, NetworkStateInfo};
4546
use sc_service::TaskManager;
4647
use sp_runtime::traits::Block as BlockT;
4748

@@ -74,6 +75,8 @@ pub(crate) struct CollatorOverseerGenArgs<'a> {
7475
pub req_protocol_names: ReqProtocolNames,
7576
/// Peerset protocols name mapping
7677
pub peer_set_protocol_names: PeerSetProtocolNames,
78+
/// Notification services.
79+
pub notification_services: HashMap<PeerSet, Box<dyn NotificationService>>,
7780
}
7881

7982
fn build_overseer(
@@ -90,13 +93,16 @@ fn build_overseer(
9093
collator_pair,
9194
req_protocol_names,
9295
peer_set_protocol_names,
96+
notification_services,
9397
}: CollatorOverseerGenArgs<'_>,
9498
) -> Result<
9599
(Overseer<SpawnGlue<sc_service::SpawnTaskHandle>, Arc<BlockChainRpcClient>>, OverseerHandle),
96100
RelayChainError,
97101
> {
98102
let spawner = SpawnGlue(spawner);
99103
let network_bridge_metrics: NetworkBridgeMetrics = Metrics::register(registry)?;
104+
let notification_sinks = Arc::new(Mutex::new(HashMap::new()));
105+
100106
let builder = Overseer::builder()
101107
.availability_distribution(DummySubsystem)
102108
.availability_recovery(AvailabilityRecoverySubsystem::with_availability_store_skip(
@@ -126,13 +132,16 @@ fn build_overseer(
126132
sync_oracle,
127133
network_bridge_metrics.clone(),
128134
peer_set_protocol_names.clone(),
135+
notification_services,
136+
notification_sinks.clone(),
129137
))
130138
.network_bridge_tx(NetworkBridgeTxSubsystem::new(
131139
network_service,
132140
authority_discovery_service,
133141
network_bridge_metrics,
134142
req_protocol_names,
135143
peer_set_protocol_names,
144+
notification_sinks.clone(),
136145
))
137146
.provisioner(DummySubsystem)
138147
.runtime_api(RuntimeApiSubsystem::new(

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,23 @@ use cumulus_relay_chain_rpc_interface::{RelayChainRpcInterface, Url};
2121
use network::build_collator_network;
2222
use polkadot_network_bridge::{peer_sets_info, IsAuthority};
2323
use polkadot_node_network_protocol::{
24-
peer_set::PeerSetProtocolNames,
24+
peer_set::{PeerSet, PeerSetProtocolNames},
2525
request_response::{v1, IncomingRequest, IncomingRequestReceiver, Protocol, ReqProtocolNames},
2626
};
2727

2828
use polkadot_node_subsystem_util::metrics::prometheus::Registry;
2929
use polkadot_primitives::CollatorPair;
3030

3131
use sc_authority_discovery::Service as AuthorityDiscoveryService;
32-
use sc_network::{config::FullNetworkConfiguration, Event, NetworkEventStream, NetworkService};
32+
use sc_network::{
33+
config::FullNetworkConfiguration, service::traits::NotificationService, Event,
34+
NetworkEventStream, NetworkService,
35+
};
3336
use sc_service::{Configuration, TaskManager};
3437
use sp_runtime::{app_crypto::Pair, traits::Block as BlockT};
3538

3639
use futures::StreamExt;
37-
use std::sync::Arc;
40+
use std::{collections::HashMap, sync::Arc};
3841

3942
mod collator_overseer;
4043

@@ -143,9 +146,13 @@ async fn new_minimal_relay_chain(
143146
PeerSetProtocolNames::new(genesis_hash, config.chain_spec.fork_id());
144147
let is_authority = if role.is_authority() { IsAuthority::Yes } else { IsAuthority::No };
145148

146-
for config in peer_sets_info(is_authority, &peer_set_protocol_names) {
147-
net_config.add_notification_protocol(config);
148-
}
149+
let notification_services = peer_sets_info(is_authority, &peer_set_protocol_names)
150+
.into_iter()
151+
.map(|(config, (peerset, service))| {
152+
net_config.add_notification_protocol(config);
153+
(peerset, service)
154+
})
155+
.collect::<HashMap<PeerSet, Box<dyn NotificationService>>>();
149156

150157
let request_protocol_names = ReqProtocolNames::new(genesis_hash, config.chain_spec.fork_id());
151158
let (collation_req_receiver, available_data_req_receiver) =
@@ -184,6 +191,7 @@ async fn new_minimal_relay_chain(
184191
collator_pair,
185192
req_protocol_names: request_protocol_names,
186193
peer_set_protocol_names,
194+
notification_services,
187195
};
188196

189197
let overseer_handle =

client/relay-chain-minimal-node/src/network.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,12 @@ use sc_network::{
2222
NonDefaultSetConfig, NonReservedPeerMode, NotificationHandshake, ProtocolId, SetConfig,
2323
},
2424
peer_store::PeerStore,
25-
NetworkService,
25+
NetworkService, NotificationService,
2626
};
2727

2828
use sc_network::config::FullNetworkConfiguration;
2929
use sc_network_common::{role::Roles, sync::message::BlockAnnouncesHandshake};
3030
use sc_service::{error::Error, Configuration, NetworkStarter, SpawnTaskHandle};
31-
use sc_utils::mpsc::tracing_unbounded;
3231

3332
use std::{iter, sync::Arc};
3433

@@ -44,7 +43,7 @@ pub(crate) fn build_collator_network(
4443
Error,
4544
> {
4645
let protocol_id = config.protocol_id();
47-
let block_announce_config = get_block_announce_proto_config::<Block>(
46+
let (block_announce_config, _notification_service) = get_block_announce_proto_config::<Block>(
4847
protocol_id.clone(),
4948
&None,
5049
Roles::from(&config.role),
@@ -64,8 +63,6 @@ pub(crate) fn build_collator_network(
6463
let peer_store_handle = peer_store.handle();
6564
spawn_handle.spawn("peer-store", Some("networking"), peer_store.run());
6665

67-
// RX is not used for anything because syncing is not started for the minimal node
68-
let (tx, _rx) = tracing_unbounded("mpsc_syncing_engine_protocol", 100_000);
6966
let network_params = sc_network::config::Params::<Block> {
7067
role: config.role.clone(),
7168
executor: {
@@ -81,7 +78,6 @@ pub(crate) fn build_collator_network(
8178
protocol_id,
8279
metrics_registry: config.prometheus_config.as_ref().map(|config| config.registry.clone()),
8380
block_announce_config,
84-
tx,
8581
};
8682

8783
let network_worker = sc_network::NetworkWorker::new(network_params)?;
@@ -133,7 +129,7 @@ fn get_block_announce_proto_config<B: BlockT>(
133129
best_number: NumberFor<B>,
134130
best_hash: B::Hash,
135131
genesis_hash: B::Hash,
136-
) -> NonDefaultSetConfig {
132+
) -> (NonDefaultSetConfig, Box<dyn NotificationService>) {
137133
let block_announces_protocol = {
138134
let genesis_hash = genesis_hash.as_ref();
139135
if let Some(ref fork_id) = fork_id {
@@ -143,24 +139,23 @@ fn get_block_announce_proto_config<B: BlockT>(
143139
}
144140
};
145141

146-
NonDefaultSetConfig {
147-
notifications_protocol: block_announces_protocol.into(),
148-
fallback_names: iter::once(format!("/{}/block-announces/1", protocol_id.as_ref()).into())
149-
.collect(),
150-
max_notification_size: 1024 * 1024,
151-
handshake: Some(NotificationHandshake::new(BlockAnnouncesHandshake::<B>::build(
142+
NonDefaultSetConfig::new(
143+
block_announces_protocol.into(),
144+
iter::once(format!("/{}/block-announces/1", protocol_id.as_ref()).into()).collect(),
145+
1024 * 1024,
146+
Some(NotificationHandshake::new(BlockAnnouncesHandshake::<B>::build(
152147
roles,
153148
best_number,
154149
best_hash,
155150
genesis_hash,
156151
))),
157152
// NOTE: `set_config` will be ignored by `protocol.rs` as the block announcement
158153
// protocol is still hardcoded into the peerset.
159-
set_config: SetConfig {
154+
SetConfig {
160155
in_peers: 0,
161156
out_peers: 0,
162157
reserved_nodes: Vec::new(),
163158
non_reserved_mode: NonReservedPeerMode::Deny,
164159
},
165-
}
160+
)
166161
}

0 commit comments

Comments
 (0)