Skip to content

Commit

Permalink
remove block_announce_config from Params
Browse files Browse the repository at this point in the history
and treat it instead as any other `Notifications` protocol

Refs #13542
  • Loading branch information
melekes committed Apr 13, 2023
1 parent a44af4b commit 48d62f8
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 27 deletions.
3 changes: 0 additions & 3 deletions client/network/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -722,9 +722,6 @@ pub struct Params<Block: BlockT> {
/// Registry for recording prometheus metrics to.
pub metrics_registry: Option<Registry>,

/// Block announce protocol configuration
pub block_announce_config: NonDefaultSetConfig,

/// TX channel for direct communication with `SyncingEngine` and `Protocol`.
pub tx: TracingUnboundedSender<crate::event::SyncEvent<Block>>,

Expand Down
21 changes: 6 additions & 15 deletions client/network/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ use sp_runtime::traits::Block as BlockT;
use std::{
collections::{HashMap, HashSet, VecDeque},
future::Future,
iter,
pin::Pin,
task::Poll,
};
Expand Down Expand Up @@ -104,7 +103,6 @@ impl<B: BlockT> Protocol<B> {
pub fn new(
roles: Roles,
network_config: &config::NetworkConfiguration,
block_announces_protocol: config::NonDefaultSetConfig,
tx: TracingUnboundedSender<crate::event::SyncEvent<B>>,
) -> error::Result<(Self, sc_peerset::PeersetHandle, Vec<(PeerId, Multiaddr)>)> {
let mut known_addresses = Vec::new();
Expand Down Expand Up @@ -162,30 +160,23 @@ impl<B: BlockT> Protocol<B> {
let behaviour = {
Notifications::new(
peerset,
// NOTE: Block announcement protocol is still very much hardcoded into `Protocol`.
// This protocol must be the first notification protocol given to
// `Notifications`
iter::once(notifications::ProtocolConfig {
name: block_announces_protocol.notifications_protocol.clone(),
fallback_names: block_announces_protocol.fallback_names.clone(),
handshake: block_announces_protocol.handshake.as_ref().unwrap().to_vec(),
max_notification_size: block_announces_protocol.max_notification_size,
})
.chain(network_config.extra_sets.iter().map(|s| notifications::ProtocolConfig {
network_config.extra_sets.iter().map(|s| notifications::ProtocolConfig {
name: s.notifications_protocol.clone(),
fallback_names: s.fallback_names.clone(),
handshake: s.handshake.as_ref().map_or(roles.encode(), |h| (*h).to_vec()),
max_notification_size: s.max_notification_size,
})),
}),
)
};

let protocol = Self {
pending_messages: VecDeque::new(),
peerset_handle: peerset_handle.clone(),
behaviour,
notification_protocols: iter::once(block_announces_protocol.notifications_protocol)
.chain(network_config.extra_sets.iter().map(|s| s.notifications_protocol.clone()))
notification_protocols: network_config
.extra_sets
.iter()
.map(|s| s.notifications_protocol.clone())
.collect(),
bad_handshake_substreams: Default::default(),
peers: HashMap::new(),
Expand Down
8 changes: 2 additions & 6 deletions client/network/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,8 @@ where
local_peer_id.to_base58(),
);

let (protocol, peerset_handle, mut known_addresses) = Protocol::new(
From::from(&params.role),
&params.network_config,
params.block_announce_config,
params.tx,
)?;
let (protocol, peerset_handle, mut known_addresses) =
Protocol::new(From::from(&params.role), &params.network_config, params.tx)?;

// List of multiaddresses that we know in the network.
let mut boot_node_ids = HashSet::new();
Expand Down
4 changes: 3 additions & 1 deletion client/network/test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,9 @@ where
let sync_service_import_queue = Box::new(sync_service.clone());
let sync_service = Arc::new(sync_service.clone());

// This protocol MUST BE the first notification protocol given to `Notifications`
network_config.extra_sets.insert(0, block_announce_config);

let genesis_hash =
client.hash(Zero::zero()).ok().flatten().expect("Genesis block exists; qed");
let network = NetworkWorker::new(sc_network::config::Params {
Expand All @@ -930,7 +933,6 @@ where
protocol_id,
fork_id,
metrics_registry: None,
block_announce_config,
tx,
request_response_protocol_configs: [
block_request_protocol_config,
Expand Down
7 changes: 5 additions & 2 deletions client/service/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,6 @@ where
protocol_id: protocol_id.clone(),
fork_id: config.chain_spec.fork_id().map(ToOwned::to_owned),
metrics_registry: config.prometheus_config.as_ref().map(|config| config.registry.clone()),
block_announce_config,
tx,
request_response_protocol_configs: request_response_protocol_configs
.into_iter()
Expand All @@ -901,6 +900,9 @@ where
.collect::<Vec<_>>(),
};

// This protocol MUST BE the first notification protocol given to `Notifications`
network_params.network_config.extra_sets.insert(0, block_announce_config);

// crate transactions protocol and add it to the list of supported protocols of `network_params`
let transactions_handler_proto = sc_network_transactions::TransactionsHandlerPrototype::new(
protocol_id.clone(),
Expand All @@ -911,10 +913,11 @@ where
.expect("Genesis block exists; qed"),
config.chain_spec.fork_id(),
);

network_params
.network_config
.extra_sets
.insert(0, transactions_handler_proto.set_config());
.insert(1, transactions_handler_proto.set_config());

let has_bootnodes = !network_params.network_config.boot_nodes.is_empty();
let network_mut = sc_network::NetworkWorker::new(network_params)?;
Expand Down

0 comments on commit 48d62f8

Please sign in to comment.