Correct protocol name handling

This commit is contained in:
Luke Parker
2022-11-08 02:14:49 -05:00
parent 5dab3352f2
commit 16a2c9a2dc
3 changed files with 16 additions and 17 deletions

View File

@@ -26,7 +26,7 @@ use sc_consensus::import_queue::IncomingBlock;
use sc_service::ImportQueue;
use sc_client_api::{BlockBackend, Finalizer};
use sc_network::NetworkBlock;
use sc_network::{ProtocolName, NetworkBlock};
use sc_network_gossip::GossipEngine;
use substrate_prometheus_endpoint::Registry;
@@ -37,7 +37,7 @@ use tendermint_machine::{
};
use crate::{
CONSENSUS_ID, PROTOCOL_NAME, TendermintValidator,
CONSENSUS_ID, TendermintValidator,
validators::{TendermintSigner, TendermintValidators},
tendermint::TendermintImport,
};
@@ -142,6 +142,7 @@ impl<T: TendermintValidator> TendermintAuthority<T> {
/// as it will not return until the P2P stack shuts down.
pub async fn authority(
mut self,
protocol: ProtocolName,
keys: Arc<dyn CryptoStore>,
providers: T::CIDP,
env: T::Environment,
@@ -158,7 +159,6 @@ impl<T: TendermintValidator> TendermintAuthority<T> {
// Create the gossip network
let mut gossip = GossipEngine::new(
network.clone(),
PROTOCOL_NAME,
protocol,
Arc::new(TendermintGossip::new(number.clone(), self.import.validators.clone())),
registry,

View File

@@ -35,7 +35,7 @@ pub(crate) const KEY_TYPE_ID: KeyTypeId = KeyTypeId(CONSENSUS_ID);
const PROTOCOL_NAME: &str = "/tendermint/1";
fn protocol_name<Hash: AsRef<[u8]>>(genesis: Hash, fork: Option<&str>) -> ProtocolName {
pub fn protocol_name<Hash: AsRef<[u8]>>(genesis: Hash, fork: Option<&str>) -> ProtocolName {
let mut name = format!("/{}", hex::encode(genesis.as_ref()));
if let Some(fork) = fork {
name += &format!("/{}", fork);
@@ -44,9 +44,9 @@ fn protocol_name<Hash: AsRef<[u8]>>(genesis: Hash, fork: Option<&str>) -> Protoc
name.into()
}
pub fn set_config<Hash: AsRef<[u8]>>(genesis: Hash, fork: Option<&str>) -> NonDefaultSetConfig {
pub fn set_config(protocol: ProtocolName) -> NonDefaultSetConfig {
// TODO: 1 MiB Block Size + 1 KiB
let mut cfg = NonDefaultSetConfig::new(protocol_name(genesis, fork), (1024 * 1024) + 1024);
let mut cfg = NonDefaultSetConfig::new(protocol, (1024 * 1024) + 1024);
cfg.allow_non_reserved(25, 25);
cfg
}