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

Commit

Permalink
Companion for paritytech/polkadot#6117
Browse files Browse the repository at this point in the history
  • Loading branch information
altonen committed Oct 10, 2022
1 parent 7612d61 commit 2b3d9ae
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 3 deletions.
1 change: 1 addition & 0 deletions client/relay-chain-minimal-node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ cumulus-relay-chain-interface = { path = "../relay-chain-interface" }
cumulus-relay-chain-rpc-interface = { path = "../relay-chain-rpc-interface" }
cumulus-primitives-core = { path = "../../primitives/core" }

array-bytes = "4.1"
lru = "0.8"
tracing = "0.1.25"
async-trait = "0.1.52"
Expand Down
72 changes: 69 additions & 3 deletions client/relay-chain-minimal-node/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,21 @@ use polkadot_service::{BlockT, NumberFor};
use polkadot_node_network_protocol::PeerId;
use sc_network::{NetworkService, SyncState};

use sc_network_common::sync::{Metrics, SyncStatus};
use sc_client_api::HeaderBackend;
use sc_network_common::{
config::{
NonDefaultSetConfig, NonReservedPeerMode, NotificationHandshake, ProtocolId, SetConfig,
},
protocol::role::Roles,
sync::{message::BlockAnnouncesHandshake, Metrics, SyncStatus},
};
use sc_network_light::light_client_requests;
use sc_network_sync::{block_request_handler, state_request_handler};
use sc_service::{error::Error, Configuration, NetworkStarter, SpawnTaskHandle};
use sp_consensus::BlockOrigin;
use sp_runtime::Justifications;

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

use crate::BlockChainRpcClient;

Expand Down Expand Up @@ -59,6 +66,16 @@ pub(crate) fn build_collator_network(
let light_client_request_protocol_config =
light_client_requests::generate_protocol_config(&protocol_id, genesis_hash, None);

let chain_sync = DummyChainSync;
let block_announce_config = chain_sync.get_block_announce_proto_config(
&protocol_id.clone(),
None,
Roles::from(&config.role),
client.info().best_number,
client.info().best_hash,
genesis_hash,
);

let network_params = sc_network::config::Params {
role: config.role.clone(),
executor: {
Expand All @@ -68,12 +85,13 @@ pub(crate) fn build_collator_network(
}))
},
fork_id: None,
chain_sync: Box::new(DummyChainSync),
chain_sync: Box::new(chain_sync),
network_config: config.network.clone(),
chain: client.clone(),
import_queue: Box::new(DummyImportQueue),
protocol_id,
metrics_registry: config.prometheus_config.as_ref().map(|config| config.registry.clone()),
// block_announce_config,
block_request_protocol_config,
state_request_protocol_config,
warp_sync_protocol_config: None,
Expand Down Expand Up @@ -116,6 +134,54 @@ pub(crate) fn build_collator_network(
/// we provide a noop implementation.
struct DummyChainSync;

impl DummyChainSync {
pub fn get_block_announce_proto_config<B: BlockT>(
&self,
protocol_id: ProtocolId,
fork_id: &Option<String>,
roles: Roles,
best_number: NumberFor<B>,
best_hash: B::Hash,
genesis_hash: B::Hash,
) -> NonDefaultSetConfig {
let block_announces_protocol = {
let genesis_hash = genesis_hash.as_ref();
if let Some(ref fork_id) = fork_id {
format!(
"/{}/{}/block-announces/1",
array_bytes::bytes2hex("", genesis_hash),
fork_id
)
} else {
format!("/{}/block-announces/1", array_bytes::bytes2hex("", genesis_hash))
}
};

NonDefaultSetConfig {
notifications_protocol: block_announces_protocol.into(),
fallback_names: iter::once(
format!("/{}/block-announces/1", protocol_id.as_ref()).into(),
)
.collect(),
max_notification_size: 1024 * 1024,
handshake: Some(NotificationHandshake::new(BlockAnnouncesHandshake::<B>::build(
roles,
best_number,
best_hash,
genesis_hash,
))),
// NOTE: `set_config` will be ignored by `protocol.rs` as the block announcement
// protocol is still hardcoded into the peerset.
set_config: SetConfig {
in_peers: 0,
out_peers: 0,
reserved_nodes: Vec::new(),
non_reserved_mode: NonReservedPeerMode::Deny,
},
}
}
}

impl<B: BlockT> sc_network_common::sync::ChainSync<B> for DummyChainSync {
fn peer_info(&self, _who: &PeerId) -> Option<sc_network_common::sync::PeerInfo<B>> {
None
Expand Down

0 comments on commit 2b3d9ae

Please sign in to comment.