Configure node for a multi-node testnet

This commit is contained in:
Luke Parker
2022-11-01 23:10:36 -04:00
parent 86aaadaea0
commit e3fc3f28fb
9 changed files with 65 additions and 31 deletions

View File

@@ -14,11 +14,14 @@ name = "serai-node"
[dependencies]
async-trait = "0.1"
log = "0.4"
clap = { version = "4", features = ["derive"] }
jsonrpsee = { version = "0.15", features = ["server"] }
sp-core = { git = "https://github.com/serai-dex/substrate" }
sp-application-crypto = { git = "https://github.com/serai-dex/substrate" }
sp-keystore = { git = "https://github.com/serai-dex/substrate" }
sp-keyring = { git = "https://github.com/serai-dex/substrate" }
sp-inherents = { git = "https://github.com/serai-dex/substrate" }
sp-timestamp = { git = "https://github.com/serai-dex/substrate" }
@@ -53,6 +56,7 @@ sc-rpc-api = { git = "https://github.com/serai-dex/substrate" }
substrate-frame-rpc-system = { git = "https://github.com/serai-dex/substrate" }
pallet-transaction-payment-rpc = { git = "https://github.com/serai-dex/substrate" }
sp-tendermint = { path = "../tendermint/primitives" }
pallet-tendermint = { path = "../tendermint/pallet", default-features = false }
serai-runtime = { path = "../runtime" }
sc_tendermint = { path = "../tendermint/client" }

View File

@@ -19,7 +19,11 @@ fn account_id_from_name(name: &'static str) -> AccountId {
}
fn testnet_genesis(wasm_binary: &[u8], endowed_accounts: Vec<AccountId>) -> GenesisConfig {
let alice = account_id_from_name("Alice");
let session_key = |name| {
let key = account_id_from_name(name);
(key, key, SessionKeys { tendermint: Public::from(key) })
};
GenesisConfig {
system: SystemConfig { code: wasm_binary.to_vec() },
balances: BalancesConfig {
@@ -27,7 +31,7 @@ fn testnet_genesis(wasm_binary: &[u8], endowed_accounts: Vec<AccountId>) -> Gene
},
transaction_payment: Default::default(),
session: SessionConfig {
keys: vec![(alice, alice, SessionKeys { tendermint: Public::from(alice) })],
keys: vec![session_key("Alice"), session_key("Bob"), session_key("Charlie")],
},
}
}

View File

@@ -1,9 +1,11 @@
use std::{boxed::Box, sync::Arc, error::Error};
use sp_keystore::SyncCryptoStore;
use sp_runtime::traits::{Block as BlockTrait};
use sp_inherents::CreateInherentDataProviders;
use sp_consensus::DisableProofRecording;
use sp_api::ProvideRuntimeApi;
use sp_api::{BlockId, ProvideRuntimeApi};
use sp_tendermint::TendermintApi;
use sc_executor::{NativeVersion, NativeExecutionDispatch, NativeElseWasmExecutor};
use sc_transaction_pool::FullPool;
@@ -219,23 +221,44 @@ pub async fn new_full(config: Configuration) -> Result<TaskManager, ServiceError
})?;
if is_authority {
task_manager.spawn_essential_handle().spawn(
"tendermint",
None,
TendermintAuthority::new(authority).authority(
(0, keystore_container.keystore()),
Cidp,
sc_basic_authorship::ProposerFactory::new(
task_manager.spawn_handle(),
client,
transaction_pool,
registry.as_ref(),
telemetry.map(|telemtry| telemtry.handle()),
),
network,
None,
),
);
let keys = keystore_container.sync_keystore();
let key = SyncCryptoStore::sr25519_public_keys(&*keys, sc_tendermint::KEY_TYPE_ID)
.get(0)
.cloned()
.unwrap_or_else(|| {
SyncCryptoStore::sr25519_generate_new(&*keys, sc_tendermint::KEY_TYPE_ID, None).unwrap()
});
let mut spawned = false;
let mut validators =
client.runtime_api().validators(&BlockId::Hash(client.chain_info().finalized_hash)).unwrap();
for (i, validator) in validators.drain(..).enumerate() {
if validator == key {
task_manager.spawn_essential_handle().spawn(
"tendermint",
None,
TendermintAuthority::new(authority).authority(
(u16::try_from(i).unwrap(), keystore_container.keystore()),
Cidp,
sc_basic_authorship::ProposerFactory::new(
task_manager.spawn_handle(),
client,
transaction_pool,
registry.as_ref(),
telemetry.map(|telemtry| telemtry.handle()),
),
network,
None,
),
);
spawned = true;
break;
}
}
if !spawned {
log::warn!("authority role yet not a validator");
}
}
network_starter.start_network();