mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 20:29:23 +00:00
Correct protocol name handling
This commit is contained in:
@@ -21,12 +21,12 @@ pub(crate) use sc_tendermint::{
|
|||||||
use serai_runtime::{self, MILLISECS_PER_BLOCK, opaque::Block, RuntimeApi};
|
use serai_runtime::{self, MILLISECS_PER_BLOCK, opaque::Block, RuntimeApi};
|
||||||
|
|
||||||
type FullBackend = sc_service::TFullBackend<Block>;
|
type FullBackend = sc_service::TFullBackend<Block>;
|
||||||
type FullSelectChain = TendermintSelectChain<Block, FullBackend>;
|
pub type FullClient = TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<ExecutorDispatch>>;
|
||||||
|
|
||||||
type PartialComponents = sc_service::PartialComponents<
|
type PartialComponents = sc_service::PartialComponents<
|
||||||
FullClient,
|
FullClient,
|
||||||
FullBackend,
|
FullBackend,
|
||||||
FullSelectChain,
|
TendermintSelectChain<Block, FullBackend>,
|
||||||
sc_consensus::DefaultImportQueue<Block, FullClient>,
|
sc_consensus::DefaultImportQueue<Block, FullClient>,
|
||||||
sc_transaction_pool::FullPool<Block, FullClient>,
|
sc_transaction_pool::FullPool<Block, FullClient>,
|
||||||
Option<Telemetry>,
|
Option<Telemetry>,
|
||||||
@@ -48,8 +48,6 @@ impl NativeExecutionDispatch for ExecutorDispatch {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type FullClient = TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<ExecutorDispatch>>;
|
|
||||||
|
|
||||||
pub struct Cidp;
|
pub struct Cidp;
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
impl CreateInherentDataProviders<Block, ()> for Cidp {
|
impl CreateInherentDataProviders<Block, ()> for Cidp {
|
||||||
@@ -169,11 +167,13 @@ pub async fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceE
|
|||||||
},
|
},
|
||||||
) = new_partial(&config)?;
|
) = new_partial(&config)?;
|
||||||
|
|
||||||
if config.role.is_authority() {
|
let is_authority = config.role.is_authority();
|
||||||
config.network.extra_sets.push(sc_tendermint::set_config(
|
let tendermint_protocol = sc_tendermint::protocol_name(
|
||||||
client.block_hash(0).unwrap().unwrap(),
|
client.block_hash(0).unwrap().unwrap(),
|
||||||
config.chain_spec.fork_id(),
|
config.chain_spec.fork_id(),
|
||||||
));
|
);
|
||||||
|
if is_authority {
|
||||||
|
config.network.extra_sets.push(sc_tendermint::set_config(tendermint_protocol.clone()));
|
||||||
}
|
}
|
||||||
|
|
||||||
let (network, system_rpc_tx, tx_handler_controller, network_starter) =
|
let (network, system_rpc_tx, tx_handler_controller, network_starter) =
|
||||||
@@ -210,8 +210,6 @@ pub async fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceE
|
|||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
let is_authority = config.role.is_authority();
|
|
||||||
|
|
||||||
let registry = config.prometheus_registry().cloned();
|
let registry = config.prometheus_registry().cloned();
|
||||||
sc_service::spawn_tasks(sc_service::SpawnTasksParams {
|
sc_service::spawn_tasks(sc_service::SpawnTasksParams {
|
||||||
network: network.clone(),
|
network: network.clone(),
|
||||||
@@ -232,6 +230,7 @@ pub async fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceE
|
|||||||
"tendermint",
|
"tendermint",
|
||||||
None,
|
None,
|
||||||
TendermintAuthority::new(authority).authority(
|
TendermintAuthority::new(authority).authority(
|
||||||
|
tendermint_protocol,
|
||||||
keystore_container.keystore(),
|
keystore_container.keystore(),
|
||||||
Cidp,
|
Cidp,
|
||||||
sc_basic_authorship::ProposerFactory::new(
|
sc_basic_authorship::ProposerFactory::new(
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ use sc_consensus::import_queue::IncomingBlock;
|
|||||||
|
|
||||||
use sc_service::ImportQueue;
|
use sc_service::ImportQueue;
|
||||||
use sc_client_api::{BlockBackend, Finalizer};
|
use sc_client_api::{BlockBackend, Finalizer};
|
||||||
use sc_network::NetworkBlock;
|
use sc_network::{ProtocolName, NetworkBlock};
|
||||||
use sc_network_gossip::GossipEngine;
|
use sc_network_gossip::GossipEngine;
|
||||||
|
|
||||||
use substrate_prometheus_endpoint::Registry;
|
use substrate_prometheus_endpoint::Registry;
|
||||||
@@ -37,7 +37,7 @@ use tendermint_machine::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
CONSENSUS_ID, PROTOCOL_NAME, TendermintValidator,
|
CONSENSUS_ID, TendermintValidator,
|
||||||
validators::{TendermintSigner, TendermintValidators},
|
validators::{TendermintSigner, TendermintValidators},
|
||||||
tendermint::TendermintImport,
|
tendermint::TendermintImport,
|
||||||
};
|
};
|
||||||
@@ -142,6 +142,7 @@ impl<T: TendermintValidator> TendermintAuthority<T> {
|
|||||||
/// as it will not return until the P2P stack shuts down.
|
/// as it will not return until the P2P stack shuts down.
|
||||||
pub async fn authority(
|
pub async fn authority(
|
||||||
mut self,
|
mut self,
|
||||||
|
protocol: ProtocolName,
|
||||||
keys: Arc<dyn CryptoStore>,
|
keys: Arc<dyn CryptoStore>,
|
||||||
providers: T::CIDP,
|
providers: T::CIDP,
|
||||||
env: T::Environment,
|
env: T::Environment,
|
||||||
@@ -158,7 +159,6 @@ impl<T: TendermintValidator> TendermintAuthority<T> {
|
|||||||
// Create the gossip network
|
// Create the gossip network
|
||||||
let mut gossip = GossipEngine::new(
|
let mut gossip = GossipEngine::new(
|
||||||
network.clone(),
|
network.clone(),
|
||||||
PROTOCOL_NAME,
|
|
||||||
protocol,
|
protocol,
|
||||||
Arc::new(TendermintGossip::new(number.clone(), self.import.validators.clone())),
|
Arc::new(TendermintGossip::new(number.clone(), self.import.validators.clone())),
|
||||||
registry,
|
registry,
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ pub(crate) const KEY_TYPE_ID: KeyTypeId = KeyTypeId(CONSENSUS_ID);
|
|||||||
|
|
||||||
const PROTOCOL_NAME: &str = "/tendermint/1";
|
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()));
|
let mut name = format!("/{}", hex::encode(genesis.as_ref()));
|
||||||
if let Some(fork) = fork {
|
if let Some(fork) = fork {
|
||||||
name += &format!("/{}", fork);
|
name += &format!("/{}", fork);
|
||||||
@@ -44,9 +44,9 @@ fn protocol_name<Hash: AsRef<[u8]>>(genesis: Hash, fork: Option<&str>) -> Protoc
|
|||||||
name.into()
|
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
|
// 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.allow_non_reserved(25, 25);
|
||||||
cfg
|
cfg
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user