mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 12:19:24 +00:00
Add bootnode code prior used in testnet-internal (#554)
* Add bootnode code prior used in testnet-internal Also performs the devnet/testnet differentation done since the testnet branch. * Fixes * fmt
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
use core::marker::PhantomData;
|
||||
use std::collections::HashSet;
|
||||
|
||||
use sp_core::Pair as PairTrait;
|
||||
use sp_core::{Decode, Pair as PairTrait, sr25519::Public};
|
||||
|
||||
use sc_service::ChainType;
|
||||
|
||||
@@ -23,7 +24,7 @@ fn wasm_binary() -> Vec<u8> {
|
||||
WASM_BINARY.ok_or("compiled in wasm not available").unwrap().to_vec()
|
||||
}
|
||||
|
||||
fn testnet_genesis(
|
||||
fn devnet_genesis(
|
||||
wasm_binary: &[u8],
|
||||
validators: &[&'static str],
|
||||
endowed_accounts: Vec<PublicKey>,
|
||||
@@ -72,6 +73,57 @@ fn testnet_genesis(
|
||||
}
|
||||
}
|
||||
|
||||
fn testnet_genesis(wasm_binary: &[u8], validators: Vec<&'static str>) -> RuntimeGenesisConfig {
|
||||
let validators = validators
|
||||
.into_iter()
|
||||
.map(|validator| Public::decode(&mut hex::decode(validator).unwrap().as_slice()).unwrap())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
assert_eq!(validators.iter().collect::<HashSet<_>>().len(), validators.len());
|
||||
|
||||
RuntimeGenesisConfig {
|
||||
system: SystemConfig { code: wasm_binary.to_vec(), _config: PhantomData },
|
||||
|
||||
transaction_payment: Default::default(),
|
||||
|
||||
coins: CoinsConfig {
|
||||
accounts: validators
|
||||
.iter()
|
||||
.map(|a| (*a, Balance { coin: Coin::Serai, amount: Amount(5_000_000 * 10_u64.pow(8)) }))
|
||||
.collect(),
|
||||
_ignore: Default::default(),
|
||||
},
|
||||
|
||||
dex: DexConfig {
|
||||
pools: vec![Coin::Bitcoin, Coin::Ether, Coin::Dai, Coin::Monero],
|
||||
_ignore: Default::default(),
|
||||
},
|
||||
|
||||
validator_sets: ValidatorSetsConfig {
|
||||
networks: serai_runtime::primitives::NETWORKS
|
||||
.iter()
|
||||
.map(|network| match network {
|
||||
NetworkId::Serai => (NetworkId::Serai, Amount(50_000 * 10_u64.pow(8))),
|
||||
NetworkId::Bitcoin => (NetworkId::Bitcoin, Amount(1_000_000 * 10_u64.pow(8))),
|
||||
NetworkId::Ethereum => (NetworkId::Ethereum, Amount(1_000_000 * 10_u64.pow(8))),
|
||||
NetworkId::Monero => (NetworkId::Monero, Amount(100_000 * 10_u64.pow(8))),
|
||||
})
|
||||
.collect(),
|
||||
participants: validators.clone(),
|
||||
},
|
||||
signals: SignalsConfig::default(),
|
||||
babe: BabeConfig {
|
||||
authorities: validators.iter().map(|validator| ((*validator).into(), 1)).collect(),
|
||||
epoch_config: Some(BABE_GENESIS_EPOCH_CONFIG),
|
||||
_config: PhantomData,
|
||||
},
|
||||
grandpa: GrandpaConfig {
|
||||
authorities: validators.into_iter().map(|validator| (validator.into(), 1)).collect(),
|
||||
_config: PhantomData,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn development_config() -> ChainSpec {
|
||||
let wasm_binary = wasm_binary();
|
||||
|
||||
@@ -82,7 +134,7 @@ pub fn development_config() -> ChainSpec {
|
||||
"devnet",
|
||||
ChainType::Development,
|
||||
move || {
|
||||
testnet_genesis(
|
||||
devnet_genesis(
|
||||
&wasm_binary,
|
||||
&["Alice"],
|
||||
vec![
|
||||
@@ -100,7 +152,7 @@ pub fn development_config() -> ChainSpec {
|
||||
// Telemetry
|
||||
None,
|
||||
// Protocol ID
|
||||
Some("serai"),
|
||||
Some("serai-devnet"),
|
||||
// Fork ID
|
||||
None,
|
||||
// Properties
|
||||
@@ -110,7 +162,7 @@ pub fn development_config() -> ChainSpec {
|
||||
)
|
||||
}
|
||||
|
||||
pub fn testnet_config() -> ChainSpec {
|
||||
pub fn local_config() -> ChainSpec {
|
||||
let wasm_binary = wasm_binary();
|
||||
|
||||
ChainSpec::from_genesis(
|
||||
@@ -120,7 +172,7 @@ pub fn testnet_config() -> ChainSpec {
|
||||
"local",
|
||||
ChainType::Local,
|
||||
move || {
|
||||
testnet_genesis(
|
||||
devnet_genesis(
|
||||
&wasm_binary,
|
||||
&["Alice", "Bob", "Charlie", "Dave"],
|
||||
vec![
|
||||
@@ -138,7 +190,7 @@ pub fn testnet_config() -> ChainSpec {
|
||||
// Telemetry
|
||||
None,
|
||||
// Protocol ID
|
||||
Some("serai"),
|
||||
Some("serai-local"),
|
||||
// Fork ID
|
||||
None,
|
||||
// Properties
|
||||
@@ -147,3 +199,39 @@ pub fn testnet_config() -> ChainSpec {
|
||||
None,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn testnet_config() -> ChainSpec {
|
||||
let wasm_binary = wasm_binary();
|
||||
|
||||
ChainSpec::from_genesis(
|
||||
// Name
|
||||
"Test Network 2",
|
||||
// ID
|
||||
"testnet-2",
|
||||
ChainType::Live,
|
||||
move || {
|
||||
let _ = testnet_genesis(&wasm_binary, vec![]);
|
||||
todo!()
|
||||
},
|
||||
// Bootnodes
|
||||
vec![],
|
||||
// Telemetry
|
||||
None,
|
||||
// Protocol ID
|
||||
Some("serai-testnet-2"),
|
||||
// Fork ID
|
||||
None,
|
||||
// Properties
|
||||
None,
|
||||
// Extensions
|
||||
None,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn bootnode_multiaddrs(id: &str) -> Vec<libp2p::Multiaddr> {
|
||||
match id {
|
||||
"devnet" | "local" => vec![],
|
||||
"testnet-2" => todo!(),
|
||||
_ => panic!("unrecognized network ID"),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user