Companion for paritytech/polkadot#6117 (#1749)

* Companion for paritytech/polkadot#6117

* Fix code

* Fix trait

* update lockfile for {"polkadot", "substrate"}

Co-authored-by: parity-processbot <>
This commit is contained in:
Aaro Altonen
2022-10-10 14:38:54 +03:00
committed by GitHub
parent 445440400e
commit 466725aad1
3 changed files with 328 additions and 258 deletions
Generated
+258 -255
View File
File diff suppressed because it is too large Load Diff
@@ -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.37"
async-trait = "0.1.52"
+69 -3
View File
@@ -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;
@@ -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::<Block>(
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: {
@@ -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,
@@ -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