Base Kademlia protocol name on genesis hash and fork ID (#12545)

This commit is contained in:
Dmitrii Markin
2022-10-24 14:47:58 +03:00
committed by GitHub
parent a877b0ccec
commit d0dcf008ec
2 changed files with 104 additions and 38 deletions
+8 -2
View File
@@ -76,7 +76,7 @@ use sc_network_common::{
use sc_peerset::PeersetHandle;
use sc_utils::mpsc::{tracing_unbounded, TracingUnboundedReceiver, TracingUnboundedSender};
use sp_blockchain::HeaderBackend;
use sp_runtime::traits::{Block as BlockT, NumberFor};
use sp_runtime::traits::{Block as BlockT, NumberFor, Zero};
use std::{
cmp,
collections::{HashMap, HashSet},
@@ -282,7 +282,13 @@ where
config.discovery_limit(
u64::from(params.network_config.default_peers_set.out_peers) + 15,
);
config.with_kademlia(params.protocol_id.clone());
let genesis_hash = params
.chain
.hash(Zero::zero())
.ok()
.flatten()
.expect("Genesis block exists; qed");
config.with_kademlia(genesis_hash, params.fork_id.as_deref(), &params.protocol_id);
config.with_dht_random_walk(params.network_config.enable_dht_random_walk);
config.allow_non_globals_in_dht(params.network_config.allow_non_globals_in_dht);
config.use_kademlia_disjoint_query_paths(