From 2315b3c79b4a34ffce110545c838d267e101dd66 Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Thu, 3 Nov 2022 00:20:50 -0400 Subject: [PATCH] Localize the LibP2P protocol to the blockchain Follows convention by doing so. Theoretically enables running multiple blockchains over a single LibP2P connection. --- Cargo.lock | 2 ++ substrate/node/src/service.rs | 11 ++++------- substrate/tendermint/client/Cargo.toml | 2 ++ substrate/tendermint/client/src/lib.rs | 25 ++++++++++++++++++++++--- 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d5adcdbf..35225434 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7327,12 +7327,14 @@ version = "0.1.0" dependencies = [ "async-trait", "futures", + "hex", "log", "sc-block-builder", "sc-client-api", "sc-consensus", "sc-executor", "sc-network", + "sc-network-common", "sc-network-gossip", "sc-service", "sc-transaction-pool", diff --git a/substrate/node/src/service.rs b/substrate/node/src/service.rs index c3d570db..7d768fab 100644 --- a/substrate/node/src/service.rs +++ b/substrate/node/src/service.rs @@ -168,13 +168,10 @@ pub async fn new_full(mut config: Configuration) -> Result>(genesis: Hash, fork: Option<&str>) -> ProtocolName { + let mut name = format!("/{}", hex::encode(genesis.as_ref())); + if let Some(fork) = fork { + name += &format!("/{}", fork); + } + name += PROTOCOL_NAME; + name.into() +} + +pub fn set_config>(genesis: Hash, fork: Option<&str>) -> NonDefaultSetConfig { + // TODO: 1 MiB Block Size + 1 KiB + let mut cfg = NonDefaultSetConfig::new(protocol_name(genesis, fork), (1024 * 1024) + 1024); + cfg.allow_non_reserved(25, 25); + cfg +} /// Trait consolidating all generics required by sc_tendermint for processing. pub trait TendermintClient: Send + Sync + 'static {