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-system",
"jsonrpsee",
"log",
"pallet-tendermint",
"pallet-transaction-payment",
"pallet-transaction-payment-rpc",
@ -7616,7 +7617,9 @@ dependencies = [
"sp-core",
"sp-inherents",
"sp-keyring",
"sp-keystore",
"sp-runtime",
"sp-tendermint",
"sp-timestamp",
"substrate-build-script-utils",
"substrate-frame-rpc-system",

View file

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

View file

@ -26,12 +26,11 @@ RUN --mount=type=cache,target=/usr/local/cargo/git \
--mount=type=cache,target=/serai/target/release/build \
--mount=type=cache,target=/serai/target/release/deps \
--mount=type=cache,target=/serai/target/release/.fingerprint \
--mount=type=cache,target=/serai/target/release/incremental \
--mount=type=cache,target=/serai/target/release/incremental \
--mount=type=cache,target=/serai/target/release/wbuild \
--mount=type=cache,target=/serai/target/release/lib* \
cargo build --release
# Prepare Image
FROM ubuntu:latest as image
LABEL description="STAGE 2: Copy and Run"

View file

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

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();

View file

@ -28,8 +28,8 @@ pub use block_import::TendermintSelectChain;
pub(crate) mod authority;
pub use authority::TendermintAuthority;
const CONSENSUS_ID: [u8; 4] = *b"tend";
const KEY_TYPE_ID: KeyTypeId = KeyTypeId(CONSENSUS_ID);
pub const CONSENSUS_ID: [u8; 4] = *b"tend";
pub const KEY_TYPE_ID: KeyTypeId = KeyTypeId(CONSENSUS_ID);
/// Trait consolidating all generics required by sc_tendermint for processing.
pub trait TendermintClient: Send + Sync + 'static {

View file

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