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

Remove block_announce_config from Params #13905

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
5 changes: 3 additions & 2 deletions client/network/test/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl TestNetworkBuilder {
|v| v.clone(),
);

let network_config = self.config.unwrap_or(config::NetworkConfiguration {
let mut network_config = self.config.unwrap_or(config::NetworkConfiguration {
extra_sets: vec![config::NonDefaultSetConfig {
notifications_protocol: PROTOCOL_NAME.into(),
fallback_names: Vec::new(),
Expand Down Expand Up @@ -196,14 +196,15 @@ impl TestNetworkBuilder {
rx,
)
.unwrap();
// This protocol MUST BE the first notification protocol given to `Notifications`
network_config.extra_sets.insert(0, block_announce_config);
let mut link = self.link.unwrap_or(Box::new(chain_sync_service.clone()));
let genesis_hash =
client.hash(Zero::zero()).ok().flatten().expect("Genesis block exists; qed");
let worker = NetworkWorker::<
substrate_test_runtime_client::runtime::Block,
substrate_test_runtime_client::runtime::Hash,
>::new(config::Params::<substrate_test_runtime_client::runtime::Block> {
block_announce_config,
role: config::Role::Full,
executor: Box::new(|f| {
tokio::spawn(f);
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