mirror of
https://github.com/serai-dex/serai.git
synced 2025-04-22 05:58:13 +00:00
Localize the LibP2P protocol to the blockchain
Follows convention by doing so. Theoretically enables running multiple blockchains over a single LibP2P connection.
This commit is contained in:
parent
bd08cd3c9b
commit
2315b3c79b
4 changed files with 30 additions and 10 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -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",
|
||||
|
|
|
@ -168,13 +168,10 @@ pub async fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceE
|
|||
) = new_partial(&config)?;
|
||||
|
||||
if config.role.is_authority() {
|
||||
// Block size + 1 KiB
|
||||
let mut cfg = sc_service::config::NonDefaultSetConfig::new(
|
||||
sc_tendermint::PROTOCOL_NAME.into(),
|
||||
(1024 * 1024) + 1024,
|
||||
);
|
||||
cfg.allow_non_reserved(25, 25);
|
||||
config.network.extra_sets.push(cfg);
|
||||
config.network.extra_sets.push(sc_tendermint::set_config(
|
||||
client.block_hash(0).unwrap().unwrap(),
|
||||
config.chain_spec.fork_id(),
|
||||
));
|
||||
}
|
||||
|
||||
let (network, system_rpc_tx, tx_handler_controller, network_starter) =
|
||||
|
|
|
@ -15,6 +15,7 @@ rustdoc-args = ["--cfg", "docsrs"]
|
|||
[dependencies]
|
||||
async-trait = "0.1"
|
||||
|
||||
hex = "0.4"
|
||||
log = "0.4"
|
||||
|
||||
futures = "0.3"
|
||||
|
@ -34,6 +35,7 @@ sp-tendermint = { path = "../primitives" }
|
|||
|
||||
sc-transaction-pool = { git = "https://github.com/serai-dex/substrate" }
|
||||
sc-executor = { git = "https://github.com/serai-dex/substrate" }
|
||||
sc-network-common = { git = "https://github.com/serai-dex/substrate" }
|
||||
sc-network = { git = "https://github.com/serai-dex/substrate" }
|
||||
sc-network-gossip = { git = "https://github.com/serai-dex/substrate" }
|
||||
sc-service = { git = "https://github.com/serai-dex/substrate" }
|
||||
|
|
|
@ -10,7 +10,9 @@ use sp_consensus::{Error, Environment};
|
|||
use sc_client_api::{BlockBackend, Backend, Finalizer};
|
||||
use sc_block_builder::BlockBuilderApi;
|
||||
use sc_consensus::{BlockImport, BasicQueue};
|
||||
use sc_network::NetworkBlock;
|
||||
|
||||
use sc_network_common::config::NonDefaultSetConfig;
|
||||
use sc_network::{ProtocolName, NetworkBlock};
|
||||
use sc_network_gossip::Network;
|
||||
|
||||
use sp_tendermint::TendermintApi;
|
||||
|
@ -29,8 +31,25 @@ pub(crate) mod authority;
|
|||
pub use authority::TendermintAuthority;
|
||||
|
||||
pub const CONSENSUS_ID: [u8; 4] = *b"tend";
|
||||
pub const KEY_TYPE_ID: KeyTypeId = KeyTypeId(CONSENSUS_ID);
|
||||
pub const PROTOCOL_NAME: &str = "/serai/tendermint/1";
|
||||
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 {
|
||||
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<Hash: AsRef<[u8]>>(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 {
|
||||
|
|
Loading…
Reference in a new issue