mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 20:29:23 +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:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -7327,12 +7327,14 @@ version = "0.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"futures",
|
"futures",
|
||||||
|
"hex",
|
||||||
"log",
|
"log",
|
||||||
"sc-block-builder",
|
"sc-block-builder",
|
||||||
"sc-client-api",
|
"sc-client-api",
|
||||||
"sc-consensus",
|
"sc-consensus",
|
||||||
"sc-executor",
|
"sc-executor",
|
||||||
"sc-network",
|
"sc-network",
|
||||||
|
"sc-network-common",
|
||||||
"sc-network-gossip",
|
"sc-network-gossip",
|
||||||
"sc-service",
|
"sc-service",
|
||||||
"sc-transaction-pool",
|
"sc-transaction-pool",
|
||||||
|
|||||||
@@ -168,13 +168,10 @@ pub async fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceE
|
|||||||
) = new_partial(&config)?;
|
) = new_partial(&config)?;
|
||||||
|
|
||||||
if config.role.is_authority() {
|
if config.role.is_authority() {
|
||||||
// Block size + 1 KiB
|
config.network.extra_sets.push(sc_tendermint::set_config(
|
||||||
let mut cfg = sc_service::config::NonDefaultSetConfig::new(
|
client.block_hash(0).unwrap().unwrap(),
|
||||||
sc_tendermint::PROTOCOL_NAME.into(),
|
config.chain_spec.fork_id(),
|
||||||
(1024 * 1024) + 1024,
|
));
|
||||||
);
|
|
||||||
cfg.allow_non_reserved(25, 25);
|
|
||||||
config.network.extra_sets.push(cfg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let (network, system_rpc_tx, tx_handler_controller, network_starter) =
|
let (network, system_rpc_tx, tx_handler_controller, network_starter) =
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ rustdoc-args = ["--cfg", "docsrs"]
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
async-trait = "0.1"
|
async-trait = "0.1"
|
||||||
|
|
||||||
|
hex = "0.4"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
|
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
@@ -34,6 +35,7 @@ sp-tendermint = { path = "../primitives" }
|
|||||||
|
|
||||||
sc-transaction-pool = { git = "https://github.com/serai-dex/substrate" }
|
sc-transaction-pool = { git = "https://github.com/serai-dex/substrate" }
|
||||||
sc-executor = { 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 = { git = "https://github.com/serai-dex/substrate" }
|
||||||
sc-network-gossip = { 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" }
|
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_client_api::{BlockBackend, Backend, Finalizer};
|
||||||
use sc_block_builder::BlockBuilderApi;
|
use sc_block_builder::BlockBuilderApi;
|
||||||
use sc_consensus::{BlockImport, BasicQueue};
|
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 sc_network_gossip::Network;
|
||||||
|
|
||||||
use sp_tendermint::TendermintApi;
|
use sp_tendermint::TendermintApi;
|
||||||
@@ -29,8 +31,25 @@ pub(crate) mod authority;
|
|||||||
pub use authority::TendermintAuthority;
|
pub use authority::TendermintAuthority;
|
||||||
|
|
||||||
pub const CONSENSUS_ID: [u8; 4] = *b"tend";
|
pub const CONSENSUS_ID: [u8; 4] = *b"tend";
|
||||||
pub const KEY_TYPE_ID: KeyTypeId = KeyTypeId(CONSENSUS_ID);
|
pub(crate) const KEY_TYPE_ID: KeyTypeId = KeyTypeId(CONSENSUS_ID);
|
||||||
pub const PROTOCOL_NAME: &str = "/serai/tendermint/1";
|
|
||||||
|
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.
|
/// Trait consolidating all generics required by sc_tendermint for processing.
|
||||||
pub trait TendermintClient: Send + Sync + 'static {
|
pub trait TendermintClient: Send + Sync + 'static {
|
||||||
|
|||||||
Reference in New Issue
Block a user