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
No known key found for this signature in database
GPG key ID: F9F1386DB1E119B6
9 changed files with 65 additions and 31 deletions

3
Cargo.lock generated
View file

@ -7589,6 +7589,7 @@ dependencies = [
"frame-benchmarking-cli", "frame-benchmarking-cli",
"frame-system", "frame-system",
"jsonrpsee", "jsonrpsee",
"log",
"pallet-tendermint", "pallet-tendermint",
"pallet-transaction-payment", "pallet-transaction-payment",
"pallet-transaction-payment-rpc", "pallet-transaction-payment-rpc",
@ -7616,7 +7617,9 @@ dependencies = [
"sp-core", "sp-core",
"sp-inherents", "sp-inherents",
"sp-keyring", "sp-keyring",
"sp-keystore",
"sp-runtime", "sp-runtime",
"sp-tendermint",
"sp-timestamp", "sp-timestamp",
"substrate-build-script-utils", "substrate-build-script-utils",
"substrate-frame-rpc-system", "substrate-frame-rpc-system",

View file

@ -25,7 +25,6 @@ volumes:
services: services:
_serai: _serai:
&serai_defaults &serai_defaults
restart: unless-stopped restart: unless-stopped
@ -61,7 +60,7 @@ services:
- cluster-coins-lg - cluster-coins-lg
environment: environment:
CHAIN: dev CHAIN: dev
NAME: Alice NAME: alice
VALIDATOR: true VALIDATOR: true
serai-bob: serai-bob:
@ -75,7 +74,8 @@ services:
- cluster-coins-lg - cluster-coins-lg
environment: environment:
CHAIN: dev CHAIN: dev
NAME: Bob NAME: bob
VALIDATOR: true
serai-charlie: serai-charlie:
<<: *serai_defaults <<: *serai_defaults
@ -88,7 +88,8 @@ services:
- cluster-coins-lg - cluster-coins-lg
environment: environment:
CHAIN: dev CHAIN: dev
NAME: Charlie NAME: charlie
VALIDATOR: true
serai-dave: serai-dave:
<<: *serai_defaults <<: *serai_defaults
@ -122,6 +123,7 @@ services:
environment: environment:
CHAIN: dev CHAIN: dev
NAME: Ferdie NAME: Ferdie
# Processor Services # Processor Services
# Coin Services # Coin Services

View file

@ -31,7 +31,6 @@ RUN --mount=type=cache,target=/usr/local/cargo/git \
--mount=type=cache,target=/serai/target/release/lib* \ --mount=type=cache,target=/serai/target/release/lib* \
cargo build --release cargo build --release
# Prepare Image # Prepare Image
FROM ubuntu:latest as image FROM ubuntu:latest as image
LABEL description="STAGE 2: Copy and Run" LABEL description="STAGE 2: Copy and Run"

View file

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
if [[ -z $VALIDATOR ]]; then if [[ -z $VALIDATOR ]]; then
serai-node --chain $CHAIN --name $NAME serai-node --chain $CHAIN --$NAME
else else
serai-node --chain $CHAIN --name $NAME --validator serai-node --chain $CHAIN --$NAME --validator
fi fi

View file

@ -14,11 +14,14 @@ name = "serai-node"
[dependencies] [dependencies]
async-trait = "0.1" async-trait = "0.1"
log = "0.4"
clap = { version = "4", features = ["derive"] } clap = { version = "4", features = ["derive"] }
jsonrpsee = { version = "0.15", features = ["server"] } jsonrpsee = { version = "0.15", features = ["server"] }
sp-core = { git = "https://github.com/serai-dex/substrate" } sp-core = { git = "https://github.com/serai-dex/substrate" }
sp-application-crypto = { 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-keyring = { git = "https://github.com/serai-dex/substrate" }
sp-inherents = { 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" } 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" } substrate-frame-rpc-system = { git = "https://github.com/serai-dex/substrate" }
pallet-transaction-payment-rpc = { 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 } pallet-tendermint = { path = "../tendermint/pallet", default-features = false }
serai-runtime = { path = "../runtime" } serai-runtime = { path = "../runtime" }
sc_tendermint = { path = "../tendermint/client" } 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 { 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 { GenesisConfig {
system: SystemConfig { code: wasm_binary.to_vec() }, system: SystemConfig { code: wasm_binary.to_vec() },
balances: BalancesConfig { balances: BalancesConfig {
@ -27,7 +31,7 @@ fn testnet_genesis(wasm_binary: &[u8], endowed_accounts: Vec<AccountId>) -> Gene
}, },
transaction_payment: Default::default(), transaction_payment: Default::default(),
session: SessionConfig { 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 std::{boxed::Box, sync::Arc, error::Error};
use sp_keystore::SyncCryptoStore;
use sp_runtime::traits::{Block as BlockTrait}; use sp_runtime::traits::{Block as BlockTrait};
use sp_inherents::CreateInherentDataProviders; use sp_inherents::CreateInherentDataProviders;
use sp_consensus::DisableProofRecording; 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_executor::{NativeVersion, NativeExecutionDispatch, NativeElseWasmExecutor};
use sc_transaction_pool::FullPool; use sc_transaction_pool::FullPool;
@ -219,11 +221,24 @@ pub async fn new_full(config: Configuration) -> Result<TaskManager, ServiceError
})?; })?;
if is_authority { if is_authority {
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( task_manager.spawn_essential_handle().spawn(
"tendermint", "tendermint",
None, None,
TendermintAuthority::new(authority).authority( TendermintAuthority::new(authority).authority(
(0, keystore_container.keystore()), (u16::try_from(i).unwrap(), keystore_container.keystore()),
Cidp, Cidp,
sc_basic_authorship::ProposerFactory::new( sc_basic_authorship::ProposerFactory::new(
task_manager.spawn_handle(), task_manager.spawn_handle(),
@ -236,6 +251,14 @@ pub async fn new_full(config: Configuration) -> Result<TaskManager, ServiceError
None, None,
), ),
); );
spawned = true;
break;
}
}
if !spawned {
log::warn!("authority role yet not a validator");
}
} }
network_starter.start_network(); network_starter.start_network();

View file

@ -28,8 +28,8 @@ pub use block_import::TendermintSelectChain;
pub(crate) mod authority; pub(crate) mod authority;
pub use authority::TendermintAuthority; pub use authority::TendermintAuthority;
const CONSENSUS_ID: [u8; 4] = *b"tend"; pub const CONSENSUS_ID: [u8; 4] = *b"tend";
const KEY_TYPE_ID: KeyTypeId = KeyTypeId(CONSENSUS_ID); pub const KEY_TYPE_ID: KeyTypeId = KeyTypeId(CONSENSUS_ID);
/// 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 {

View file

@ -38,7 +38,6 @@ impl TendermintValidatorsStruct {
let api = client.runtime_api(); let api = client.runtime_api();
let session = api.current_session(&BlockId::Hash(last)).unwrap(); let session = api.current_session(&BlockId::Hash(last)).unwrap();
let validators = api.validators(&BlockId::Hash(last)).unwrap(); let validators = api.validators(&BlockId::Hash(last)).unwrap();
assert_eq!(validators.len(), 1);
Self { Self {
session, session,