From ea7851eda027d032e9d0d1b73bc7407b39f437fd Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Mon, 15 Jan 2024 15:15:07 -0700 Subject: [PATCH 01/28] Move some chain spec accounts to constants --- Cargo.lock | 5 +++++ crates/shared/Cargo.toml | 1 + crates/shared/src/lib.rs | 21 +++++++++++++++++++++ crates/testing-utils/src/constants.rs | 1 + node/cli/Cargo.toml | 1 + node/cli/src/chain_spec.rs | 27 +++++++++++++-------------- 6 files changed, 42 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index edd3d7042..4e04631a9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2456,6 +2456,7 @@ dependencies = [ "hex-literal", "jsonrpc-core", "jsonrpsee 0.16.2", + "lazy_static", "log", "node-inspect", "node-primitives", @@ -2700,6 +2701,7 @@ name = "entropy-shared" version = "0.1.0" dependencies = [ "frame-support", + "lazy_static", "node-primitives", "parity-scale-codec", "scale-info", @@ -4715,6 +4717,9 @@ name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +dependencies = [ + "spin 0.5.2", +] [[package]] name = "lazycell" diff --git a/crates/shared/Cargo.toml b/crates/shared/Cargo.toml index bf8b254da..45d09a6e9 100644 --- a/crates/shared/Cargo.toml +++ b/crates/shared/Cargo.toml @@ -15,6 +15,7 @@ serde_derive ="1.0.147" sp-std ={ package="sp-std", git="https://github.com/paritytech/substrate", branch="polkadot-v1.0.0", default-features=false } frame-support ={ package="frame-support", git="https://github.com/paritytech/substrate", branch="polkadot-v1.0.0", default-features=false, optional=true } node-primitives={ version="2.0.0", default-features=false, git='https://github.com/paritytech/substrate.git', branch="polkadot-v1.0.0", optional=true } +lazy_static = { version = "1.4.0", features = ["spin_no_std"] } [features] default=["std"] diff --git a/crates/shared/src/lib.rs b/crates/shared/src/lib.rs index b775c69f2..f3c2a8c78 100644 --- a/crates/shared/src/lib.rs +++ b/crates/shared/src/lib.rs @@ -39,3 +39,24 @@ pub const REFRESHES_PER_SESSION: u32 = 10; /// Max instructions per wasm program pub const MAX_INSTRUCTIONS_PER_PROGRAM: u64 = 10_000; + +// TODO: This should only be used for non-production things... +lazy_static::lazy_static! { + + // Used `DEFAULT_ALICE_MNEMONIC` to generate this + // Mnemonic: "alarm mutual concert decrease hurry invest culture survey diagram crash snap click" + pub static ref ALICE_X25519_PUBLIC_KEY: [u8; 32] = [ + 10, 192, 41, 240, 184, 83, 178, 59, 237, 101, 45, 109, 13, 230, 155, 124, 195, 141, 148, + 249, 55, 50, 238, 252, 133, 181, 134, 30, 144, 247, 58, 34, + + ]; + + // Used `DEFAULT_BOB_MNEMONIC` to generate this + // Mnemonic: "where sight patient orphan general short empower hope party hurt month voice" + pub static ref BOB_X25519_PUBLIC_KEY: [u8; 32] = [ + 225, 48, 135, 211, 227, 213, 170, 21, 1, 189, 118, 158, 255, 87, 245, 89, 36, 170, 169, + 181, 68, 201, 210, 178, 237, 247, 101, 80, 153, 136, 102, 10, + + ]; + +} diff --git a/crates/testing-utils/src/constants.rs b/crates/testing-utils/src/constants.rs index 1caaa4558..303567648 100644 --- a/crates/testing-utils/src/constants.rs +++ b/crates/testing-utils/src/constants.rs @@ -41,6 +41,7 @@ lazy_static! { .try_into() .unwrap(), ]; + } /// The following constants are values used for integration testing specific to the diff --git a/node/cli/Cargo.toml b/node/cli/Cargo.toml index 15fedeb9b..0739aae10 100644 --- a/node/cli/Cargo.toml +++ b/node/cli/Cargo.toml @@ -19,6 +19,7 @@ name='entropy' jsonrpc-core ='18.0.0' serde_json ='1.0.0' log ="0.4.17" +lazy_static = { version = "1.4.0", features = ["spin_no_std"] } clap ={ version="4.0.9", features=["derive"], optional=true } codec ={ package="parity-scale-codec", version="3.0.0" } structopt ='0.3.8' diff --git a/node/cli/src/chain_spec.rs b/node/cli/src/chain_spec.rs index d404476f7..61f0b9bf8 100644 --- a/node/cli/src/chain_spec.rs +++ b/node/cli/src/chain_spec.rs @@ -67,6 +67,15 @@ type AccountPublic = ::Signer; const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/"; const DEFAULT_PROTOCOL_ID: &str = "Entropy"; // TODO finalize +lazy_static::lazy_static! { + // TODO: Make this an AccountId32 + pub static ref ALICE_TSS_ACCOUNT_ID: [u8; 32] = + hex!["e0543c102def9f6ef0e8b8ffa31aa259167a9391566929fd718a1ccdaabdb876"]; + + pub static ref BOB_TSS_ACCOUNT_ID: [u8; 32] = + hex!["2a8200850770290c7ea3b50a8ff64c6761c882ff8393dc95fccb5d1475eff17f"]; +} + // TODO: finalize fn entropy_props() -> Properties { json!({"tokenDecimals": 10, "tokenSymbol": "BITS" }).as_object().unwrap().clone() @@ -224,13 +233,8 @@ pub fn testnet_genesis( get_account_id_from_seed::("Alice//stash"), ( // Seed phrase: "alarm mutual concert decrease hurry invest culture survey diagram crash snap click" - hex!["e0543c102def9f6ef0e8b8ffa31aa259167a9391566929fd718a1ccdaabdb876"] - .into(), - [ - 10, 192, 41, 240, 184, 83, 178, 59, 237, 101, 45, 109, 13, 230, 155, - 124, 195, 141, 148, 249, 55, 50, 238, 252, 133, 181, 134, 30, 144, 247, - 58, 34, - ], + (*ALICE_TSS_ACCOUNT_ID).into(), + *entropy_shared::ALICE_X25519_PUBLIC_KEY, "127.0.0.1:3001".as_bytes().to_vec(), ), ), @@ -238,13 +242,8 @@ pub fn testnet_genesis( get_account_id_from_seed::("Bob//stash"), ( // Seed phrase: "where sight patient orphan general short empower hope party hurt month voice" - hex!["2a8200850770290c7ea3b50a8ff64c6761c882ff8393dc95fccb5d1475eff17f"] - .into(), - [ - 225, 48, 135, 211, 227, 213, 170, 21, 1, 189, 118, 158, 255, 87, 245, - 89, 36, 170, 169, 181, 68, 201, 210, 178, 237, 247, 101, 80, 153, 136, - 102, 10, - ], + (*BOB_TSS_ACCOUNT_ID).into(), + *entropy_shared::BOB_X25519_PUBLIC_KEY, "127.0.0.1:3002".as_bytes().to_vec(), ), ), From e787a1b4a40bbc36c9f725e10f97fef8a014f031 Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Mon, 15 Jan 2024 15:41:13 -0700 Subject: [PATCH 02/28] Create new `chain_spec` module --- node/cli/src/chain_spec/dev.rs | 1 + node/cli/src/{chain_spec.rs => chain_spec/mod.rs} | 0 node/cli/src/chain_spec/testnet.rs | 1 + 3 files changed, 2 insertions(+) create mode 100644 node/cli/src/chain_spec/dev.rs rename node/cli/src/{chain_spec.rs => chain_spec/mod.rs} (100%) create mode 100644 node/cli/src/chain_spec/testnet.rs diff --git a/node/cli/src/chain_spec/dev.rs b/node/cli/src/chain_spec/dev.rs new file mode 100644 index 000000000..ca05a6a90 --- /dev/null +++ b/node/cli/src/chain_spec/dev.rs @@ -0,0 +1 @@ +pub struct Bar; diff --git a/node/cli/src/chain_spec.rs b/node/cli/src/chain_spec/mod.rs similarity index 100% rename from node/cli/src/chain_spec.rs rename to node/cli/src/chain_spec/mod.rs diff --git a/node/cli/src/chain_spec/testnet.rs b/node/cli/src/chain_spec/testnet.rs new file mode 100644 index 000000000..4a835673a --- /dev/null +++ b/node/cli/src/chain_spec/testnet.rs @@ -0,0 +1 @@ +pub struct Foo; From 15e2213deb20354bdba72cc930fb2fdc200fa6a5 Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Mon, 15 Jan 2024 16:10:40 -0700 Subject: [PATCH 03/28] Fill out `dev` module --- node/cli/src/admin.rs | 8 -- node/cli/src/chain_spec/dev.rs | 221 ++++++++++++++++++++++++++++++++- node/cli/src/chain_spec/mod.rs | 19 +-- 3 files changed, 223 insertions(+), 25 deletions(-) diff --git a/node/cli/src/admin.rs b/node/cli/src/admin.rs index dfd5cc35f..ef55aab54 100644 --- a/node/cli/src/admin.rs +++ b/node/cli/src/admin.rs @@ -249,14 +249,6 @@ pub fn staging_testnet_config_genesis() -> RuntimeGenesisConfig { testnet_genesis(initial_authorities, vec![], root_key) } -pub fn development_config_genesis() -> RuntimeGenesisConfig { - testnet_genesis( - vec![authority_keys_from_seed("Alice"), authority_keys_from_seed("Bob")], - vec![], - get_account_id_from_seed::("Alice"), - ) -} - pub fn local_devnet_config_genesis() -> RuntimeGenesisConfig { local_devnet_genesis( vec![authority_keys_from_seed("Alice"), authority_keys_from_seed("Bob")], diff --git a/node/cli/src/chain_spec/dev.rs b/node/cli/src/chain_spec/dev.rs index ca05a6a90..01eb25c91 100644 --- a/node/cli/src/chain_spec/dev.rs +++ b/node/cli/src/chain_spec/dev.rs @@ -1 +1,220 @@ -pub struct Bar; +// Copyright (C) 2023 Entropy Cryptography Inc. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +use crate::endowed_accounts::endowed_accounts_dev; +pub use entropy_runtime::RuntimeGenesisConfig; +use entropy_runtime::{ + constants::currency::*, wasm_binary_unwrap, AuthorityDiscoveryConfig, BabeConfig, + BalancesConfig, CouncilConfig, DemocracyConfig, ElectionsConfig, GrandpaConfig, ImOnlineConfig, + IndicesConfig, MaxNominations, RelayerConfig, SessionConfig, StakerStatus, StakingConfig, + StakingExtensionConfig, SudoConfig, SystemConfig, TechnicalCommitteeConfig, +}; +use grandpa_primitives::AuthorityId as GrandpaId; +pub use node_primitives::{AccountId, Balance, Signature}; +use pallet_im_online::sr25519::AuthorityId as ImOnlineId; +use sc_service::ChainType; +use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId; +use sp_consensus_babe::AuthorityId as BabeId; +use sp_core::sr25519; +use sp_runtime::Perbill; + +/// Development config (single validator Alice) +pub fn development_config() -> crate::chain_spec::ChainSpec { + crate::chain_spec::ChainSpec::from_genesis( + "Development", + "dev", + ChainType::Development, + development_config_genesis, + vec![], + None, + None, + None, + None, + Default::default(), + ) +} + +pub fn development_config_genesis() -> RuntimeGenesisConfig { + development_genesis_config( + vec![ + crate::chain_spec::authority_keys_from_seed("Alice"), + crate::chain_spec::authority_keys_from_seed("Bob"), + ], + vec![], + crate::chain_spec::get_account_id_from_seed::("Alice"), + ) +} + +/// Helper function to create RuntimeGenesisConfig for development +pub fn development_genesis_config( + initial_authorities: Vec<( + AccountId, + AccountId, + GrandpaId, + BabeId, + ImOnlineId, + AuthorityDiscoveryId, + )>, + initial_nominators: Vec, + root_key: AccountId, +) -> RuntimeGenesisConfig { + let mut endowed_accounts = endowed_accounts_dev(); + // endow all authorities and nominators. + initial_authorities.iter().map(|x| &x.0).chain(initial_nominators.iter()).for_each(|x| { + if !endowed_accounts.contains(x) { + endowed_accounts.push(x.clone()) + } + }); + + // stakers: all validators and nominators. + let mut rng = rand::thread_rng(); + let stakers = initial_authorities + .iter() + .map(|x| (x.0.clone(), x.1.clone(), STASH, StakerStatus::Validator)) + .chain(initial_nominators.iter().map(|x| { + use rand::{seq::SliceRandom, Rng}; + let limit = (MaxNominations::get() as usize).min(initial_authorities.len()); + let count = rng.gen::() % limit; + let nominations = initial_authorities + .as_slice() + .choose_multiple(&mut rng, count) + .map(|choice| choice.0.clone()) + .collect::>(); + (x.clone(), x.clone(), STASH, StakerStatus::Nominator(nominations)) + })) + .collect::>(); + + let num_endowed_accounts = endowed_accounts.len(); + + const ENDOWMENT: Balance = 10_000_000 * DOLLARS; + const STASH: Balance = ENDOWMENT / 1000; + + RuntimeGenesisConfig { + system: SystemConfig { code: wasm_binary_unwrap().to_vec(), ..Default::default() }, + balances: BalancesConfig { + balances: endowed_accounts.iter().cloned().map(|x| (x, ENDOWMENT)).collect(), + }, + indices: IndicesConfig { indices: vec![] }, + session: SessionConfig { + keys: initial_authorities + .iter() + .map(|x| { + ( + x.0.clone(), + x.0.clone(), + crate::chain_spec::session_keys( + x.2.clone(), + x.3.clone(), + x.4.clone(), + x.5.clone(), + ), + ) + }) + .collect::>(), + }, + staking: StakingConfig { + validator_count: initial_authorities.len() as u32, + minimum_validator_count: 0, + invulnerables: vec![], + slash_reward_fraction: Perbill::from_percent(10), + stakers, + ..Default::default() + }, + staking_extension: StakingExtensionConfig { + threshold_servers: vec![ + ( + crate::chain_spec::get_account_id_from_seed::("Alice//stash"), + ( + // Seed phrase: "alarm mutual concert decrease hurry invest culture survey diagram crash snap click" + (*crate::chain_spec::ALICE_TSS_ACCOUNT_ID).into(), + *entropy_shared::ALICE_X25519_PUBLIC_KEY, + "127.0.0.1:3001".as_bytes().to_vec(), + ), + ), + ( + crate::chain_spec::get_account_id_from_seed::("Bob//stash"), + ( + // Seed phrase: "where sight patient orphan general short empower hope party hurt month voice" + (*crate::chain_spec::BOB_TSS_ACCOUNT_ID).into(), + *entropy_shared::BOB_X25519_PUBLIC_KEY, + "127.0.0.1:3002".as_bytes().to_vec(), + ), + ), + ], + signing_groups: vec![ + ( + 0, + vec![crate::chain_spec::get_account_id_from_seed::( + "Alice//stash", + )], + ), + ( + 1, + vec![crate::chain_spec::get_account_id_from_seed::( + "Bob//stash", + )], + ), + ], + proactive_refresh_validators: vec![], + }, + democracy: DemocracyConfig::default(), + elections: ElectionsConfig { + members: endowed_accounts + .iter() + .take((num_endowed_accounts + 1) / 2) + .cloned() + .map(|member| (member, STASH)) + .collect(), + }, + council: CouncilConfig::default(), + technical_committee: TechnicalCommitteeConfig { + members: endowed_accounts + .iter() + .take((num_endowed_accounts + 1) / 2) + .cloned() + .collect(), + phantom: Default::default(), + }, + sudo: SudoConfig { key: Some(root_key) }, + babe: BabeConfig { + authorities: vec![], + epoch_config: Some(entropy_runtime::BABE_GENESIS_EPOCH_CONFIG), + ..Default::default() + }, + im_online: ImOnlineConfig { keys: vec![] }, + authority_discovery: AuthorityDiscoveryConfig { keys: vec![], ..Default::default() }, + grandpa: GrandpaConfig { authorities: vec![], ..Default::default() }, + technical_membership: Default::default(), + treasury: Default::default(), + relayer: RelayerConfig { + registered_accounts: vec![ + (crate::chain_spec::get_account_id_from_seed::("Dave"), 0, None), + ( + crate::chain_spec::get_account_id_from_seed::("Eve"), + 1, + Some([ + 28, 63, 144, 84, 78, 147, 195, 214, 190, 234, 111, 101, 117, 133, 9, 198, + 96, 96, 76, 140, 152, 251, 255, 28, 167, 38, 157, 185, 192, 42, 201, 82, + ]), + ), + (crate::chain_spec::get_account_id_from_seed::("Ferdie"), 2, None), + ], + }, + vesting: Default::default(), + transaction_storage: Default::default(), + transaction_payment: Default::default(), + nomination_pools: Default::default(), + } +} diff --git a/node/cli/src/chain_spec/mod.rs b/node/cli/src/chain_spec/mod.rs index 61f0b9bf8..916848f31 100644 --- a/node/cli/src/chain_spec/mod.rs +++ b/node/cli/src/chain_spec/mod.rs @@ -32,6 +32,9 @@ //! Substrate chain configurations. #![allow(dead_code)] + +pub mod dev; + pub use entropy_runtime::RuntimeGenesisConfig; use entropy_runtime::{ constants::currency::*, wasm_binary_unwrap, AuthorityDiscoveryConfig, BabeConfig, @@ -802,22 +805,6 @@ pub fn testing( } } -/// Development config (single validator Alice) -pub fn development_config() -> ChainSpec { - ChainSpec::from_genesis( - "Development", - "dev", - ChainType::Development, - admin::development_config_genesis, - vec![], - None, - None, - None, - None, - Default::default(), - ) -} - /// Local devnet configuration, used when invoked with the /// `--chain local-devnet` option. pub fn local_devnet_config() -> ChainSpec { From 069c75b1c42da5075101e150f9dcfd6c3ca2ed26 Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Mon, 15 Jan 2024 16:11:04 -0700 Subject: [PATCH 04/28] Add WIP `load_spec` changes --- node/cli/src/command.rs | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/node/cli/src/command.rs b/node/cli/src/command.rs index b2255d212..4be681a88 100644 --- a/node/cli/src/command.rs +++ b/node/cli/src/command.rs @@ -67,16 +67,34 @@ impl SubstrateCli for Cli { 2022 } + // dev -> one node, Alice + // + // testnet-dev, one node, Alice + // testnet-local, two nodes, Alice + Bob + // testnet-staging -> four nodes, secret seeds <-- This is what we're doing now basically + // testnet -> production spec, four nodes, secret seed <-- Maybe merge with above + // + // | --chain | Description | + // |-----------------|----------- | + // | dev | Single node, Alice, Development Configuration | + // | testnet-dev | Single node, Alice, Testnet Configuration | + // | testnet-local | Two Nodes, Alice and Bob, Testnet Configuration | + // | testnet-staging | Four Nodes, Own Seed, Testnet Configuration | fn load_spec(&self, id: &str) -> Result, String> { Ok(match id { - "dev" => Box::new(chain_spec::development_config()), - "test" => Box::new(chain_spec::testing_config()), - "local-devnet" => Box::new(chain_spec::local_devnet_config()), - "" | "local" => Box::new(chain_spec::local_testnet_config()), - "testnet" => Box::new(chain_spec::testnet_config()), - path => { - Box::new(chain_spec::ChainSpec::from_json_file(std::path::PathBuf::from(path))?) - }, + "dev" => Box::new(chain_spec::dev::development_config()), + _ => unimplemented!(), + // "testnet-dev" => Box::new(chain_spec::testnet_config()), + // "testnet-local" => Box::new(chain_spec::testnet_config()), + // "testnet" => Box::new(chain_spec::testnet_config()), + + // "test" => Box::new(chain_spec::testing_config()), + // "local-devnet" => Box::new(chain_spec::local_devnet_config()), + // "" | "local" => Box::new(chain_spec::local_testnet_config()), + // "testnet" => Box::new(chain_spec::testnet_config()), + // path => { + // Box::new(chain_spec::ChainSpec::from_json_file(std::path::PathBuf::from(path))?) + // }, }) } } From 6e03f9f4a69bd6af640688352585d208e4f83b3d Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Mon, 15 Jan 2024 16:35:18 -0700 Subject: [PATCH 05/28] Fill out `testnet` module --- node/cli/src/admin.rs | 104 ---------- node/cli/src/chain_spec/dev.rs | 22 +- node/cli/src/chain_spec/mod.rs | 20 +- node/cli/src/chain_spec/testnet.rs | 318 ++++++++++++++++++++++++++++- node/cli/src/command.rs | 1 + 5 files changed, 329 insertions(+), 136 deletions(-) diff --git a/node/cli/src/admin.rs b/node/cli/src/admin.rs index ef55aab54..aaf9083fe 100644 --- a/node/cli/src/admin.rs +++ b/node/cli/src/admin.rs @@ -43,110 +43,6 @@ use crate::chain_spec::{ testnet_genesis, }; -pub fn testnet_config_genesis() -> RuntimeGenesisConfig { - #[rustfmt::skip] - // stash, controller, session-key - // generated with secret: - // for i in 1 2 3 4 ; do for j in stash controller; do subkey inspect "$secret"/fir/$j/$i; done; done - // - // and - // - // for i in 1 2 3 4 ; do for j in session; do subkey --ed25519 inspect "$secret"//fir//$j//$i; done; done - - let initial_authorities: Vec<( - AccountId, - AccountId, - GrandpaId, - BabeId, - ImOnlineId, - AuthorityDiscoveryId, - )> = vec![ - ( - // controller -> Sr25519 - // 5DUp9KHrDi8k8R4e2rPZhbxudUzEuNtxwUvfbCYtCZRA4no6 - hex!["3e9f4983e0cd02803c0d2e0fd58ea8d89e0a279e829a1aa9fdc1162a1a53e359"].into(), - // stash -> Sr25519 - // 5FNHcKqJzVGfSCFNAsw3YfPdHioKN7Usdtd32vBEkU1LjVV7 - hex!["921d7e7421fa0120839c5f4f29b651421720d79e3885856abb127ed8d5744d22"].into(), - // grandpa -> ed25519 - // 5H9kQJyK9THVhvgcKBSGWGidjSezNTdUn5p5Jc2c75kV6Txk - hex!["e105f69f91ddfa8499434c6cf03f0208ee26bf57446f70558ef6bc5bfbdcd258"] - .unchecked_into(), - // babe -> Sr25519 - // 5D7MndGJ3BVvm7sAcuVuXffVuDfTrSjS4cSieVJcQeqLfycR - hex!["2e4268b609fac59c448d755d3b63ef30d897c6f7e0eeb3eeff3e7d0e0d93cc12"] - .unchecked_into(), - // im online -> Sr25519 - // 5F4RQ5dTKKyvmkuVuKTTUUqDFm9oRe8gZRpmU8fhDtpxH4ar - hex!["847d4be0524b7eac945860cfd1bcd8d40e6cfcfbc7634251ddcdb89c54d4356d"] - .unchecked_into(), - // authority discovery -> Sr25519 - // 5FBo1QLcDGzH9zZcpE59dFJjWnqqpXnT6ZcwF6y2fGByGNKf - hex!["8a1cc1b2c4cd82693fc73714a4ef9937c1a413f612e0f46e095b3cf60f928f73"] - .unchecked_into(), - ), - ( - // 5Gen3ZR6zY4bo55KwioD6bE57GVv8QnBEzL7b5t9rFUZXGE2 - hex!["caed5ff7554fd17349372086115af48ffa4329ad92eb33b62f8ef3de425f4c42"].into(), - // 5CY72U7tqHNGspa2jE9MpJomDtBnzNSC73yq3dB8tsGohH3F - hex!["14e59e9d3c8b718545a9fc6994a83eb49f801c38d7cc268ad05dbe281cd5ed63"].into(), - // 5EkndhZ94fKCnx2zQ2o88rjGGupzhiKraHkEuxhwvDtQDzi5 - hex!["770a5ca4319c336b603afc1561529bb9be2ef91a1d54ab3cc1f3b86ee89525c9"] - .unchecked_into(), - // 5FZJsJ3zojt8fqiiR1LE1YtwmGfuVHicLrfBWfQ5ioH5hAsd - hex!["9a856db37bedb9376c143bf6b033737205a7f04c7e13102fdd902d94d9130c56"] - .unchecked_into(), - // 5CDmK3XPvYij5UBeCWXQwrfkboKmAHL3YLfZZeUf2AHHmXsv - hex!["06e8d69f5e46f672f07ab84387dd81cf7f592ada2153aaab7f1be723bf37bb3b"] - .unchecked_into(), - // 5CXJMPeb9xXHgRQYRj9kV3UpvacAc2qNEydrZH9WjyD191kp - hex!["1448807387ae3a70de2c86ce09a00f7f856344459413027520f48414f6cff972"] - .unchecked_into(), - ), - ( - // 5DwWZzE82vNXbLdo8hpnjxrwVSmhBRjVZczQBcyH3Z2oRWKX - hex!["52fbc068cc0917950befb99cc3f9077d4a2fb0bdaefeaf19a49a88481a11b412"].into(), - // 5CD3xHo9rp1gGNnnpVgRtVTN55bRHKbaYbDDSr32T9usNLsE - hex!["065d9d92615eb51aca8d14b06a84d7bf6700f0914095f9c4a8b0e0b62160ea42"].into(), - // 5FdoJSe3oGSDFU8ebnmQpKr4FUeM9tgtsRMaNWYbT42AzVLV - hex!["9df22049a7c64c3728f798ec667949930c6835d8f63ef3d47322096ab5e341a1"] - .unchecked_into(), - // 5DJ2e2NVmZe2H81MFp3zLQSy1CQmHTmpidB8GCSo3gow2oeh - hex!["3665a6484210be60c355d1521644c87348f9a0c0c8621d3ea58de3a907508417"] - .unchecked_into(), - // 5EFsfWeGvDLmdv6oKmkK9FtieSuTTFzQg8p4bZqxwC5k8q5n - hex!["60fd2e8b6823646393021617820571411e09260b059203743182d565235aef03"] - .unchecked_into(), - // 5EeXANUui1gHckcw7zF3AdmwXyFBzRcicC5wU36CY4cHdNGF - hex!["7242cf0d47e22380f5d16e4d283cd2fc33d1d7526cb4fbbf9787b564f1ce9679"] - .unchecked_into(), - ), - ( - // 5FLc2mJXwzfPsWAtaLAK9f1RUirr3hBRP9btADeYrSY6TSkn - hex!["90d503d66e6f555429433573bf0998f60e4916b3e80f16fed334f11470533d4b"].into(), - // 5CXuG9z2XcHwdqTAG451tNvcr9PSrVfEXtCkzkRwPnFLBE7Y - hex!["14be04b5670df7ca712ce3e67d620fd0846f87fa34de72bb2f80c9f0c881b401"].into(), - // 5DZ4Sq7C6fDPRgm4im5H6wyhL3SbUqCWAfRB9gMc1hFAgHrb - hex!["41dc69dafec1016f5d4168975a6c7615017703f6d8b5fdeeca4952ed91fabf67"] - .unchecked_into(), - // 5FWy2dvHo4B2CnkwumMQgM5hVUV3mgviB16WQ1DWqFcZM8bi - hex!["98bc276917d57ead1874841aa956f9fa28a8c9a21a3f03eb982186fead6a2467"] - .unchecked_into(), - // 5FvBb7ZaSny6h8G9HCdKEZH79o7BfjVxKjsfMNc7vgoMFZ3f - hex!["aa71142ae23a5c60f33a064462c44c5425c48c7345f12dc9ad00a56580e8835b"] - .unchecked_into(), - // 5ELz6TfwTwbwAsXoEycB5oTQCcMPLipEqDRsjVw7GYot2pNh - hex!["64e30dfddf0e622b1db1e6ad27f3724b349ed9369862b84ec9a1a262c724603e"] - .unchecked_into(), - ), - ]; - - let root_key: AccountId = - hex!["6a16ded05ff7a50716e1ca943f0467c60b4b71c2a7fd7f75b6333b8af80b6e6f"].into(); - - testnet_genesis(initial_authorities, vec![], root_key) -} - pub fn staging_testnet_config_genesis() -> RuntimeGenesisConfig { #[rustfmt::skip] // stash, controller, session-key diff --git a/node/cli/src/chain_spec/dev.rs b/node/cli/src/chain_spec/dev.rs index 01eb25c91..880fa8ab6 100644 --- a/node/cli/src/chain_spec/dev.rs +++ b/node/cli/src/chain_spec/dev.rs @@ -36,7 +36,16 @@ pub fn development_config() -> crate::chain_spec::ChainSpec { "Development", "dev", ChainType::Development, - development_config_genesis, + || { + development_genesis_config( + vec![ + crate::chain_spec::authority_keys_from_seed("Alice"), + crate::chain_spec::authority_keys_from_seed("Bob"), + ], + vec![], + crate::chain_spec::get_account_id_from_seed::("Alice"), + ) + }, vec![], None, None, @@ -46,17 +55,6 @@ pub fn development_config() -> crate::chain_spec::ChainSpec { ) } -pub fn development_config_genesis() -> RuntimeGenesisConfig { - development_genesis_config( - vec![ - crate::chain_spec::authority_keys_from_seed("Alice"), - crate::chain_spec::authority_keys_from_seed("Bob"), - ], - vec![], - crate::chain_spec::get_account_id_from_seed::("Alice"), - ) -} - /// Helper function to create RuntimeGenesisConfig for development pub fn development_genesis_config( initial_authorities: Vec<( diff --git a/node/cli/src/chain_spec/mod.rs b/node/cli/src/chain_spec/mod.rs index 916848f31..4c2d17b93 100644 --- a/node/cli/src/chain_spec/mod.rs +++ b/node/cli/src/chain_spec/mod.rs @@ -34,6 +34,7 @@ #![allow(dead_code)] pub mod dev; +pub mod testnet; pub use entropy_runtime::RuntimeGenesisConfig; use entropy_runtime::{ @@ -838,25 +839,6 @@ pub fn testing_config() -> ChainSpec { ) } -/// Development config (single validator Alice) -pub fn testnet_config() -> ChainSpec { - ChainSpec::from_genesis( - "EntropyTestnet", - "ETest", - ChainType::Live, - admin::testnet_config_genesis, - vec![], - Some( - TelemetryEndpoints::new(vec![(STAGING_TELEMETRY_URL.to_string(), 0)]) - .expect("Staging telemetry url is valid; qed"), - ), - Some(DEFAULT_PROTOCOL_ID), - None, - Some(entropy_props()), - Default::default(), - ) -} - fn local_testnet_genesis() -> RuntimeGenesisConfig { testnet_genesis( vec![authority_keys_from_seed("Alice"), authority_keys_from_seed("Bob")], diff --git a/node/cli/src/chain_spec/testnet.rs b/node/cli/src/chain_spec/testnet.rs index 4a835673a..69fc30ecd 100644 --- a/node/cli/src/chain_spec/testnet.rs +++ b/node/cli/src/chain_spec/testnet.rs @@ -1 +1,317 @@ -pub struct Foo; +// Copyright (C) 2023 Entropy Cryptography Inc. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +pub use entropy_runtime::RuntimeGenesisConfig; +use entropy_runtime::{ + constants::currency::*, wasm_binary_unwrap, AuthorityDiscoveryConfig, BabeConfig, + BalancesConfig, CouncilConfig, DemocracyConfig, ElectionsConfig, GrandpaConfig, ImOnlineConfig, + IndicesConfig, MaxNominations, RelayerConfig, SessionConfig, StakerStatus, StakingConfig, + StakingExtensionConfig, SudoConfig, SystemConfig, TechnicalCommitteeConfig, +}; +use grandpa_primitives::AuthorityId as GrandpaId; +use hex_literal::hex; +pub use node_primitives::{AccountId, Balance, Signature}; +use pallet_im_online::sr25519::AuthorityId as ImOnlineId; +use sc_service::ChainType; +use sc_telemetry::TelemetryEndpoints; +use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId; +use sp_consensus_babe::AuthorityId as BabeId; +use sp_core::{crypto::UncheckedInto, sr25519}; +use sp_runtime::Perbill; + +use crate::endowed_accounts::endowed_accounts_dev; + +pub fn testnet_initial_authorities( +) -> Vec<(AccountId, AccountId, GrandpaId, BabeId, ImOnlineId, AuthorityDiscoveryId)> { + // stash, controller, session-key + // generated with secret: + // for i in 1 2 3 4 ; do for j in stash controller; do subkey inspect "$secret"/fir/$j/$i; done; done + // + // and + // + // for i in 1 2 3 4 ; do for j in session; do subkey --ed25519 inspect "$secret"//fir//$j//$i; done; done + vec![ + ( + // controller -> Sr25519 + // 5DUp9KHrDi8k8R4e2rPZhbxudUzEuNtxwUvfbCYtCZRA4no6 + hex!["3e9f4983e0cd02803c0d2e0fd58ea8d89e0a279e829a1aa9fdc1162a1a53e359"].into(), + // stash -> Sr25519 + // 5FNHcKqJzVGfSCFNAsw3YfPdHioKN7Usdtd32vBEkU1LjVV7 + hex!["921d7e7421fa0120839c5f4f29b651421720d79e3885856abb127ed8d5744d22"].into(), + // grandpa -> ed25519 + // 5H9kQJyK9THVhvgcKBSGWGidjSezNTdUn5p5Jc2c75kV6Txk + hex!["e105f69f91ddfa8499434c6cf03f0208ee26bf57446f70558ef6bc5bfbdcd258"] + .unchecked_into(), + // babe -> Sr25519 + // 5D7MndGJ3BVvm7sAcuVuXffVuDfTrSjS4cSieVJcQeqLfycR + hex!["2e4268b609fac59c448d755d3b63ef30d897c6f7e0eeb3eeff3e7d0e0d93cc12"] + .unchecked_into(), + // im online -> Sr25519 + // 5F4RQ5dTKKyvmkuVuKTTUUqDFm9oRe8gZRpmU8fhDtpxH4ar + hex!["847d4be0524b7eac945860cfd1bcd8d40e6cfcfbc7634251ddcdb89c54d4356d"] + .unchecked_into(), + // authority discovery -> Sr25519 + // 5FBo1QLcDGzH9zZcpE59dFJjWnqqpXnT6ZcwF6y2fGByGNKf + hex!["8a1cc1b2c4cd82693fc73714a4ef9937c1a413f612e0f46e095b3cf60f928f73"] + .unchecked_into(), + ), + ( + // 5Gen3ZR6zY4bo55KwioD6bE57GVv8QnBEzL7b5t9rFUZXGE2 + hex!["caed5ff7554fd17349372086115af48ffa4329ad92eb33b62f8ef3de425f4c42"].into(), + // 5CY72U7tqHNGspa2jE9MpJomDtBnzNSC73yq3dB8tsGohH3F + hex!["14e59e9d3c8b718545a9fc6994a83eb49f801c38d7cc268ad05dbe281cd5ed63"].into(), + // 5EkndhZ94fKCnx2zQ2o88rjGGupzhiKraHkEuxhwvDtQDzi5 + hex!["770a5ca4319c336b603afc1561529bb9be2ef91a1d54ab3cc1f3b86ee89525c9"] + .unchecked_into(), + // 5FZJsJ3zojt8fqiiR1LE1YtwmGfuVHicLrfBWfQ5ioH5hAsd + hex!["9a856db37bedb9376c143bf6b033737205a7f04c7e13102fdd902d94d9130c56"] + .unchecked_into(), + // 5CDmK3XPvYij5UBeCWXQwrfkboKmAHL3YLfZZeUf2AHHmXsv + hex!["06e8d69f5e46f672f07ab84387dd81cf7f592ada2153aaab7f1be723bf37bb3b"] + .unchecked_into(), + // 5CXJMPeb9xXHgRQYRj9kV3UpvacAc2qNEydrZH9WjyD191kp + hex!["1448807387ae3a70de2c86ce09a00f7f856344459413027520f48414f6cff972"] + .unchecked_into(), + ), + ( + // 5DwWZzE82vNXbLdo8hpnjxrwVSmhBRjVZczQBcyH3Z2oRWKX + hex!["52fbc068cc0917950befb99cc3f9077d4a2fb0bdaefeaf19a49a88481a11b412"].into(), + // 5CD3xHo9rp1gGNnnpVgRtVTN55bRHKbaYbDDSr32T9usNLsE + hex!["065d9d92615eb51aca8d14b06a84d7bf6700f0914095f9c4a8b0e0b62160ea42"].into(), + // 5FdoJSe3oGSDFU8ebnmQpKr4FUeM9tgtsRMaNWYbT42AzVLV + hex!["9df22049a7c64c3728f798ec667949930c6835d8f63ef3d47322096ab5e341a1"] + .unchecked_into(), + // 5DJ2e2NVmZe2H81MFp3zLQSy1CQmHTmpidB8GCSo3gow2oeh + hex!["3665a6484210be60c355d1521644c87348f9a0c0c8621d3ea58de3a907508417"] + .unchecked_into(), + // 5EFsfWeGvDLmdv6oKmkK9FtieSuTTFzQg8p4bZqxwC5k8q5n + hex!["60fd2e8b6823646393021617820571411e09260b059203743182d565235aef03"] + .unchecked_into(), + // 5EeXANUui1gHckcw7zF3AdmwXyFBzRcicC5wU36CY4cHdNGF + hex!["7242cf0d47e22380f5d16e4d283cd2fc33d1d7526cb4fbbf9787b564f1ce9679"] + .unchecked_into(), + ), + ( + // 5FLc2mJXwzfPsWAtaLAK9f1RUirr3hBRP9btADeYrSY6TSkn + hex!["90d503d66e6f555429433573bf0998f60e4916b3e80f16fed334f11470533d4b"].into(), + // 5CXuG9z2XcHwdqTAG451tNvcr9PSrVfEXtCkzkRwPnFLBE7Y + hex!["14be04b5670df7ca712ce3e67d620fd0846f87fa34de72bb2f80c9f0c881b401"].into(), + // 5DZ4Sq7C6fDPRgm4im5H6wyhL3SbUqCWAfRB9gMc1hFAgHrb + hex!["41dc69dafec1016f5d4168975a6c7615017703f6d8b5fdeeca4952ed91fabf67"] + .unchecked_into(), + // 5FWy2dvHo4B2CnkwumMQgM5hVUV3mgviB16WQ1DWqFcZM8bi + hex!["98bc276917d57ead1874841aa956f9fa28a8c9a21a3f03eb982186fead6a2467"] + .unchecked_into(), + // 5FvBb7ZaSny6h8G9HCdKEZH79o7BfjVxKjsfMNc7vgoMFZ3f + hex!["aa71142ae23a5c60f33a064462c44c5425c48c7345f12dc9ad00a56580e8835b"] + .unchecked_into(), + // 5ELz6TfwTwbwAsXoEycB5oTQCcMPLipEqDRsjVw7GYot2pNh + hex!["64e30dfddf0e622b1db1e6ad27f3724b349ed9369862b84ec9a1a262c724603e"] + .unchecked_into(), + ), + ] +} + +/// Development config (single validator Alice) +pub fn testnet_config() -> crate::chain_spec::ChainSpec { + crate::chain_spec::ChainSpec::from_genesis( + "EntropyTestnet", + "ETest", + ChainType::Live, + || { + testnet_genesis_config( + testnet_initial_authorities(), + vec![], + hex!["6a16ded05ff7a50716e1ca943f0467c60b4b71c2a7fd7f75b6333b8af80b6e6f"].into(), + ) + }, + vec![], + Some( + TelemetryEndpoints::new(vec![( + crate::chain_spec::STAGING_TELEMETRY_URL.to_string(), + 0, + )]) + .expect("Staging telemetry url is valid; qed"), + ), + Some(crate::chain_spec::DEFAULT_PROTOCOL_ID), + None, + Some(crate::chain_spec::entropy_props()), // TODO: Maybe move into this module + Default::default(), + ) +} + +/// Helper function to create RuntimeGenesisConfig for testing +pub fn testnet_genesis_config( + initial_authorities: Vec<( + AccountId, + AccountId, + GrandpaId, + BabeId, + ImOnlineId, + AuthorityDiscoveryId, + )>, + initial_nominators: Vec, + root_key: AccountId, +) -> RuntimeGenesisConfig { + // --- Config Below this --- + + let mut endowed_accounts = endowed_accounts_dev(); + // endow all authorities and nominators. + initial_authorities.iter().map(|x| &x.0).chain(initial_nominators.iter()).for_each(|x| { + if !endowed_accounts.contains(x) { + endowed_accounts.push(x.clone()) + } + }); + + // stakers: all validators and nominators. + let mut rng = rand::thread_rng(); + let stakers = initial_authorities + .iter() + .map(|x| (x.0.clone(), x.1.clone(), STASH, StakerStatus::Validator)) + .chain(initial_nominators.iter().map(|x| { + use rand::{seq::SliceRandom, Rng}; + let limit = (MaxNominations::get() as usize).min(initial_authorities.len()); + let count = rng.gen::() % limit; + let nominations = initial_authorities + .as_slice() + .choose_multiple(&mut rng, count) + .map(|choice| choice.0.clone()) + .collect::>(); + (x.clone(), x.clone(), STASH, StakerStatus::Nominator(nominations)) + })) + .collect::>(); + + let num_endowed_accounts = endowed_accounts.len(); + + const ENDOWMENT: Balance = 10_000_000 * DOLLARS; + const STASH: Balance = ENDOWMENT / 1000; + + RuntimeGenesisConfig { + system: SystemConfig { code: wasm_binary_unwrap().to_vec(), ..Default::default() }, + balances: BalancesConfig { + balances: endowed_accounts.iter().cloned().map(|x| (x, ENDOWMENT)).collect(), + }, + indices: IndicesConfig { indices: vec![] }, + session: SessionConfig { + keys: initial_authorities + .iter() + .map(|x| { + ( + x.0.clone(), + x.0.clone(), + crate::chain_spec::session_keys( + x.2.clone(), + x.3.clone(), + x.4.clone(), + x.5.clone(), + ), + ) + }) + .collect::>(), + }, + staking: StakingConfig { + validator_count: initial_authorities.len() as u32, + minimum_validator_count: 0, + invulnerables: vec![], + slash_reward_fraction: Perbill::from_percent(10), + stakers, + ..Default::default() + }, + staking_extension: StakingExtensionConfig { + threshold_servers: vec![ + ( + crate::chain_spec::get_account_id_from_seed::("Alice//stash"), + ( + // Seed phrase: "alarm mutual concert decrease hurry invest culture survey diagram crash snap click" + (*crate::chain_spec::ALICE_TSS_ACCOUNT_ID).into(), + *entropy_shared::ALICE_X25519_PUBLIC_KEY, + "127.0.0.1:3001".as_bytes().to_vec(), + ), + ), + ( + crate::chain_spec::get_account_id_from_seed::("Bob//stash"), + ( + // Seed phrase: "where sight patient orphan general short empower hope party hurt month voice" + (*crate::chain_spec::BOB_TSS_ACCOUNT_ID).into(), + *entropy_shared::BOB_X25519_PUBLIC_KEY, + "127.0.0.1:3002".as_bytes().to_vec(), + ), + ), + ], + signing_groups: vec![ + ( + 0, + vec![crate::chain_spec::get_account_id_from_seed::( + "Alice//stash", + )], + ), + ( + 1, + vec![crate::chain_spec::get_account_id_from_seed::( + "Bob//stash", + )], + ), + ], + proactive_refresh_validators: vec![], + }, + democracy: DemocracyConfig::default(), + elections: ElectionsConfig { + members: endowed_accounts + .iter() + .take((num_endowed_accounts + 1) / 2) + .cloned() + .map(|member| (member, STASH)) + .collect(), + }, + council: CouncilConfig::default(), + technical_committee: TechnicalCommitteeConfig { + members: endowed_accounts + .iter() + .take((num_endowed_accounts + 1) / 2) + .cloned() + .collect(), + phantom: Default::default(), + }, + sudo: SudoConfig { key: Some(root_key) }, + babe: BabeConfig { + authorities: vec![], + epoch_config: Some(entropy_runtime::BABE_GENESIS_EPOCH_CONFIG), + ..Default::default() + }, + im_online: ImOnlineConfig { keys: vec![] }, + authority_discovery: AuthorityDiscoveryConfig { keys: vec![], ..Default::default() }, + grandpa: GrandpaConfig { authorities: vec![], ..Default::default() }, + technical_membership: Default::default(), + treasury: Default::default(), + relayer: RelayerConfig { + registered_accounts: vec![ + (crate::chain_spec::get_account_id_from_seed::("Dave"), 0, None), + ( + crate::chain_spec::get_account_id_from_seed::("Eve"), + 1, + Some([ + 28, 63, 144, 84, 78, 147, 195, 214, 190, 234, 111, 101, 117, 133, 9, 198, + 96, 96, 76, 140, 152, 251, 255, 28, 167, 38, 157, 185, 192, 42, 201, 82, + ]), + ), + (crate::chain_spec::get_account_id_from_seed::("Ferdie"), 2, None), + ], + }, + vesting: Default::default(), + transaction_storage: Default::default(), + transaction_payment: Default::default(), + nomination_pools: Default::default(), + } +} diff --git a/node/cli/src/command.rs b/node/cli/src/command.rs index 4be681a88..74d65abf9 100644 --- a/node/cli/src/command.rs +++ b/node/cli/src/command.rs @@ -83,6 +83,7 @@ impl SubstrateCli for Cli { fn load_spec(&self, id: &str) -> Result, String> { Ok(match id { "dev" => Box::new(chain_spec::dev::development_config()), + "testnet" => Box::new(chain_spec::testnet::testnet_config()), _ => unimplemented!(), // "testnet-dev" => Box::new(chain_spec::testnet_config()), // "testnet-local" => Box::new(chain_spec::testnet_config()), From 38396c57d4cd3ce5575a25a0fd3c0f9d497e524c Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Mon, 15 Jan 2024 16:57:19 -0700 Subject: [PATCH 06/28] Add `testnet_local` configuration --- node/cli/src/chain_spec/testnet.rs | 37 ++++++++++++++++++++++++++++-- node/cli/src/command.rs | 1 + 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/node/cli/src/chain_spec/testnet.rs b/node/cli/src/chain_spec/testnet.rs index 69fc30ecd..a738a4661 100644 --- a/node/cli/src/chain_spec/testnet.rs +++ b/node/cli/src/chain_spec/testnet.rs @@ -33,6 +33,14 @@ use sp_runtime::Perbill; use crate::endowed_accounts::endowed_accounts_dev; +pub fn testnet_local_initial_authorities( +) -> Vec<(AccountId, AccountId, GrandpaId, BabeId, ImOnlineId, AuthorityDiscoveryId)> { + vec![ + crate::chain_spec::authority_keys_from_seed("Alice"), + crate::chain_spec::authority_keys_from_seed("Bob"), + ] +} + pub fn testnet_initial_authorities( ) -> Vec<(AccountId, AccountId, GrandpaId, BabeId, ImOnlineId, AuthorityDiscoveryId)> { // stash, controller, session-key @@ -124,6 +132,33 @@ pub fn testnet_initial_authorities( ] } +pub fn testnet_local_config() -> crate::chain_spec::ChainSpec { + crate::chain_spec::ChainSpec::from_genesis( + "EntropyTestnetLocal", + "ETestLocal", + ChainType::Live, + || { + testnet_genesis_config( + testnet_local_initial_authorities(), + vec![], + crate::chain_spec::get_account_id_from_seed::("Alice"), + ) + }, + vec![], + Some( + TelemetryEndpoints::new(vec![( + crate::chain_spec::STAGING_TELEMETRY_URL.to_string(), + 0, + )]) + .expect("Staging telemetry url is valid; qed"), + ), + Some(crate::chain_spec::DEFAULT_PROTOCOL_ID), + None, + Some(crate::chain_spec::entropy_props()), // TODO: Maybe move into this module + Default::default(), + ) +} + /// Development config (single validator Alice) pub fn testnet_config() -> crate::chain_spec::ChainSpec { crate::chain_spec::ChainSpec::from_genesis( @@ -165,8 +200,6 @@ pub fn testnet_genesis_config( initial_nominators: Vec, root_key: AccountId, ) -> RuntimeGenesisConfig { - // --- Config Below this --- - let mut endowed_accounts = endowed_accounts_dev(); // endow all authorities and nominators. initial_authorities.iter().map(|x| &x.0).chain(initial_nominators.iter()).for_each(|x| { diff --git a/node/cli/src/command.rs b/node/cli/src/command.rs index 74d65abf9..4b5a399d2 100644 --- a/node/cli/src/command.rs +++ b/node/cli/src/command.rs @@ -83,6 +83,7 @@ impl SubstrateCli for Cli { fn load_spec(&self, id: &str) -> Result, String> { Ok(match id { "dev" => Box::new(chain_spec::dev::development_config()), + "testnet-local" => Box::new(chain_spec::testnet::testnet_local_config()), "testnet" => Box::new(chain_spec::testnet::testnet_config()), _ => unimplemented!(), // "testnet-dev" => Box::new(chain_spec::testnet_config()), From 5c25b9d7dee50ef70d6b1cd09b7705f893c65345 Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Mon, 15 Jan 2024 17:12:55 -0700 Subject: [PATCH 07/28] Remove `admin` module We don't need this anymore. Functionality has been moved into the `chain_spec` module. --- node/cli/src/admin.rs | 162 ------------------------------------------ node/cli/src/main.rs | 1 - 2 files changed, 163 deletions(-) delete mode 100644 node/cli/src/admin.rs diff --git a/node/cli/src/admin.rs b/node/cli/src/admin.rs deleted file mode 100644 index aaf9083fe..000000000 --- a/node/cli/src/admin.rs +++ /dev/null @@ -1,162 +0,0 @@ -// Copyright (C) 2023 Entropy Cryptography Inc. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -use entropy_runtime::RuntimeGenesisConfig; -use grandpa_primitives::AuthorityId as GrandpaId; -use hex_literal::hex; -use node_primitives::AccountId; -use pallet_im_online::sr25519::AuthorityId as ImOnlineId; -use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId; -use sp_consensus_babe::AuthorityId as BabeId; -use sp_core::{crypto::UncheckedInto, sr25519}; - -use crate::chain_spec::{ - authority_keys_from_seed, get_account_id_from_seed, local_devnet_genesis, testing, - testnet_genesis, -}; - -pub fn staging_testnet_config_genesis() -> RuntimeGenesisConfig { - #[rustfmt::skip] - // stash, controller, session-key - // generated with secret: - // for i in 1 2 3 4 ; do for j in stash controller; do subkey inspect "$secret"/fir/$j/$i; done; done - // - // and - // - // for i in 1 2 3 4 ; do for j in session; do subkey --ed25519 inspect "$secret"//fir//$j//$i; done; done - - let initial_authorities: Vec<( - AccountId, - AccountId, - GrandpaId, - BabeId, - ImOnlineId, - AuthorityDiscoveryId, - )> = vec![ - ( - // 5Fbsd6WXDGiLTxunqeK5BATNiocfCqu9bS1yArVjCgeBLkVy - hex!["9c7a2ee14e565db0c69f78c7b4cd839fbf52b607d867e9e9c5a79042898a0d12"].into(), - // 5EnCiV7wSHeNhjW3FSUwiJNkcc2SBkPLn5Nj93FmbLtBjQUq - hex!["781ead1e2fa9ccb74b44c19d29cb2a7a4b5be3972927ae98cd3877523976a276"].into(), - // 5Fb9ayurnxnaXj56CjmyQLBiadfRCqUbL2VWNbbe1nZU6wiC - hex!["9becad03e6dcac03cee07edebca5475314861492cdfc96a2144a67bbe9699332"] - .unchecked_into(), - // 5EZaeQ8djPcq9pheJUhgerXQZt9YaHnMJpiHMRhwQeinqUW8 - hex!["6e7e4eb42cbd2e0ab4cae8708ce5509580b8c04d11f6758dbf686d50fe9f9106"] - .unchecked_into(), - // 5EZaeQ8djPcq9pheJUhgerXQZt9YaHnMJpiHMRhwQeinqUW8 - hex!["6e7e4eb42cbd2e0ab4cae8708ce5509580b8c04d11f6758dbf686d50fe9f9106"] - .unchecked_into(), - // 5EZaeQ8djPcq9pheJUhgerXQZt9YaHnMJpiHMRhwQeinqUW8 - hex!["6e7e4eb42cbd2e0ab4cae8708ce5509580b8c04d11f6758dbf686d50fe9f9106"] - .unchecked_into(), - ), - ( - // 5ERawXCzCWkjVq3xz1W5KGNtVx2VdefvZ62Bw1FEuZW4Vny2 - hex!["68655684472b743e456907b398d3a44c113f189e56d1bbfd55e889e295dfde78"].into(), - // 5Gc4vr42hH1uDZc93Nayk5G7i687bAQdHHc9unLuyeawHipF - hex!["c8dc79e36b29395413399edaec3e20fcca7205fb19776ed8ddb25d6f427ec40e"].into(), - // 5EockCXN6YkiNCDjpqqnbcqd4ad35nU4RmA1ikM4YeRN4WcE - hex!["7932cff431e748892fa48e10c63c17d30f80ca42e4de3921e641249cd7fa3c2f"] - .unchecked_into(), - // 5DhLtiaQd1L1LU9jaNeeu9HJkP6eyg3BwXA7iNMzKm7qqruQ - hex!["482dbd7297a39fa145c570552249c2ca9dd47e281f0c500c971b59c9dcdcd82e"] - .unchecked_into(), - // 5DhLtiaQd1L1LU9jaNeeu9HJkP6eyg3BwXA7iNMzKm7qqruQ - hex!["482dbd7297a39fa145c570552249c2ca9dd47e281f0c500c971b59c9dcdcd82e"] - .unchecked_into(), - // 5DhLtiaQd1L1LU9jaNeeu9HJkP6eyg3BwXA7iNMzKm7qqruQ - hex!["482dbd7297a39fa145c570552249c2ca9dd47e281f0c500c971b59c9dcdcd82e"] - .unchecked_into(), - ), - ( - // 5DyVtKWPidondEu8iHZgi6Ffv9yrJJ1NDNLom3X9cTDi98qp - hex!["547ff0ab649283a7ae01dbc2eb73932eba2fb09075e9485ff369082a2ff38d65"].into(), - // 5FeD54vGVNpFX3PndHPXJ2MDakc462vBCD5mgtWRnWYCpZU9 - hex!["9e42241d7cd91d001773b0b616d523dd80e13c6c2cab860b1234ef1b9ffc1526"].into(), - // 5E1jLYfLdUQKrFrtqoKgFrRvxM3oQPMbf6DfcsrugZZ5Bn8d - hex!["5633b70b80a6c8bb16270f82cca6d56b27ed7b76c8fd5af2986a25a4788ce440"] - .unchecked_into(), - // 5DhKqkHRkndJu8vq7pi2Q5S3DfftWJHGxbEUNH43b46qNspH - hex!["482a3389a6cf42d8ed83888cfd920fec738ea30f97e44699ada7323f08c3380a"] - .unchecked_into(), - // 5DhKqkHRkndJu8vq7pi2Q5S3DfftWJHGxbEUNH43b46qNspH - hex!["482a3389a6cf42d8ed83888cfd920fec738ea30f97e44699ada7323f08c3380a"] - .unchecked_into(), - // 5DhKqkHRkndJu8vq7pi2Q5S3DfftWJHGxbEUNH43b46qNspH - hex!["482a3389a6cf42d8ed83888cfd920fec738ea30f97e44699ada7323f08c3380a"] - .unchecked_into(), - ), - ( - // 5HYZnKWe5FVZQ33ZRJK1rG3WaLMztxWrrNDb1JRwaHHVWyP9 - hex!["f26cdb14b5aec7b2789fd5ca80f979cef3761897ae1f37ffb3e154cbcc1c2663"].into(), - // 5EPQdAQ39WQNLCRjWsCk5jErsCitHiY5ZmjfWzzbXDoAoYbn - hex!["66bc1e5d275da50b72b15de072a2468a5ad414919ca9054d2695767cf650012f"].into(), - // 5DMa31Hd5u1dwoRKgC4uvqyrdK45RHv3CpwvpUC1EzuwDit4 - hex!["3919132b851ef0fd2dae42a7e734fe547af5a6b809006100f48944d7fae8e8ef"] - .unchecked_into(), - // 5C4vDQxA8LTck2xJEy4Yg1hM9qjDt4LvTQaMo4Y8ne43aU6x - hex!["00299981a2b92f878baaf5dbeba5c18d4e70f2a1fcd9c61b32ea18daf38f4378"] - .unchecked_into(), - // 5C4vDQxA8LTck2xJEy4Yg1hM9qjDt4LvTQaMo4Y8ne43aU6x - hex!["00299981a2b92f878baaf5dbeba5c18d4e70f2a1fcd9c61b32ea18daf38f4378"] - .unchecked_into(), - // 5C4vDQxA8LTck2xJEy4Yg1hM9qjDt4LvTQaMo4Y8ne43aU6x - hex!["00299981a2b92f878baaf5dbeba5c18d4e70f2a1fcd9c61b32ea18daf38f4378"] - .unchecked_into(), - ), - ]; - - // generated with secret: subkey inspect "$secret"/fir - let root_key: AccountId = hex![ - // 5Ff3iXP75ruzroPWRP2FYBHWnmGGBSb63857BgnzCoXNxfPo - "9ee5e5bdc0ec239eb164f865ecc345ce4c88e76ee002e0f7e318097347471809" - ] - .into(); - - testnet_genesis(initial_authorities, vec![], root_key) -} - -pub fn local_devnet_config_genesis() -> RuntimeGenesisConfig { - local_devnet_genesis( - vec![authority_keys_from_seed("Alice"), authority_keys_from_seed("Bob")], - vec![], - get_account_id_from_seed::("Alice"), - ) -} - -pub fn testing_config_genesis() -> RuntimeGenesisConfig { - testing( - vec![authority_keys_from_seed("Alice"), authority_keys_from_seed("Bob")], - vec![], - get_account_id_from_seed::("Alice"), - ) -} diff --git a/node/cli/src/main.rs b/node/cli/src/main.rs index 416cf594c..2a2c51be5 100644 --- a/node/cli/src/main.rs +++ b/node/cli/src/main.rs @@ -36,7 +36,6 @@ mod chain_spec; #[macro_use] mod service; -mod admin; mod benchmarking; mod cli; mod command; From c1efa387f260346ae4d20a9ab9a78c61019046c4 Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Mon, 15 Jan 2024 17:13:35 -0700 Subject: [PATCH 08/28] Remove uneccessary chain configs Let's keep this as simple as we can. If we need to add more chain configs later let's do that, but only if they're acutally being used. --- node/cli/src/chain_spec/mod.rs | 520 +------------------------------ node/cli/src/endowed_accounts.rs | 7 - 2 files changed, 7 insertions(+), 520 deletions(-) diff --git a/node/cli/src/chain_spec/mod.rs b/node/cli/src/chain_spec/mod.rs index 4c2d17b93..14380bb7a 100644 --- a/node/cli/src/chain_spec/mod.rs +++ b/node/cli/src/chain_spec/mod.rs @@ -50,8 +50,6 @@ use hex_literal::hex; pub use node_primitives::{AccountId, Balance, Signature}; use pallet_im_online::sr25519::AuthorityId as ImOnlineId; use sc_chain_spec::{ChainSpecExtension, Properties}; -use sc_service::ChainType; -use sc_telemetry::TelemetryEndpoints; use serde::{Deserialize, Serialize}; use serde_json::json; use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId; @@ -62,10 +60,7 @@ use sp_runtime::{ Perbill, }; -use crate::{ - admin, - endowed_accounts::{endowed_accounts_dev, endowed_accounts_devnet}, -}; +use crate::endowed_accounts::endowed_accounts_dev; type AccountPublic = ::Signer; const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/"; @@ -112,26 +107,6 @@ fn session_keys( SessionKeys { grandpa, babe, im_online, authority_discovery } } -/// Staging testnet config. -pub fn staging_testnet_config() -> ChainSpec { - let boot_nodes = vec![]; - ChainSpec::from_genesis( - "Staging Testnet", - "staging_testnet", - ChainType::Live, - admin::staging_testnet_config_genesis, - boot_nodes, - Some( - TelemetryEndpoints::new(vec![(STAGING_TELEMETRY_URL.to_string(), 0)]) - .expect("Staging telemetry url is valid; qed"), - ), - None, - None, - None, - Default::default(), - ) -} - /// Helper function to generate a crypto pair from seed pub fn get_from_seed(seed: &str) -> ::Public { TPublic::Pair::from_string(&format!("//{seed}"), None) @@ -161,436 +136,12 @@ pub fn authority_keys_from_seed( ) } -/// Helper function to create RuntimeGenesisConfig for testing -pub fn testnet_genesis( - initial_authorities: Vec<( - AccountId, - AccountId, - GrandpaId, - BabeId, - ImOnlineId, - AuthorityDiscoveryId, - )>, - initial_nominators: Vec, - root_key: AccountId, -) -> RuntimeGenesisConfig { - let mut endowed_accounts = endowed_accounts_dev(); - // endow all authorities and nominators. - initial_authorities.iter().map(|x| &x.0).chain(initial_nominators.iter()).for_each(|x| { - if !endowed_accounts.contains(x) { - endowed_accounts.push(x.clone()) - } - }); - - // stakers: all validators and nominators. - let mut rng = rand::thread_rng(); - let stakers = initial_authorities - .iter() - .map(|x| (x.0.clone(), x.1.clone(), STASH, StakerStatus::Validator)) - .chain(initial_nominators.iter().map(|x| { - use rand::{seq::SliceRandom, Rng}; - let limit = (MaxNominations::get() as usize).min(initial_authorities.len()); - let count = rng.gen::() % limit; - let nominations = initial_authorities - .as_slice() - .choose_multiple(&mut rng, count) - .map(|choice| choice.0.clone()) - .collect::>(); - (x.clone(), x.clone(), STASH, StakerStatus::Nominator(nominations)) - })) - .collect::>(); - - let num_endowed_accounts = endowed_accounts.len(); - - const ENDOWMENT: Balance = 10_000_000 * DOLLARS; - const STASH: Balance = ENDOWMENT / 1000; - - RuntimeGenesisConfig { - system: SystemConfig { code: wasm_binary_unwrap().to_vec(), ..Default::default() }, - balances: BalancesConfig { - balances: endowed_accounts.iter().cloned().map(|x| (x, ENDOWMENT)).collect(), - }, - indices: IndicesConfig { indices: vec![] }, - session: SessionConfig { - keys: initial_authorities - .iter() - .map(|x| { - ( - x.0.clone(), - x.0.clone(), - session_keys(x.2.clone(), x.3.clone(), x.4.clone(), x.5.clone()), - ) - }) - .collect::>(), - }, - staking: StakingConfig { - validator_count: initial_authorities.len() as u32, - minimum_validator_count: 0, - invulnerables: vec![], - slash_reward_fraction: Perbill::from_percent(10), - stakers, - ..Default::default() - }, - staking_extension: StakingExtensionConfig { - threshold_servers: vec![ - ( - get_account_id_from_seed::("Alice//stash"), - ( - // Seed phrase: "alarm mutual concert decrease hurry invest culture survey diagram crash snap click" - (*ALICE_TSS_ACCOUNT_ID).into(), - *entropy_shared::ALICE_X25519_PUBLIC_KEY, - "127.0.0.1:3001".as_bytes().to_vec(), - ), - ), - ( - get_account_id_from_seed::("Bob//stash"), - ( - // Seed phrase: "where sight patient orphan general short empower hope party hurt month voice" - (*BOB_TSS_ACCOUNT_ID).into(), - *entropy_shared::BOB_X25519_PUBLIC_KEY, - "127.0.0.1:3002".as_bytes().to_vec(), - ), - ), - ], - signing_groups: vec![ - (0, vec![get_account_id_from_seed::("Alice//stash")]), - (1, vec![get_account_id_from_seed::("Bob//stash")]), - ], - proactive_refresh_validators: vec![], - }, - democracy: DemocracyConfig::default(), - elections: ElectionsConfig { - members: endowed_accounts - .iter() - .take((num_endowed_accounts + 1) / 2) - .cloned() - .map(|member| (member, STASH)) - .collect(), - }, - council: CouncilConfig::default(), - technical_committee: TechnicalCommitteeConfig { - members: endowed_accounts - .iter() - .take((num_endowed_accounts + 1) / 2) - .cloned() - .collect(), - phantom: Default::default(), - }, - sudo: SudoConfig { key: Some(root_key) }, - babe: BabeConfig { - authorities: vec![], - epoch_config: Some(entropy_runtime::BABE_GENESIS_EPOCH_CONFIG), - ..Default::default() - }, - im_online: ImOnlineConfig { keys: vec![] }, - authority_discovery: AuthorityDiscoveryConfig { keys: vec![], ..Default::default() }, - grandpa: GrandpaConfig { authorities: vec![], ..Default::default() }, - technical_membership: Default::default(), - treasury: Default::default(), - relayer: RelayerConfig { - registered_accounts: vec![ - (get_account_id_from_seed::("Dave"), 0, None), - ( - get_account_id_from_seed::("Eve"), - 1, - Some([ - 28, 63, 144, 84, 78, 147, 195, 214, 190, 234, 111, 101, 117, 133, 9, 198, - 96, 96, 76, 140, 152, 251, 255, 28, 167, 38, 157, 185, 192, 42, 201, 82, - ]), - ), - (get_account_id_from_seed::("Ferdie"), 2, None), - ], - }, - vesting: Default::default(), - transaction_storage: Default::default(), - transaction_payment: Default::default(), - nomination_pools: Default::default(), - } -} - -/// Generates a [Substrate chain spec] for use during "[local devnet]" -/// operation to ensure proper startup of the network. -/// -/// Poper startup means informing each of the [chain nodes] that make -/// up the initial network participants of each other's reachable -/// network addresses, such thtat they can all find communicate with -/// one another, along with other information such as initial funding -/// balances, and the initial ("genesis") values of certain key data. -/// This network-wide, shared data is termed "on-chain storage." The -/// generated chain spec is thus the genesis data (initial values) of -/// the on-chain storage for the network. -/// -/// [Substrate chain spec]: https://docs.substrate.io/build/chain-spec/ -/// [local devnet]: https://github.com/entropyxyz/meta/wiki/Local-devnet -/// [chain nodes]: https://github.com/entropyxyz/meta/wiki/Glossary#chain-node -pub fn local_devnet_genesis( - initial_authorities: Vec<( - AccountId, - AccountId, - GrandpaId, - BabeId, - ImOnlineId, - AuthorityDiscoveryId, - )>, - initial_nominators: Vec, - root_key: AccountId, -) -> RuntimeGenesisConfig { - let mut endowed_accounts = endowed_accounts_dev(); - // endow all authorities and nominators. - initial_authorities.iter().map(|x| &x.0).chain(initial_nominators.iter()).for_each(|x| { - if !endowed_accounts.contains(x) { - endowed_accounts.push(x.clone()) - } - }); - - // stakers: all validators and nominators. - let mut rng = rand::thread_rng(); - let stakers = initial_authorities - .iter() - .map(|x| (x.0.clone(), x.1.clone(), STASH, StakerStatus::Validator)) - .chain(initial_nominators.iter().map(|x| { - use rand::{seq::SliceRandom, Rng}; - let limit = (MaxNominations::get() as usize).min(initial_authorities.len()); - let count = rng.gen::() % limit; - let nominations = initial_authorities - .as_slice() - .choose_multiple(&mut rng, count) - .map(|choice| choice.0.clone()) - .collect::>(); - (x.clone(), x.clone(), STASH, StakerStatus::Nominator(nominations)) - })) - .collect::>(); - - let num_endowed_accounts = endowed_accounts.len(); - - const ENDOWMENT: Balance = 10_000_000 * DOLLARS; - const STASH: Balance = ENDOWMENT / 1000; - - RuntimeGenesisConfig { - system: SystemConfig { code: wasm_binary_unwrap().to_vec(), ..Default::default() }, - balances: BalancesConfig { - balances: endowed_accounts.iter().cloned().map(|x| (x, ENDOWMENT)).collect(), - }, - indices: IndicesConfig { indices: vec![] }, - session: SessionConfig { - keys: initial_authorities - .iter() - .map(|x| { - ( - x.0.clone(), - x.0.clone(), - session_keys(x.2.clone(), x.3.clone(), x.4.clone(), x.5.clone()), - ) - }) - .collect::>(), - }, - staking: StakingConfig { - validator_count: initial_authorities.len() as u32, - minimum_validator_count: 0, - invulnerables: vec![], - slash_reward_fraction: Perbill::from_percent(10), - stakers, - ..Default::default() - }, - staking_extension: StakingExtensionConfig { - threshold_servers: vec![ - ( - get_account_id_from_seed::("Alice//stash"), - ( - // Seed phrase: "alarm mutual concert decrease hurry invest culture survey diagram crash snap click" - hex!["e0543c102def9f6ef0e8b8ffa31aa259167a9391566929fd718a1ccdaabdb876"] - .into(), - [ - 10, 192, 41, 240, 184, 83, 178, 59, 237, 101, 45, 109, 13, 230, 155, - 124, 195, 141, 148, 249, 55, 50, 238, 252, 133, 181, 134, 30, 144, 247, - 58, 34, - ], - "alice-tss-server:3001".as_bytes().to_vec(), - ), - ), - ( - get_account_id_from_seed::("Bob//stash"), - ( - // Seed phrase: "where sight patient orphan general short empower hope party hurt month voice" - hex!["2a8200850770290c7ea3b50a8ff64c6761c882ff8393dc95fccb5d1475eff17f"] - .into(), - [ - 225, 48, 135, 211, 227, 213, 170, 21, 1, 189, 118, 158, 255, 87, 245, - 89, 36, 170, 169, 181, 68, 201, 210, 178, 237, 247, 101, 80, 153, 136, - 102, 10, - ], - "bob-tss-server:3002".as_bytes().to_vec(), - ), - ), - ], - signing_groups: vec![ - (0, vec![get_account_id_from_seed::("Alice//stash")]), - (1, vec![get_account_id_from_seed::("Bob//stash")]), - ], - proactive_refresh_validators: vec![], - }, - democracy: DemocracyConfig::default(), - elections: ElectionsConfig { - members: endowed_accounts - .iter() - .take((num_endowed_accounts + 1) / 2) - .cloned() - .map(|member| (member, STASH)) - .collect(), - }, - council: CouncilConfig::default(), - technical_committee: TechnicalCommitteeConfig { - members: endowed_accounts - .iter() - .take((num_endowed_accounts + 1) / 2) - .cloned() - .collect(), - phantom: Default::default(), - }, - sudo: SudoConfig { key: Some(root_key) }, - babe: BabeConfig { - authorities: vec![], - epoch_config: Some(entropy_runtime::BABE_GENESIS_EPOCH_CONFIG), - ..Default::default() - }, - im_online: ImOnlineConfig { keys: vec![] }, - authority_discovery: AuthorityDiscoveryConfig { keys: vec![], ..Default::default() }, - grandpa: GrandpaConfig { authorities: vec![], ..Default::default() }, - technical_membership: Default::default(), - treasury: Default::default(), - relayer: RelayerConfig { - registered_accounts: vec![ - (get_account_id_from_seed::("Dave"), 0, None), - ( - get_account_id_from_seed::("Eve"), - 1, - Some([ - 28, 63, 144, 84, 78, 147, 195, 214, 190, 234, 111, 101, 117, 133, 9, 198, - 96, 96, 76, 140, 152, 251, 255, 28, 167, 38, 157, 185, 192, 42, 201, 82, - ]), - ), - (get_account_id_from_seed::("Ferdie"), 2, None), - ], - }, - vesting: Default::default(), - transaction_storage: Default::default(), - transaction_payment: Default::default(), - nomination_pools: Default::default(), - } -} - -/// Helper function to create GenesisConfig for testing -pub fn devnet_genesis( - initial_authorities: Vec<( - AccountId, - AccountId, - GrandpaId, - BabeId, - ImOnlineId, - AuthorityDiscoveryId, - )>, - initial_nominators: Vec, - root_key: AccountId, -) -> RuntimeGenesisConfig { - let mut endowed_accounts = endowed_accounts_devnet(); - // endow all authorities and nominators. - initial_authorities.iter().map(|x| &x.0).chain(initial_nominators.iter()).for_each(|x| { - if !endowed_accounts.contains(x) { - endowed_accounts.push(x.clone()) - } - }); - if !endowed_accounts.contains(&root_key) { - endowed_accounts.push(root_key.clone()) - } - // stakers: all validators and nominators. - let mut rng = rand::thread_rng(); - let stakers = initial_authorities - .iter() - .map(|x| (x.0.clone(), x.1.clone(), STASH, StakerStatus::Validator)) - .chain(initial_nominators.iter().map(|x| { - use rand::{seq::SliceRandom, Rng}; - let limit = (MaxNominations::get() as usize).min(initial_authorities.len()); - let count = rng.gen::() % limit; - let nominations = initial_authorities - .as_slice() - .choose_multiple(&mut rng, count) - .map(|choice| choice.0.clone()) - .collect::>(); - (x.clone(), x.clone(), STASH, StakerStatus::Nominator(nominations)) - })) - .collect::>(); - - let num_endowed_accounts = endowed_accounts.len(); - - const ENDOWMENT: Balance = 10_000_000 * DOLLARS; - const STASH: Balance = ENDOWMENT / 1000; - - RuntimeGenesisConfig { - system: SystemConfig { code: wasm_binary_unwrap().to_vec(), ..Default::default() }, - balances: BalancesConfig { - balances: endowed_accounts.iter().cloned().map(|x| (x, ENDOWMENT)).collect(), - }, - indices: IndicesConfig { indices: vec![] }, - session: SessionConfig { - keys: initial_authorities - .iter() - .map(|x| { - ( - x.0.clone(), - x.0.clone(), - session_keys(x.2.clone(), x.3.clone(), x.4.clone(), x.5.clone()), - ) - }) - .collect::>(), - }, - staking: StakingConfig { - validator_count: initial_authorities.len() as u32, - minimum_validator_count: 0, - invulnerables: initial_authorities.iter().map(|x| x.0.clone()).collect(), - slash_reward_fraction: Perbill::from_percent(10), - stakers, - ..Default::default() - }, - staking_extension: StakingExtensionConfig { - threshold_servers: vec![], - signing_groups: vec![], - proactive_refresh_validators: vec![], - }, - democracy: DemocracyConfig::default(), - elections: ElectionsConfig { - members: endowed_accounts - .iter() - .take((num_endowed_accounts + 1) / 2) - .cloned() - .map(|member| (member, STASH)) - .collect(), - }, - council: CouncilConfig::default(), - technical_committee: TechnicalCommitteeConfig { - members: endowed_accounts - .iter() - .take((num_endowed_accounts + 1) / 2) - .cloned() - .collect(), - phantom: Default::default(), - }, - sudo: SudoConfig { key: Some(root_key) }, - babe: BabeConfig { - authorities: vec![], - epoch_config: Some(entropy_runtime::BABE_GENESIS_EPOCH_CONFIG), - ..Default::default() - }, - im_online: ImOnlineConfig { keys: vec![] }, - authority_discovery: AuthorityDiscoveryConfig { keys: vec![], ..Default::default() }, - grandpa: GrandpaConfig { authorities: vec![], ..Default::default() }, - technical_membership: Default::default(), - treasury: Default::default(), - relayer: RelayerConfig { registered_accounts: vec![] }, - vesting: Default::default(), - transaction_storage: Default::default(), - transaction_payment: Default::default(), - nomination_pools: Default::default(), - } +pub fn testing_config_genesis() -> RuntimeGenesisConfig { + testing( + vec![authority_keys_from_seed("Alice"), authority_keys_from_seed("Bob")], + vec![], + get_account_id_from_seed::("Alice"), + ) } /// Helper function to create RuntimeGenesisConfig for testing @@ -805,60 +356,3 @@ pub fn testing( nomination_pools: Default::default(), } } - -/// Local devnet configuration, used when invoked with the -/// `--chain local-devnet` option. -pub fn local_devnet_config() -> ChainSpec { - ChainSpec::from_genesis( - "Entropy Local Devnet", - "EDevLocal", - ChainType::Development, - admin::local_devnet_config_genesis, - vec![], - None, - None, - None, - None, - Default::default(), - ) -} - -/// Testing config (single validator Alice) -pub fn testing_config() -> ChainSpec { - ChainSpec::from_genesis( - "Testing", - "test", - ChainType::Development, - admin::testing_config_genesis, - vec![], - None, - None, - None, - None, - Default::default(), - ) -} - -fn local_testnet_genesis() -> RuntimeGenesisConfig { - testnet_genesis( - vec![authority_keys_from_seed("Alice"), authority_keys_from_seed("Bob")], - vec![], - get_account_id_from_seed::("Alice"), - ) -} - -/// Local testnet config (multivalidator Alice + Bob) -pub fn local_testnet_config() -> ChainSpec { - ChainSpec::from_genesis( - "Local Testnet", - "local_testnet", - ChainType::Local, - local_testnet_genesis, - vec![], - None, - None, - None, - None, - Default::default(), - ) -} diff --git a/node/cli/src/endowed_accounts.rs b/node/cli/src/endowed_accounts.rs index c528d93c3..eefc2b0f0 100644 --- a/node/cli/src/endowed_accounts.rs +++ b/node/cli/src/endowed_accounts.rs @@ -42,10 +42,3 @@ pub fn endowed_accounts_dev() -> Vec { hex!["14d223daeec68671f07298c66c9458980a48bb89fb8a85d5df31131acad8d611"].into(), ] } - -pub fn endowed_accounts_devnet() -> Vec { - vec![ - // random placeholder - // hex!["a617f1a88de5efbaefaafdf4d02818e00b6bb45c673c2dedca447b62dad2a26d"].into(), - ] -} From 1d08f61e394fa71856abf44dfa2c716eec07a510 Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Mon, 15 Jan 2024 17:16:00 -0700 Subject: [PATCH 09/28] Clean up `--chain` options This make `--dev` the default option if no chain is passed in. In the future we'll may want to change this to be our mainnet. --- node/cli/src/command.rs | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/node/cli/src/command.rs b/node/cli/src/command.rs index 4b5a399d2..f5f713aad 100644 --- a/node/cli/src/command.rs +++ b/node/cli/src/command.rs @@ -67,36 +67,19 @@ impl SubstrateCli for Cli { 2022 } - // dev -> one node, Alice - // - // testnet-dev, one node, Alice - // testnet-local, two nodes, Alice + Bob - // testnet-staging -> four nodes, secret seeds <-- This is what we're doing now basically - // testnet -> production spec, four nodes, secret seed <-- Maybe merge with above - // // | --chain | Description | // |-----------------|----------- | // | dev | Single node, Alice, Development Configuration | - // | testnet-dev | Single node, Alice, Testnet Configuration | // | testnet-local | Two Nodes, Alice and Bob, Testnet Configuration | - // | testnet-staging | Four Nodes, Own Seed, Testnet Configuration | + // | testnet | Four Nodes, Own Seed, Testnet Configuration | fn load_spec(&self, id: &str) -> Result, String> { Ok(match id { - "dev" => Box::new(chain_spec::dev::development_config()), + "" | "dev" => Box::new(chain_spec::dev::development_config()), "testnet-local" => Box::new(chain_spec::testnet::testnet_local_config()), "testnet" => Box::new(chain_spec::testnet::testnet_config()), - _ => unimplemented!(), - // "testnet-dev" => Box::new(chain_spec::testnet_config()), - // "testnet-local" => Box::new(chain_spec::testnet_config()), - // "testnet" => Box::new(chain_spec::testnet_config()), - - // "test" => Box::new(chain_spec::testing_config()), - // "local-devnet" => Box::new(chain_spec::local_devnet_config()), - // "" | "local" => Box::new(chain_spec::local_testnet_config()), - // "testnet" => Box::new(chain_spec::testnet_config()), - // path => { - // Box::new(chain_spec::ChainSpec::from_json_file(std::path::PathBuf::from(path))?) - // }, + path => { + Box::new(chain_spec::ChainSpec::from_json_file(std::path::PathBuf::from(path))?) + }, }) } } From 7523d3acbefc3ee54abdfc7517e0dbf12d9c9fd8 Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Mon, 15 Jan 2024 17:48:53 -0700 Subject: [PATCH 10/28] TaploFmt --- crates/shared/Cargo.toml | 2 +- node/cli/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/shared/Cargo.toml b/crates/shared/Cargo.toml index 45d09a6e9..b8eda6c5e 100644 --- a/crates/shared/Cargo.toml +++ b/crates/shared/Cargo.toml @@ -15,7 +15,7 @@ serde_derive ="1.0.147" sp-std ={ package="sp-std", git="https://github.com/paritytech/substrate", branch="polkadot-v1.0.0", default-features=false } frame-support ={ package="frame-support", git="https://github.com/paritytech/substrate", branch="polkadot-v1.0.0", default-features=false, optional=true } node-primitives={ version="2.0.0", default-features=false, git='https://github.com/paritytech/substrate.git', branch="polkadot-v1.0.0", optional=true } -lazy_static = { version = "1.4.0", features = ["spin_no_std"] } +lazy_static ={ version="1.4.0", features=["spin_no_std"] } [features] default=["std"] diff --git a/node/cli/Cargo.toml b/node/cli/Cargo.toml index 0739aae10..3246da7f3 100644 --- a/node/cli/Cargo.toml +++ b/node/cli/Cargo.toml @@ -19,7 +19,7 @@ name='entropy' jsonrpc-core ='18.0.0' serde_json ='1.0.0' log ="0.4.17" -lazy_static = { version = "1.4.0", features = ["spin_no_std"] } +lazy_static ={ version="1.4.0", features=["spin_no_std"] } clap ={ version="4.0.9", features=["derive"], optional=true } codec ={ package="parity-scale-codec", version="3.0.0" } structopt ='0.3.8' From e22791d9ad157f31020df60984b36df57f23a15b Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Tue, 16 Jan 2024 16:18:06 -0700 Subject: [PATCH 11/28] Move testing configuration to own module Ideally I'd want this to be the same as the `dev` config, but let's leave it this way for now. --- node/cli/src/chain_spec/mod.rs | 237 +----------------------- node/cli/src/chain_spec/testing.rs | 286 +++++++++++++++++++++++++++++ node/cli/src/command.rs | 1 + 3 files changed, 290 insertions(+), 234 deletions(-) create mode 100644 node/cli/src/chain_spec/testing.rs diff --git a/node/cli/src/chain_spec/mod.rs b/node/cli/src/chain_spec/mod.rs index 14380bb7a..c561b512b 100644 --- a/node/cli/src/chain_spec/mod.rs +++ b/node/cli/src/chain_spec/mod.rs @@ -34,17 +34,11 @@ #![allow(dead_code)] pub mod dev; +pub mod testing; pub mod testnet; pub use entropy_runtime::RuntimeGenesisConfig; -use entropy_runtime::{ - constants::currency::*, wasm_binary_unwrap, AuthorityDiscoveryConfig, BabeConfig, - BalancesConfig, Block, CouncilConfig, DemocracyConfig, ElectionsConfig, GrandpaConfig, - ImOnlineConfig, IndicesConfig, MaxNominations, RelayerConfig, SessionConfig, SessionKeys, - StakerStatus, StakingConfig, StakingExtensionConfig, SudoConfig, SystemConfig, - TechnicalCommitteeConfig, -}; -use entropy_shared::ValidatorInfo; +use entropy_runtime::{Block, SessionKeys}; use grandpa_primitives::AuthorityId as GrandpaId; use hex_literal::hex; pub use node_primitives::{AccountId, Balance, Signature}; @@ -55,12 +49,8 @@ use serde_json::json; use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId; use sp_consensus_babe::AuthorityId as BabeId; use sp_core::{sr25519, Pair, Public}; -use sp_runtime::{ - traits::{IdentifyAccount, Verify}, - Perbill, -}; +use sp_runtime::traits::{IdentifyAccount, Verify}; -use crate::endowed_accounts::endowed_accounts_dev; type AccountPublic = ::Signer; const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/"; @@ -135,224 +125,3 @@ pub fn authority_keys_from_seed( get_from_seed::(seed), ) } - -pub fn testing_config_genesis() -> RuntimeGenesisConfig { - testing( - vec![authority_keys_from_seed("Alice"), authority_keys_from_seed("Bob")], - vec![], - get_account_id_from_seed::("Alice"), - ) -} - -/// Helper function to create RuntimeGenesisConfig for testing -pub fn testing( - initial_authorities: Vec<( - AccountId, - AccountId, - GrandpaId, - BabeId, - ImOnlineId, - AuthorityDiscoveryId, - )>, - initial_nominators: Vec, - root_key: AccountId, -) -> RuntimeGenesisConfig { - let mut endowed_accounts = endowed_accounts_dev(); - // endow all authorities and nominators. - initial_authorities.iter().map(|x| &x.0).chain(initial_nominators.iter()).for_each(|x| { - if !endowed_accounts.contains(x) { - endowed_accounts.push(x.clone()) - } - }); - - // stakers: all validators and nominators. - let mut rng = rand::thread_rng(); - let stakers = initial_authorities - .iter() - .map(|x| (x.0.clone(), x.1.clone(), STASH, StakerStatus::Validator)) - .chain(initial_nominators.iter().map(|x| { - use rand::{seq::SliceRandom, Rng}; - let limit = (MaxNominations::get() as usize).min(initial_authorities.len()); - let count = rng.gen::() % limit; - let nominations = initial_authorities - .as_slice() - .choose_multiple(&mut rng, count) - .map(|choice| choice.0.clone()) - .collect::>(); - (x.clone(), x.clone(), STASH, StakerStatus::Nominator(nominations)) - })) - .collect::>(); - - let num_endowed_accounts = endowed_accounts.len(); - - const ENDOWMENT: Balance = 10_000_000 * DOLLARS; - const STASH: Balance = ENDOWMENT / 1000; - - RuntimeGenesisConfig { - system: SystemConfig { code: wasm_binary_unwrap().to_vec(), ..Default::default() }, - balances: BalancesConfig { - balances: endowed_accounts.iter().cloned().map(|x| (x, ENDOWMENT)).collect(), - }, - indices: IndicesConfig { indices: vec![] }, - session: SessionConfig { - keys: initial_authorities - .iter() - .map(|x| { - ( - x.0.clone(), - x.0.clone(), - session_keys(x.2.clone(), x.3.clone(), x.4.clone(), x.5.clone()), - ) - }) - .collect::>(), - }, - staking: StakingConfig { - validator_count: initial_authorities.len() as u32, - minimum_validator_count: 0, - invulnerables: vec![], - slash_reward_fraction: Perbill::from_percent(10), - stakers, - ..Default::default() - }, - staking_extension: StakingExtensionConfig { - threshold_servers: vec![ - ( - get_account_id_from_seed::("Alice//stash"), - ( - // Seed phrase: "alarm mutual concert decrease hurry invest culture survey diagram crash snap click" - hex!["e0543c102def9f6ef0e8b8ffa31aa259167a9391566929fd718a1ccdaabdb876"] - .into(), - [ - 10, 192, 41, 240, 184, 83, 178, 59, 237, 101, 45, 109, 13, 230, 155, - 124, 195, 141, 148, 249, 55, 50, 238, 252, 133, 181, 134, 30, 144, 247, - 58, 34, - ], - "127.0.0.1:3001".as_bytes().to_vec(), - ), - ), - ( - get_account_id_from_seed::("Bob//stash"), - ( - // Seed phrase: "where sight patient orphan general short empower hope party hurt month voice" - hex!["2a8200850770290c7ea3b50a8ff64c6761c882ff8393dc95fccb5d1475eff17f"] - .into(), - [ - 225, 48, 135, 211, 227, 213, 170, 21, 1, 189, 118, 158, 255, 87, 245, - 89, 36, 170, 169, 181, 68, 201, 210, 178, 237, 247, 101, 80, 153, 136, - 102, 10, - ], - "127.0.0.1:3002".as_bytes().to_vec(), - ), - ), - ( - // Seed phrase: "lake carry still awful point mention bike category tornado plate brass lock" - get_account_id_from_seed::("Charlie//stash"), - ( - hex!["14d223daeec68671f07298c66c9458980a48bb89fb8a85d5df31131acad8d611"] - .into(), - [ - 225, 48, 135, 211, 227, 213, 170, 21, 1, 189, 118, 158, 255, 87, 245, - 89, 36, 170, 169, 181, 68, 201, 210, 178, 237, 247, 101, 80, 153, 136, - 102, 10, - ], - "127.0.0.1:3002".as_bytes().to_vec(), - ), - ), - ( - get_account_id_from_seed::("Dave//stash"), - ( - hex!["5212c5f562f4a43b89caadfeb9f5896dd4084700afa72aa55ca306d689523f3a"] - .into(), - [ - 225, 48, 135, 211, 227, 213, 170, 21, 1, 189, 118, 158, 255, 87, 245, - 89, 36, 170, 169, 181, 68, 201, 210, 178, 237, 247, 101, 80, 153, 136, - 102, 10, - ], - "127.0.0.1:3002".as_bytes().to_vec(), - ), - ), - ], - signing_groups: vec![ - ( - 0, - vec![ - get_account_id_from_seed::("Alice//stash"), - get_account_id_from_seed::("Charlie//stash"), - ], - ), - (1, vec![get_account_id_from_seed::("Bob//stash")]), - ], - proactive_refresh_validators: vec![ - ValidatorInfo { - tss_account: hex![ - "e0543c102def9f6ef0e8b8ffa31aa259167a9391566929fd718a1ccdaabdb876" - ] - .into(), - ip_address: "127.0.0.1:3001".as_bytes().to_vec(), - x25519_public_key: [ - 10, 192, 41, 240, 184, 83, 178, 59, 237, 101, 45, 109, 13, 230, 155, 124, - 195, 141, 148, 249, 55, 50, 238, 252, 133, 181, 134, 30, 144, 247, 58, 34, - ], - }, - ValidatorInfo { - tss_account: hex![ - "2a8200850770290c7ea3b50a8ff64c6761c882ff8393dc95fccb5d1475eff17f" - ] - .into(), - ip_address: "127.0.0.1:3002".as_bytes().to_vec(), - x25519_public_key: [ - 225, 48, 135, 211, 227, 213, 170, 21, 1, 189, 118, 158, 255, 87, 245, 89, - 36, 170, 169, 181, 68, 201, 210, 178, 237, 247, 101, 80, 153, 136, 102, 10, - ], - }, - ], - }, - democracy: DemocracyConfig::default(), - elections: ElectionsConfig { - members: endowed_accounts - .iter() - .take((num_endowed_accounts + 1) / 2) - .cloned() - .map(|member| (member, STASH)) - .collect(), - }, - council: CouncilConfig::default(), - technical_committee: TechnicalCommitteeConfig { - members: endowed_accounts - .iter() - .take((num_endowed_accounts + 1) / 2) - .cloned() - .collect(), - phantom: Default::default(), - }, - sudo: SudoConfig { key: Some(root_key) }, - babe: BabeConfig { - authorities: vec![], - epoch_config: Some(entropy_runtime::BABE_GENESIS_EPOCH_CONFIG), - ..Default::default() - }, - im_online: ImOnlineConfig { keys: vec![] }, - authority_discovery: AuthorityDiscoveryConfig { keys: vec![], ..Default::default() }, - grandpa: GrandpaConfig { authorities: vec![], ..Default::default() }, - technical_membership: Default::default(), - treasury: Default::default(), - relayer: RelayerConfig { - registered_accounts: vec![ - (get_account_id_from_seed::("Dave"), 0, None), - ( - get_account_id_from_seed::("Eve"), - 1, - Some([ - 28, 63, 144, 84, 78, 147, 195, 214, 190, 234, 111, 101, 117, 133, 9, 198, - 96, 96, 76, 140, 152, 251, 255, 28, 167, 38, 157, 185, 192, 42, 201, 82, - ]), - ), - (get_account_id_from_seed::("Ferdie"), 2, None), - ], - }, - vesting: Default::default(), - transaction_storage: Default::default(), - transaction_payment: Default::default(), - nomination_pools: Default::default(), - } -} diff --git a/node/cli/src/chain_spec/testing.rs b/node/cli/src/chain_spec/testing.rs new file mode 100644 index 000000000..1cf916caf --- /dev/null +++ b/node/cli/src/chain_spec/testing.rs @@ -0,0 +1,286 @@ +// Copyright (C) 2023 Entropy Cryptography Inc. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +use crate::endowed_accounts::endowed_accounts_dev; +pub use entropy_runtime::RuntimeGenesisConfig; +use entropy_runtime::{ + constants::currency::*, wasm_binary_unwrap, AuthorityDiscoveryConfig, BabeConfig, + BalancesConfig, CouncilConfig, DemocracyConfig, ElectionsConfig, GrandpaConfig, ImOnlineConfig, + IndicesConfig, MaxNominations, RelayerConfig, SessionConfig, StakerStatus, StakingConfig, + StakingExtensionConfig, SudoConfig, SystemConfig, TechnicalCommitteeConfig, +}; +use grandpa_primitives::AuthorityId as GrandpaId; +use hex_literal::hex; +pub use node_primitives::{AccountId, Balance, Signature}; +use pallet_im_online::sr25519::AuthorityId as ImOnlineId; +use sc_service::ChainType; +use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId; +use sp_consensus_babe::AuthorityId as BabeId; +use sp_core::sr25519; +use sp_runtime::Perbill; + +/// Testing config (single validator Alice) +pub fn testing_config() -> crate::chain_spec::ChainSpec { + crate::chain_spec::ChainSpec::from_genesis( + "Testing", + "test", + ChainType::Development, + || { + testing_genesis_config( + vec![ + crate::chain_spec::authority_keys_from_seed("Alice"), + crate::chain_spec::authority_keys_from_seed("Bob"), + ], + vec![], + crate::chain_spec::get_account_id_from_seed::("Alice"), + ) + }, + vec![], + None, + None, + None, + None, + Default::default(), + ) +} + +/// Helper function to create RuntimeGenesisConfig for testing +pub fn testing_genesis_config( + initial_authorities: Vec<( + AccountId, + AccountId, + GrandpaId, + BabeId, + ImOnlineId, + AuthorityDiscoveryId, + )>, + initial_nominators: Vec, + root_key: AccountId, +) -> RuntimeGenesisConfig { + let mut endowed_accounts = endowed_accounts_dev(); + // endow all authorities and nominators. + initial_authorities.iter().map(|x| &x.0).chain(initial_nominators.iter()).for_each(|x| { + if !endowed_accounts.contains(x) { + endowed_accounts.push(x.clone()) + } + }); + + // stakers: all validators and nominators. + let mut rng = rand::thread_rng(); + let stakers = initial_authorities + .iter() + .map(|x| (x.0.clone(), x.1.clone(), STASH, StakerStatus::Validator)) + .chain(initial_nominators.iter().map(|x| { + use rand::{seq::SliceRandom, Rng}; + let limit = (MaxNominations::get() as usize).min(initial_authorities.len()); + let count = rng.gen::() % limit; + let nominations = initial_authorities + .as_slice() + .choose_multiple(&mut rng, count) + .map(|choice| choice.0.clone()) + .collect::>(); + (x.clone(), x.clone(), STASH, StakerStatus::Nominator(nominations)) + })) + .collect::>(); + + let num_endowed_accounts = endowed_accounts.len(); + + const ENDOWMENT: Balance = 10_000_000 * DOLLARS; + const STASH: Balance = ENDOWMENT / 1000; + + RuntimeGenesisConfig { + system: SystemConfig { code: wasm_binary_unwrap().to_vec(), ..Default::default() }, + balances: BalancesConfig { + balances: endowed_accounts.iter().cloned().map(|x| (x, ENDOWMENT)).collect(), + }, + indices: IndicesConfig { indices: vec![] }, + session: SessionConfig { + keys: initial_authorities + .iter() + .map(|x| { + ( + x.0.clone(), + x.0.clone(), + crate::chain_spec::session_keys( + x.2.clone(), + x.3.clone(), + x.4.clone(), + x.5.clone(), + ), + ) + }) + .collect::>(), + }, + staking: StakingConfig { + validator_count: initial_authorities.len() as u32, + minimum_validator_count: 0, + invulnerables: vec![], + slash_reward_fraction: Perbill::from_percent(10), + stakers, + ..Default::default() + }, + staking_extension: StakingExtensionConfig { + threshold_servers: vec![ + ( + crate::chain_spec::get_account_id_from_seed::("Alice//stash"), + ( + // Seed phrase: "alarm mutual concert decrease hurry invest culture survey diagram crash snap click" + hex!["e0543c102def9f6ef0e8b8ffa31aa259167a9391566929fd718a1ccdaabdb876"] + .into(), + [ + 10, 192, 41, 240, 184, 83, 178, 59, 237, 101, 45, 109, 13, 230, 155, + 124, 195, 141, 148, 249, 55, 50, 238, 252, 133, 181, 134, 30, 144, 247, + 58, 34, + ], + "127.0.0.1:3001".as_bytes().to_vec(), + ), + ), + ( + crate::chain_spec::get_account_id_from_seed::("Bob//stash"), + ( + // Seed phrase: "where sight patient orphan general short empower hope party hurt month voice" + hex!["2a8200850770290c7ea3b50a8ff64c6761c882ff8393dc95fccb5d1475eff17f"] + .into(), + [ + 225, 48, 135, 211, 227, 213, 170, 21, 1, 189, 118, 158, 255, 87, 245, + 89, 36, 170, 169, 181, 68, 201, 210, 178, 237, 247, 101, 80, 153, 136, + 102, 10, + ], + "127.0.0.1:3002".as_bytes().to_vec(), + ), + ), + ( + // Seed phrase: "lake carry still awful point mention bike category tornado plate brass lock" + crate::chain_spec::get_account_id_from_seed::( + "Charlie//stash", + ), + ( + hex!["14d223daeec68671f07298c66c9458980a48bb89fb8a85d5df31131acad8d611"] + .into(), + [ + 225, 48, 135, 211, 227, 213, 170, 21, 1, 189, 118, 158, 255, 87, 245, + 89, 36, 170, 169, 181, 68, 201, 210, 178, 237, 247, 101, 80, 153, 136, + 102, 10, + ], + "127.0.0.1:3002".as_bytes().to_vec(), + ), + ), + ( + crate::chain_spec::get_account_id_from_seed::("Dave//stash"), + ( + hex!["5212c5f562f4a43b89caadfeb9f5896dd4084700afa72aa55ca306d689523f3a"] + .into(), + [ + 225, 48, 135, 211, 227, 213, 170, 21, 1, 189, 118, 158, 255, 87, 245, + 89, 36, 170, 169, 181, 68, 201, 210, 178, 237, 247, 101, 80, 153, 136, + 102, 10, + ], + "127.0.0.1:3002".as_bytes().to_vec(), + ), + ), + ], + signing_groups: vec![ + ( + 0, + vec![ + crate::chain_spec::get_account_id_from_seed::( + "Alice//stash", + ), + crate::chain_spec::get_account_id_from_seed::( + "Charlie//stash", + ), + ], + ), + ( + 1, + vec![crate::chain_spec::get_account_id_from_seed::( + "Bob//stash", + )], + ), + ], + proactive_refresh_validators: vec![ + entropy_shared::ValidatorInfo { + tss_account: hex![ + "e0543c102def9f6ef0e8b8ffa31aa259167a9391566929fd718a1ccdaabdb876" + ] + .into(), + ip_address: "127.0.0.1:3001".as_bytes().to_vec(), + x25519_public_key: [ + 10, 192, 41, 240, 184, 83, 178, 59, 237, 101, 45, 109, 13, 230, 155, 124, + 195, 141, 148, 249, 55, 50, 238, 252, 133, 181, 134, 30, 144, 247, 58, 34, + ], + }, + entropy_shared::ValidatorInfo { + tss_account: hex![ + "2a8200850770290c7ea3b50a8ff64c6761c882ff8393dc95fccb5d1475eff17f" + ] + .into(), + ip_address: "127.0.0.1:3002".as_bytes().to_vec(), + x25519_public_key: [ + 225, 48, 135, 211, 227, 213, 170, 21, 1, 189, 118, 158, 255, 87, 245, 89, + 36, 170, 169, 181, 68, 201, 210, 178, 237, 247, 101, 80, 153, 136, 102, 10, + ], + }, + ], + }, + democracy: DemocracyConfig::default(), + elections: ElectionsConfig { + members: endowed_accounts + .iter() + .take((num_endowed_accounts + 1) / 2) + .cloned() + .map(|member| (member, STASH)) + .collect(), + }, + council: CouncilConfig::default(), + technical_committee: TechnicalCommitteeConfig { + members: endowed_accounts + .iter() + .take((num_endowed_accounts + 1) / 2) + .cloned() + .collect(), + phantom: Default::default(), + }, + sudo: SudoConfig { key: Some(root_key) }, + babe: BabeConfig { + authorities: vec![], + epoch_config: Some(entropy_runtime::BABE_GENESIS_EPOCH_CONFIG), + ..Default::default() + }, + im_online: ImOnlineConfig { keys: vec![] }, + authority_discovery: AuthorityDiscoveryConfig { keys: vec![], ..Default::default() }, + grandpa: GrandpaConfig { authorities: vec![], ..Default::default() }, + technical_membership: Default::default(), + treasury: Default::default(), + relayer: RelayerConfig { + registered_accounts: vec![ + (crate::chain_spec::get_account_id_from_seed::("Dave"), 0, None), + ( + crate::chain_spec::get_account_id_from_seed::("Eve"), + 1, + Some([ + 28, 63, 144, 84, 78, 147, 195, 214, 190, 234, 111, 101, 117, 133, 9, 198, + 96, 96, 76, 140, 152, 251, 255, 28, 167, 38, 157, 185, 192, 42, 201, 82, + ]), + ), + (crate::chain_spec::get_account_id_from_seed::("Ferdie"), 2, None), + ], + }, + vesting: Default::default(), + transaction_storage: Default::default(), + transaction_payment: Default::default(), + nomination_pools: Default::default(), + } +} diff --git a/node/cli/src/command.rs b/node/cli/src/command.rs index f5f713aad..56e83c27b 100644 --- a/node/cli/src/command.rs +++ b/node/cli/src/command.rs @@ -75,6 +75,7 @@ impl SubstrateCli for Cli { fn load_spec(&self, id: &str) -> Result, String> { Ok(match id { "" | "dev" => Box::new(chain_spec::dev::development_config()), + "test" => Box::new(chain_spec::testing::testing_config()), "testnet-local" => Box::new(chain_spec::testnet::testnet_local_config()), "testnet" => Box::new(chain_spec::testnet::testnet_config()), path => { From 32a964836c0ec30f2bc35fb844c7424979019796 Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Tue, 16 Jan 2024 16:29:56 -0700 Subject: [PATCH 12/28] Rename `test` chainspec to `integration_tests` --- crates/testing-utils/src/substrate_context.rs | 2 +- .../cli/src/chain_spec/{testing.rs => integration_tests.rs} | 6 +++--- node/cli/src/chain_spec/mod.rs | 2 +- node/cli/src/command.rs | 4 +++- 4 files changed, 8 insertions(+), 6 deletions(-) rename node/cli/src/chain_spec/{testing.rs => integration_tests.rs} (98%) diff --git a/crates/testing-utils/src/substrate_context.rs b/crates/testing-utils/src/substrate_context.rs index b4cdb7cfb..2382cb0fd 100644 --- a/crates/testing-utils/src/substrate_context.rs +++ b/crates/testing-utils/src/substrate_context.rs @@ -103,7 +103,7 @@ pub async fn test_node_process_stationary() -> TestNodeProcess { pub async fn test_node_process_testing_state( force_authoring: bool, ) -> TestNodeProcess { - test_node(AccountKeyring::Alice, "--chain=test".to_string(), force_authoring).await + test_node(AccountKeyring::Alice, "--chain=integration-tests".to_string(), force_authoring).await } /// Spins up Substrate node and a connected `subxt` client. diff --git a/node/cli/src/chain_spec/testing.rs b/node/cli/src/chain_spec/integration_tests.rs similarity index 98% rename from node/cli/src/chain_spec/testing.rs rename to node/cli/src/chain_spec/integration_tests.rs index 1cf916caf..1069dfbfa 100644 --- a/node/cli/src/chain_spec/testing.rs +++ b/node/cli/src/chain_spec/integration_tests.rs @@ -32,13 +32,13 @@ use sp_core::sr25519; use sp_runtime::Perbill; /// Testing config (single validator Alice) -pub fn testing_config() -> crate::chain_spec::ChainSpec { +pub fn integration_tests_config() -> crate::chain_spec::ChainSpec { crate::chain_spec::ChainSpec::from_genesis( "Testing", "test", ChainType::Development, || { - testing_genesis_config( + integration_tests_genesis_config( vec![ crate::chain_spec::authority_keys_from_seed("Alice"), crate::chain_spec::authority_keys_from_seed("Bob"), @@ -57,7 +57,7 @@ pub fn testing_config() -> crate::chain_spec::ChainSpec { } /// Helper function to create RuntimeGenesisConfig for testing -pub fn testing_genesis_config( +pub fn integration_tests_genesis_config( initial_authorities: Vec<( AccountId, AccountId, diff --git a/node/cli/src/chain_spec/mod.rs b/node/cli/src/chain_spec/mod.rs index c561b512b..145ddd2eb 100644 --- a/node/cli/src/chain_spec/mod.rs +++ b/node/cli/src/chain_spec/mod.rs @@ -34,7 +34,7 @@ #![allow(dead_code)] pub mod dev; -pub mod testing; +pub mod integration_tests; pub mod testnet; pub use entropy_runtime::RuntimeGenesisConfig; diff --git a/node/cli/src/command.rs b/node/cli/src/command.rs index 56e83c27b..e6574d00f 100644 --- a/node/cli/src/command.rs +++ b/node/cli/src/command.rs @@ -75,7 +75,9 @@ impl SubstrateCli for Cli { fn load_spec(&self, id: &str) -> Result, String> { Ok(match id { "" | "dev" => Box::new(chain_spec::dev::development_config()), - "test" => Box::new(chain_spec::testing::testing_config()), + "integration-tests" => { + Box::new(chain_spec::integration_tests::integration_tests_config()) + }, "testnet-local" => Box::new(chain_spec::testnet::testnet_local_config()), "testnet" => Box::new(chain_spec::testnet::testnet_config()), path => { From eb6ca1b33ab642a97a327662ddcca08e8b0f220c Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Tue, 16 Jan 2024 17:04:59 -0700 Subject: [PATCH 13/28] Move X25519 public keys into consts and own module --- Cargo.lock | 1 - crates/shared/Cargo.toml | 1 - crates/shared/src/lib.rs | 21 ------------- crates/testing-utils/src/constants.rs | 1 - node/cli/src/chain_spec/dev.rs | 6 ++-- node/cli/src/chain_spec/integration_tests.rs | 32 ++++---------------- node/cli/src/chain_spec/mod.rs | 32 ++++++++++++++++++-- node/cli/src/chain_spec/testnet.rs | 10 +++--- 8 files changed, 42 insertions(+), 62 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4e04631a9..2ac5d68eb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2701,7 +2701,6 @@ name = "entropy-shared" version = "0.1.0" dependencies = [ "frame-support", - "lazy_static", "node-primitives", "parity-scale-codec", "scale-info", diff --git a/crates/shared/Cargo.toml b/crates/shared/Cargo.toml index b8eda6c5e..bf8b254da 100644 --- a/crates/shared/Cargo.toml +++ b/crates/shared/Cargo.toml @@ -15,7 +15,6 @@ serde_derive ="1.0.147" sp-std ={ package="sp-std", git="https://github.com/paritytech/substrate", branch="polkadot-v1.0.0", default-features=false } frame-support ={ package="frame-support", git="https://github.com/paritytech/substrate", branch="polkadot-v1.0.0", default-features=false, optional=true } node-primitives={ version="2.0.0", default-features=false, git='https://github.com/paritytech/substrate.git', branch="polkadot-v1.0.0", optional=true } -lazy_static ={ version="1.4.0", features=["spin_no_std"] } [features] default=["std"] diff --git a/crates/shared/src/lib.rs b/crates/shared/src/lib.rs index f3c2a8c78..b775c69f2 100644 --- a/crates/shared/src/lib.rs +++ b/crates/shared/src/lib.rs @@ -39,24 +39,3 @@ pub const REFRESHES_PER_SESSION: u32 = 10; /// Max instructions per wasm program pub const MAX_INSTRUCTIONS_PER_PROGRAM: u64 = 10_000; - -// TODO: This should only be used for non-production things... -lazy_static::lazy_static! { - - // Used `DEFAULT_ALICE_MNEMONIC` to generate this - // Mnemonic: "alarm mutual concert decrease hurry invest culture survey diagram crash snap click" - pub static ref ALICE_X25519_PUBLIC_KEY: [u8; 32] = [ - 10, 192, 41, 240, 184, 83, 178, 59, 237, 101, 45, 109, 13, 230, 155, 124, 195, 141, 148, - 249, 55, 50, 238, 252, 133, 181, 134, 30, 144, 247, 58, 34, - - ]; - - // Used `DEFAULT_BOB_MNEMONIC` to generate this - // Mnemonic: "where sight patient orphan general short empower hope party hurt month voice" - pub static ref BOB_X25519_PUBLIC_KEY: [u8; 32] = [ - 225, 48, 135, 211, 227, 213, 170, 21, 1, 189, 118, 158, 255, 87, 245, 89, 36, 170, 169, - 181, 68, 201, 210, 178, 237, 247, 101, 80, 153, 136, 102, 10, - - ]; - -} diff --git a/crates/testing-utils/src/constants.rs b/crates/testing-utils/src/constants.rs index 303567648..1caaa4558 100644 --- a/crates/testing-utils/src/constants.rs +++ b/crates/testing-utils/src/constants.rs @@ -41,7 +41,6 @@ lazy_static! { .try_into() .unwrap(), ]; - } /// The following constants are values used for integration testing specific to the diff --git a/node/cli/src/chain_spec/dev.rs b/node/cli/src/chain_spec/dev.rs index 880fa8ab6..0b065492a 100644 --- a/node/cli/src/chain_spec/dev.rs +++ b/node/cli/src/chain_spec/dev.rs @@ -135,18 +135,16 @@ pub fn development_genesis_config( ( crate::chain_spec::get_account_id_from_seed::("Alice//stash"), ( - // Seed phrase: "alarm mutual concert decrease hurry invest culture survey diagram crash snap click" (*crate::chain_spec::ALICE_TSS_ACCOUNT_ID).into(), - *entropy_shared::ALICE_X25519_PUBLIC_KEY, + crate::chain_spec::tss_x25519_public_key::ALICE, "127.0.0.1:3001".as_bytes().to_vec(), ), ), ( crate::chain_spec::get_account_id_from_seed::("Bob//stash"), ( - // Seed phrase: "where sight patient orphan general short empower hope party hurt month voice" (*crate::chain_spec::BOB_TSS_ACCOUNT_ID).into(), - *entropy_shared::BOB_X25519_PUBLIC_KEY, + crate::chain_spec::tss_x25519_public_key::BOB, "127.0.0.1:3002".as_bytes().to_vec(), ), ), diff --git a/node/cli/src/chain_spec/integration_tests.rs b/node/cli/src/chain_spec/integration_tests.rs index 1069dfbfa..55480836a 100644 --- a/node/cli/src/chain_spec/integration_tests.rs +++ b/node/cli/src/chain_spec/integration_tests.rs @@ -136,28 +136,16 @@ pub fn integration_tests_genesis_config( ( crate::chain_spec::get_account_id_from_seed::("Alice//stash"), ( - // Seed phrase: "alarm mutual concert decrease hurry invest culture survey diagram crash snap click" - hex!["e0543c102def9f6ef0e8b8ffa31aa259167a9391566929fd718a1ccdaabdb876"] - .into(), - [ - 10, 192, 41, 240, 184, 83, 178, 59, 237, 101, 45, 109, 13, 230, 155, - 124, 195, 141, 148, 249, 55, 50, 238, 252, 133, 181, 134, 30, 144, 247, - 58, 34, - ], + (*crate::chain_spec::ALICE_TSS_ACCOUNT_ID).into(), + crate::chain_spec::tss_x25519_public_key::ALICE, "127.0.0.1:3001".as_bytes().to_vec(), ), ), ( crate::chain_spec::get_account_id_from_seed::("Bob//stash"), ( - // Seed phrase: "where sight patient orphan general short empower hope party hurt month voice" - hex!["2a8200850770290c7ea3b50a8ff64c6761c882ff8393dc95fccb5d1475eff17f"] - .into(), - [ - 225, 48, 135, 211, 227, 213, 170, 21, 1, 189, 118, 158, 255, 87, 245, - 89, 36, 170, 169, 181, 68, 201, 210, 178, 237, 247, 101, 80, 153, 136, - 102, 10, - ], + (*crate::chain_spec::BOB_TSS_ACCOUNT_ID).into(), + crate::chain_spec::tss_x25519_public_key::BOB, "127.0.0.1:3002".as_bytes().to_vec(), ), ), @@ -169,11 +157,7 @@ pub fn integration_tests_genesis_config( ( hex!["14d223daeec68671f07298c66c9458980a48bb89fb8a85d5df31131acad8d611"] .into(), - [ - 225, 48, 135, 211, 227, 213, 170, 21, 1, 189, 118, 158, 255, 87, 245, - 89, 36, 170, 169, 181, 68, 201, 210, 178, 237, 247, 101, 80, 153, 136, - 102, 10, - ], + crate::chain_spec::tss_x25519_public_key::BOB, // TODO (Nando): Should be Charlie "127.0.0.1:3002".as_bytes().to_vec(), ), ), @@ -182,11 +166,7 @@ pub fn integration_tests_genesis_config( ( hex!["5212c5f562f4a43b89caadfeb9f5896dd4084700afa72aa55ca306d689523f3a"] .into(), - [ - 225, 48, 135, 211, 227, 213, 170, 21, 1, 189, 118, 158, 255, 87, 245, - 89, 36, 170, 169, 181, 68, 201, 210, 178, 237, 247, 101, 80, 153, 136, - 102, 10, - ], + crate::chain_spec::tss_x25519_public_key::BOB, // TODO (Nando): Should be Dave "127.0.0.1:3002".as_bytes().to_vec(), ), ), diff --git a/node/cli/src/chain_spec/mod.rs b/node/cli/src/chain_spec/mod.rs index 145ddd2eb..562676e20 100644 --- a/node/cli/src/chain_spec/mod.rs +++ b/node/cli/src/chain_spec/mod.rs @@ -31,8 +31,6 @@ //! Substrate chain configurations. -#![allow(dead_code)] - pub mod dev; pub mod integration_tests; pub mod testnet; @@ -54,15 +52,45 @@ use sp_runtime::traits::{IdentifyAccount, Verify}; type AccountPublic = ::Signer; const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/"; + +// TODO (Nando): We might be able to get rid of this... const DEFAULT_PROTOCOL_ID: &str = "Entropy"; // TODO finalize lazy_static::lazy_static! { // TODO: Make this an AccountId32 + + // The `DEFAULT_ALICE_MNEMONIC` is used to derive the following account and key. + // Mnemonic: "alarm mutual concert decrease hurry invest culture survey diagram crash snap click" + + /// Beep boop pub static ref ALICE_TSS_ACCOUNT_ID: [u8; 32] = hex!["e0543c102def9f6ef0e8b8ffa31aa259167a9391566929fd718a1ccdaabdb876"]; + // The `DEFAULT_BOB_MNEMONIC` is used to derive the following account and key. + // Mnemonic: "where sight patient orphan general short empower hope party hurt month voice" + + /// Beep pub static ref BOB_TSS_ACCOUNT_ID: [u8; 32] = hex!["2a8200850770290c7ea3b50a8ff64c6761c882ff8393dc95fccb5d1475eff17f"]; + +} + +/// The X25519 public key used by the Threshold Signature Scheme servers (TSS) to encrypt messages +/// between TSS servers. +pub mod tss_x25519_public_key { + /// The `DEFAULT_ALICE_MNEMONIC` is used to derive the public key. + /// Mnemonic: "alarm mutual concert decrease hurry invest culture survey diagram crash snap click" + pub const ALICE: [u8; 32] = [ + 10, 192, 41, 240, 184, 83, 178, 59, 237, 101, 45, 109, 13, 230, 155, 124, 195, 141, 148, + 249, 55, 50, 238, 252, 133, 181, 134, 30, 144, 247, 58, 34, + ]; + + /// The `DEFAULT_BOB_MNEMONIC` is used to derive the public key. + /// Mnemonic: "where sight patient orphan general short empower hope party hurt month voice" + pub const BOB: [u8; 32] = [ + 225, 48, 135, 211, 227, 213, 170, 21, 1, 189, 118, 158, 255, 87, 245, 89, 36, 170, 169, + 181, 68, 201, 210, 178, 237, 247, 101, 80, 153, 136, 102, 10, + ]; } // TODO: finalize diff --git a/node/cli/src/chain_spec/testnet.rs b/node/cli/src/chain_spec/testnet.rs index a738a4661..0dd12bca2 100644 --- a/node/cli/src/chain_spec/testnet.rs +++ b/node/cli/src/chain_spec/testnet.rs @@ -154,7 +154,7 @@ pub fn testnet_local_config() -> crate::chain_spec::ChainSpec { ), Some(crate::chain_spec::DEFAULT_PROTOCOL_ID), None, - Some(crate::chain_spec::entropy_props()), // TODO: Maybe move into this module + Some(crate::chain_spec::entropy_props()), // TODO (Nando): Maybe move into this module Default::default(), ) } @@ -182,7 +182,7 @@ pub fn testnet_config() -> crate::chain_spec::ChainSpec { ), Some(crate::chain_spec::DEFAULT_PROTOCOL_ID), None, - Some(crate::chain_spec::entropy_props()), // TODO: Maybe move into this module + Some(crate::chain_spec::entropy_props()), // TODO (Nando): Maybe move into this module Default::default(), ) } @@ -267,18 +267,16 @@ pub fn testnet_genesis_config( ( crate::chain_spec::get_account_id_from_seed::("Alice//stash"), ( - // Seed phrase: "alarm mutual concert decrease hurry invest culture survey diagram crash snap click" (*crate::chain_spec::ALICE_TSS_ACCOUNT_ID).into(), - *entropy_shared::ALICE_X25519_PUBLIC_KEY, + crate::chain_spec::tss_x25519_public_key::ALICE, "127.0.0.1:3001".as_bytes().to_vec(), ), ), ( crate::chain_spec::get_account_id_from_seed::("Bob//stash"), ( - // Seed phrase: "where sight patient orphan general short empower hope party hurt month voice" (*crate::chain_spec::BOB_TSS_ACCOUNT_ID).into(), - *entropy_shared::BOB_X25519_PUBLIC_KEY, + crate::chain_spec::tss_x25519_public_key::BOB, "127.0.0.1:3002".as_bytes().to_vec(), ), ), From 0f867e393276d8eccfc0af6f60e0a53dca224c70 Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Tue, 16 Jan 2024 17:33:18 -0700 Subject: [PATCH 14/28] Move TSS AccountID into own module --- node/cli/src/chain_spec/dev.rs | 4 +-- node/cli/src/chain_spec/integration_tests.rs | 23 ++++++------- node/cli/src/chain_spec/mod.rs | 34 +++++++++++++------- node/cli/src/chain_spec/testnet.rs | 4 +-- 4 files changed, 36 insertions(+), 29 deletions(-) diff --git a/node/cli/src/chain_spec/dev.rs b/node/cli/src/chain_spec/dev.rs index 0b065492a..1a93162ea 100644 --- a/node/cli/src/chain_spec/dev.rs +++ b/node/cli/src/chain_spec/dev.rs @@ -135,7 +135,7 @@ pub fn development_genesis_config( ( crate::chain_spec::get_account_id_from_seed::("Alice//stash"), ( - (*crate::chain_spec::ALICE_TSS_ACCOUNT_ID).into(), + crate::chain_spec::tss_account_id::ALICE.clone(), crate::chain_spec::tss_x25519_public_key::ALICE, "127.0.0.1:3001".as_bytes().to_vec(), ), @@ -143,7 +143,7 @@ pub fn development_genesis_config( ( crate::chain_spec::get_account_id_from_seed::("Bob//stash"), ( - (*crate::chain_spec::BOB_TSS_ACCOUNT_ID).into(), + crate::chain_spec::tss_account_id::BOB.clone(), crate::chain_spec::tss_x25519_public_key::BOB, "127.0.0.1:3002".as_bytes().to_vec(), ), diff --git a/node/cli/src/chain_spec/integration_tests.rs b/node/cli/src/chain_spec/integration_tests.rs index 55480836a..3569db681 100644 --- a/node/cli/src/chain_spec/integration_tests.rs +++ b/node/cli/src/chain_spec/integration_tests.rs @@ -136,7 +136,7 @@ pub fn integration_tests_genesis_config( ( crate::chain_spec::get_account_id_from_seed::("Alice//stash"), ( - (*crate::chain_spec::ALICE_TSS_ACCOUNT_ID).into(), + crate::chain_spec::tss_account_id::ALICE.clone(), crate::chain_spec::tss_x25519_public_key::ALICE, "127.0.0.1:3001".as_bytes().to_vec(), ), @@ -144,19 +144,17 @@ pub fn integration_tests_genesis_config( ( crate::chain_spec::get_account_id_from_seed::("Bob//stash"), ( - (*crate::chain_spec::BOB_TSS_ACCOUNT_ID).into(), + crate::chain_spec::tss_account_id::BOB.clone(), crate::chain_spec::tss_x25519_public_key::BOB, "127.0.0.1:3002".as_bytes().to_vec(), ), ), ( - // Seed phrase: "lake carry still awful point mention bike category tornado plate brass lock" crate::chain_spec::get_account_id_from_seed::( "Charlie//stash", ), ( - hex!["14d223daeec68671f07298c66c9458980a48bb89fb8a85d5df31131acad8d611"] - .into(), + crate::chain_spec::tss_account_id::CHARLIE.clone(), crate::chain_spec::tss_x25519_public_key::BOB, // TODO (Nando): Should be Charlie "127.0.0.1:3002".as_bytes().to_vec(), ), @@ -164,8 +162,7 @@ pub fn integration_tests_genesis_config( ( crate::chain_spec::get_account_id_from_seed::("Dave//stash"), ( - hex!["5212c5f562f4a43b89caadfeb9f5896dd4084700afa72aa55ca306d689523f3a"] - .into(), + crate::chain_spec::tss_account_id::DAVE.clone(), crate::chain_spec::tss_x25519_public_key::BOB, // TODO (Nando): Should be Dave "127.0.0.1:3002".as_bytes().to_vec(), ), @@ -192,9 +189,9 @@ pub fn integration_tests_genesis_config( ], proactive_refresh_validators: vec![ entropy_shared::ValidatorInfo { - tss_account: hex![ - "e0543c102def9f6ef0e8b8ffa31aa259167a9391566929fd718a1ccdaabdb876" - ] + tss_account: >::as_ref( + &crate::chain_spec::tss_account_id::ALICE.clone(), + ) .into(), ip_address: "127.0.0.1:3001".as_bytes().to_vec(), x25519_public_key: [ @@ -203,9 +200,9 @@ pub fn integration_tests_genesis_config( ], }, entropy_shared::ValidatorInfo { - tss_account: hex![ - "2a8200850770290c7ea3b50a8ff64c6761c882ff8393dc95fccb5d1475eff17f" - ] + tss_account: >::as_ref( + &crate::chain_spec::tss_account_id::BOB.clone(), + ) .into(), ip_address: "127.0.0.1:3002".as_bytes().to_vec(), x25519_public_key: [ diff --git a/node/cli/src/chain_spec/mod.rs b/node/cli/src/chain_spec/mod.rs index 562676e20..456eb01f9 100644 --- a/node/cli/src/chain_spec/mod.rs +++ b/node/cli/src/chain_spec/mod.rs @@ -56,23 +56,33 @@ const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/"; // TODO (Nando): We might be able to get rid of this... const DEFAULT_PROTOCOL_ID: &str = "Entropy"; // TODO finalize -lazy_static::lazy_static! { - // TODO: Make this an AccountId32 +/// The `AccountId` represending a Threshold Signature Scheme servers (TSS). +/// +/// This gets stored on-chain to and is used to identify a particular TSS. +pub mod tss_account_id { + lazy_static::lazy_static! { - // The `DEFAULT_ALICE_MNEMONIC` is used to derive the following account and key. - // Mnemonic: "alarm mutual concert decrease hurry invest culture survey diagram crash snap click" + /// The `DEFAULT_ALICE_MNEMONIC` is used to derive the following `AccountId`. + /// Mnemonic: "alarm mutual concert decrease hurry invest culture survey diagram crash snap click" + pub static ref ALICE: sp_runtime::AccountId32 = + super::hex!["e0543c102def9f6ef0e8b8ffa31aa259167a9391566929fd718a1ccdaabdb876"].into(); - /// Beep boop - pub static ref ALICE_TSS_ACCOUNT_ID: [u8; 32] = - hex!["e0543c102def9f6ef0e8b8ffa31aa259167a9391566929fd718a1ccdaabdb876"]; + /// The `DEFAULT_BOB_MNEMONIC` is used to derive the following `AccountId`. + /// Mnemonic: "where sight patient orphan general short empower hope party hurt month voice" + pub static ref BOB: sp_runtime::AccountId32 = + super::hex!["2a8200850770290c7ea3b50a8ff64c6761c882ff8393dc95fccb5d1475eff17f"].into(); - // The `DEFAULT_BOB_MNEMONIC` is used to derive the following account and key. - // Mnemonic: "where sight patient orphan general short empower hope party hurt month voice" + /// The `DEFAULT_CHARLIE_MNEMONIC` is used to derive the following `AccountId`. + /// Mnemonic: "lake carry still awful point mention bike category tornado plate brass lock" + pub static ref CHARLIE: sp_runtime::AccountId32 = + super::hex!["14d223daeec68671f07298c66c9458980a48bb89fb8a85d5df31131acad8d611"].into(); - /// Beep - pub static ref BOB_TSS_ACCOUNT_ID: [u8; 32] = - hex!["2a8200850770290c7ea3b50a8ff64c6761c882ff8393dc95fccb5d1475eff17f"]; + /// Not sure what mneminic is used to derive the following `AccountId`. + /// Mnemonic: "????" + pub static ref DAVE: sp_runtime::AccountId32 = + super::hex!["5212c5f562f4a43b89caadfeb9f5896dd4084700afa72aa55ca306d689523f3a"].into(); + } } /// The X25519 public key used by the Threshold Signature Scheme servers (TSS) to encrypt messages diff --git a/node/cli/src/chain_spec/testnet.rs b/node/cli/src/chain_spec/testnet.rs index 0dd12bca2..2fc47fdc2 100644 --- a/node/cli/src/chain_spec/testnet.rs +++ b/node/cli/src/chain_spec/testnet.rs @@ -267,7 +267,7 @@ pub fn testnet_genesis_config( ( crate::chain_spec::get_account_id_from_seed::("Alice//stash"), ( - (*crate::chain_spec::ALICE_TSS_ACCOUNT_ID).into(), + crate::chain_spec::tss_account_id::ALICE.clone(), crate::chain_spec::tss_x25519_public_key::ALICE, "127.0.0.1:3001".as_bytes().to_vec(), ), @@ -275,7 +275,7 @@ pub fn testnet_genesis_config( ( crate::chain_spec::get_account_id_from_seed::("Bob//stash"), ( - (*crate::chain_spec::BOB_TSS_ACCOUNT_ID).into(), + crate::chain_spec::tss_account_id::BOB.clone(), crate::chain_spec::tss_x25519_public_key::BOB, "127.0.0.1:3002".as_bytes().to_vec(), ), From 466ab20b5c45669ee0a6525a8968c33fe79f2376 Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Tue, 16 Jan 2024 17:35:15 -0700 Subject: [PATCH 15/28] Use new consts in `integration_tests` module --- node/cli/src/chain_spec/integration_tests.rs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/node/cli/src/chain_spec/integration_tests.rs b/node/cli/src/chain_spec/integration_tests.rs index 3569db681..4ba870e44 100644 --- a/node/cli/src/chain_spec/integration_tests.rs +++ b/node/cli/src/chain_spec/integration_tests.rs @@ -22,7 +22,6 @@ use entropy_runtime::{ StakingExtensionConfig, SudoConfig, SystemConfig, TechnicalCommitteeConfig, }; use grandpa_primitives::AuthorityId as GrandpaId; -use hex_literal::hex; pub use node_primitives::{AccountId, Balance, Signature}; use pallet_im_online::sr25519::AuthorityId as ImOnlineId; use sc_service::ChainType; @@ -194,10 +193,7 @@ pub fn integration_tests_genesis_config( ) .into(), ip_address: "127.0.0.1:3001".as_bytes().to_vec(), - x25519_public_key: [ - 10, 192, 41, 240, 184, 83, 178, 59, 237, 101, 45, 109, 13, 230, 155, 124, - 195, 141, 148, 249, 55, 50, 238, 252, 133, 181, 134, 30, 144, 247, 58, 34, - ], + x25519_public_key: crate::chain_spec::tss_x25519_public_key::ALICE, }, entropy_shared::ValidatorInfo { tss_account: >::as_ref( @@ -205,10 +201,7 @@ pub fn integration_tests_genesis_config( ) .into(), ip_address: "127.0.0.1:3002".as_bytes().to_vec(), - x25519_public_key: [ - 225, 48, 135, 211, 227, 213, 170, 21, 1, 189, 118, 158, 255, 87, 245, 89, - 36, 170, 169, 181, 68, 201, 210, 178, 237, 247, 101, 80, 153, 136, 102, 10, - ], + x25519_public_key: crate::chain_spec::tss_x25519_public_key::BOB, }, ], }, From ddb452a03dca8bf99fe9f354c171d14d3bc60dae Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Tue, 16 Jan 2024 17:41:58 -0700 Subject: [PATCH 16/28] Clean up some unused re-exports --- node/cli/src/chain_spec/dev.rs | 9 +++++---- node/cli/src/chain_spec/integration_tests.rs | 9 +++++---- node/cli/src/chain_spec/mod.rs | 3 ++- node/cli/src/chain_spec/testnet.rs | 12 ++++++------ 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/node/cli/src/chain_spec/dev.rs b/node/cli/src/chain_spec/dev.rs index 1a93162ea..326ebd382 100644 --- a/node/cli/src/chain_spec/dev.rs +++ b/node/cli/src/chain_spec/dev.rs @@ -14,15 +14,16 @@ // along with this program. If not, see . use crate::endowed_accounts::endowed_accounts_dev; -pub use entropy_runtime::RuntimeGenesisConfig; + use entropy_runtime::{ constants::currency::*, wasm_binary_unwrap, AuthorityDiscoveryConfig, BabeConfig, BalancesConfig, CouncilConfig, DemocracyConfig, ElectionsConfig, GrandpaConfig, ImOnlineConfig, - IndicesConfig, MaxNominations, RelayerConfig, SessionConfig, StakerStatus, StakingConfig, - StakingExtensionConfig, SudoConfig, SystemConfig, TechnicalCommitteeConfig, + IndicesConfig, MaxNominations, RelayerConfig, RuntimeGenesisConfig, SessionConfig, + StakerStatus, StakingConfig, StakingExtensionConfig, SudoConfig, SystemConfig, + TechnicalCommitteeConfig, }; use grandpa_primitives::AuthorityId as GrandpaId; -pub use node_primitives::{AccountId, Balance, Signature}; +use node_primitives::{AccountId, Balance}; use pallet_im_online::sr25519::AuthorityId as ImOnlineId; use sc_service::ChainType; use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId; diff --git a/node/cli/src/chain_spec/integration_tests.rs b/node/cli/src/chain_spec/integration_tests.rs index 4ba870e44..10e3e2811 100644 --- a/node/cli/src/chain_spec/integration_tests.rs +++ b/node/cli/src/chain_spec/integration_tests.rs @@ -14,15 +14,16 @@ // along with this program. If not, see . use crate::endowed_accounts::endowed_accounts_dev; -pub use entropy_runtime::RuntimeGenesisConfig; + use entropy_runtime::{ constants::currency::*, wasm_binary_unwrap, AuthorityDiscoveryConfig, BabeConfig, BalancesConfig, CouncilConfig, DemocracyConfig, ElectionsConfig, GrandpaConfig, ImOnlineConfig, - IndicesConfig, MaxNominations, RelayerConfig, SessionConfig, StakerStatus, StakingConfig, - StakingExtensionConfig, SudoConfig, SystemConfig, TechnicalCommitteeConfig, + IndicesConfig, MaxNominations, RelayerConfig, RuntimeGenesisConfig, SessionConfig, + StakerStatus, StakingConfig, StakingExtensionConfig, SudoConfig, SystemConfig, + TechnicalCommitteeConfig, }; use grandpa_primitives::AuthorityId as GrandpaId; -pub use node_primitives::{AccountId, Balance, Signature}; +use node_primitives::{AccountId, Balance}; use pallet_im_online::sr25519::AuthorityId as ImOnlineId; use sc_service::ChainType; use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId; diff --git a/node/cli/src/chain_spec/mod.rs b/node/cli/src/chain_spec/mod.rs index 456eb01f9..4d8e8808b 100644 --- a/node/cli/src/chain_spec/mod.rs +++ b/node/cli/src/chain_spec/mod.rs @@ -36,10 +36,11 @@ pub mod integration_tests; pub mod testnet; pub use entropy_runtime::RuntimeGenesisConfig; +pub use node_primitives::{AccountId, Balance, Signature}; + use entropy_runtime::{Block, SessionKeys}; use grandpa_primitives::AuthorityId as GrandpaId; use hex_literal::hex; -pub use node_primitives::{AccountId, Balance, Signature}; use pallet_im_online::sr25519::AuthorityId as ImOnlineId; use sc_chain_spec::{ChainSpecExtension, Properties}; use serde::{Deserialize, Serialize}; diff --git a/node/cli/src/chain_spec/testnet.rs b/node/cli/src/chain_spec/testnet.rs index 2fc47fdc2..424ff4ae7 100644 --- a/node/cli/src/chain_spec/testnet.rs +++ b/node/cli/src/chain_spec/testnet.rs @@ -13,16 +13,18 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . -pub use entropy_runtime::RuntimeGenesisConfig; +use crate::endowed_accounts::endowed_accounts_dev; + use entropy_runtime::{ constants::currency::*, wasm_binary_unwrap, AuthorityDiscoveryConfig, BabeConfig, BalancesConfig, CouncilConfig, DemocracyConfig, ElectionsConfig, GrandpaConfig, ImOnlineConfig, - IndicesConfig, MaxNominations, RelayerConfig, SessionConfig, StakerStatus, StakingConfig, - StakingExtensionConfig, SudoConfig, SystemConfig, TechnicalCommitteeConfig, + IndicesConfig, MaxNominations, RelayerConfig, RuntimeGenesisConfig, SessionConfig, + StakerStatus, StakingConfig, StakingExtensionConfig, SudoConfig, SystemConfig, + TechnicalCommitteeConfig, }; use grandpa_primitives::AuthorityId as GrandpaId; use hex_literal::hex; -pub use node_primitives::{AccountId, Balance, Signature}; +use node_primitives::{AccountId, Balance}; use pallet_im_online::sr25519::AuthorityId as ImOnlineId; use sc_service::ChainType; use sc_telemetry::TelemetryEndpoints; @@ -31,8 +33,6 @@ use sp_consensus_babe::AuthorityId as BabeId; use sp_core::{crypto::UncheckedInto, sr25519}; use sp_runtime::Perbill; -use crate::endowed_accounts::endowed_accounts_dev; - pub fn testnet_local_initial_authorities( ) -> Vec<(AccountId, AccountId, GrandpaId, BabeId, ImOnlineId, AuthorityDiscoveryId)> { vec![ From 1393f21e13c46a5ea41d6c7e647918337831178d Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Tue, 16 Jan 2024 17:58:17 -0700 Subject: [PATCH 17/28] Use full word for "properties" --- node/cli/src/chain_spec/mod.rs | 5 +---- node/cli/src/chain_spec/testnet.rs | 4 ++-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/node/cli/src/chain_spec/mod.rs b/node/cli/src/chain_spec/mod.rs index 4d8e8808b..13ae72b9d 100644 --- a/node/cli/src/chain_spec/mod.rs +++ b/node/cli/src/chain_spec/mod.rs @@ -53,8 +53,6 @@ use sp_runtime::traits::{IdentifyAccount, Verify}; type AccountPublic = ::Signer; const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/"; - -// TODO (Nando): We might be able to get rid of this... const DEFAULT_PROTOCOL_ID: &str = "Entropy"; // TODO finalize /// The `AccountId` represending a Threshold Signature Scheme servers (TSS). @@ -104,8 +102,7 @@ pub mod tss_x25519_public_key { ]; } -// TODO: finalize -fn entropy_props() -> Properties { +fn entropy_properties() -> Properties { json!({"tokenDecimals": 10, "tokenSymbol": "BITS" }).as_object().unwrap().clone() } diff --git a/node/cli/src/chain_spec/testnet.rs b/node/cli/src/chain_spec/testnet.rs index 424ff4ae7..7c307a29e 100644 --- a/node/cli/src/chain_spec/testnet.rs +++ b/node/cli/src/chain_spec/testnet.rs @@ -154,7 +154,7 @@ pub fn testnet_local_config() -> crate::chain_spec::ChainSpec { ), Some(crate::chain_spec::DEFAULT_PROTOCOL_ID), None, - Some(crate::chain_spec::entropy_props()), // TODO (Nando): Maybe move into this module + Some(crate::chain_spec::entropy_properties()), Default::default(), ) } @@ -182,7 +182,7 @@ pub fn testnet_config() -> crate::chain_spec::ChainSpec { ), Some(crate::chain_spec::DEFAULT_PROTOCOL_ID), None, - Some(crate::chain_spec::entropy_props()), // TODO (Nando): Maybe move into this module + Some(crate::chain_spec::entropy_properties()), Default::default(), ) } From 0f6f31804d3e39f0bd39436c9388c9a5ff92665b Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Tue, 16 Jan 2024 18:00:48 -0700 Subject: [PATCH 18/28] Use `get_account_id_from_seed` from import instead of full path --- node/cli/src/chain_spec/dev.rs | 27 ++++++---------- node/cli/src/chain_spec/integration_tests.rs | 34 +++++++------------- node/cli/src/chain_spec/testnet.rs | 27 ++++++---------- 3 files changed, 30 insertions(+), 58 deletions(-) diff --git a/node/cli/src/chain_spec/dev.rs b/node/cli/src/chain_spec/dev.rs index 326ebd382..fb69b8a03 100644 --- a/node/cli/src/chain_spec/dev.rs +++ b/node/cli/src/chain_spec/dev.rs @@ -13,6 +13,7 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . +use crate::chain_spec::get_account_id_from_seed; use crate::endowed_accounts::endowed_accounts_dev; use entropy_runtime::{ @@ -44,7 +45,7 @@ pub fn development_config() -> crate::chain_spec::ChainSpec { crate::chain_spec::authority_keys_from_seed("Bob"), ], vec![], - crate::chain_spec::get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Alice"), ) }, vec![], @@ -134,7 +135,7 @@ pub fn development_genesis_config( staking_extension: StakingExtensionConfig { threshold_servers: vec![ ( - crate::chain_spec::get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Alice//stash"), ( crate::chain_spec::tss_account_id::ALICE.clone(), crate::chain_spec::tss_x25519_public_key::ALICE, @@ -142,7 +143,7 @@ pub fn development_genesis_config( ), ), ( - crate::chain_spec::get_account_id_from_seed::("Bob//stash"), + get_account_id_from_seed::("Bob//stash"), ( crate::chain_spec::tss_account_id::BOB.clone(), crate::chain_spec::tss_x25519_public_key::BOB, @@ -151,18 +152,8 @@ pub fn development_genesis_config( ), ], signing_groups: vec![ - ( - 0, - vec![crate::chain_spec::get_account_id_from_seed::( - "Alice//stash", - )], - ), - ( - 1, - vec![crate::chain_spec::get_account_id_from_seed::( - "Bob//stash", - )], - ), + (0, vec![get_account_id_from_seed::("Alice//stash")]), + (1, vec![get_account_id_from_seed::("Bob//stash")]), ], proactive_refresh_validators: vec![], }, @@ -197,16 +188,16 @@ pub fn development_genesis_config( treasury: Default::default(), relayer: RelayerConfig { registered_accounts: vec![ - (crate::chain_spec::get_account_id_from_seed::("Dave"), 0, None), + (get_account_id_from_seed::("Dave"), 0, None), ( - crate::chain_spec::get_account_id_from_seed::("Eve"), + get_account_id_from_seed::("Eve"), 1, Some([ 28, 63, 144, 84, 78, 147, 195, 214, 190, 234, 111, 101, 117, 133, 9, 198, 96, 96, 76, 140, 152, 251, 255, 28, 167, 38, 157, 185, 192, 42, 201, 82, ]), ), - (crate::chain_spec::get_account_id_from_seed::("Ferdie"), 2, None), + (get_account_id_from_seed::("Ferdie"), 2, None), ], }, vesting: Default::default(), diff --git a/node/cli/src/chain_spec/integration_tests.rs b/node/cli/src/chain_spec/integration_tests.rs index 10e3e2811..7d8a6dfae 100644 --- a/node/cli/src/chain_spec/integration_tests.rs +++ b/node/cli/src/chain_spec/integration_tests.rs @@ -13,6 +13,7 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . +use crate::chain_spec::get_account_id_from_seed; use crate::endowed_accounts::endowed_accounts_dev; use entropy_runtime::{ @@ -44,7 +45,7 @@ pub fn integration_tests_config() -> crate::chain_spec::ChainSpec { crate::chain_spec::authority_keys_from_seed("Bob"), ], vec![], - crate::chain_spec::get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Alice"), ) }, vec![], @@ -134,7 +135,7 @@ pub fn integration_tests_genesis_config( staking_extension: StakingExtensionConfig { threshold_servers: vec![ ( - crate::chain_spec::get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Alice//stash"), ( crate::chain_spec::tss_account_id::ALICE.clone(), crate::chain_spec::tss_x25519_public_key::ALICE, @@ -142,7 +143,7 @@ pub fn integration_tests_genesis_config( ), ), ( - crate::chain_spec::get_account_id_from_seed::("Bob//stash"), + get_account_id_from_seed::("Bob//stash"), ( crate::chain_spec::tss_account_id::BOB.clone(), crate::chain_spec::tss_x25519_public_key::BOB, @@ -150,9 +151,7 @@ pub fn integration_tests_genesis_config( ), ), ( - crate::chain_spec::get_account_id_from_seed::( - "Charlie//stash", - ), + get_account_id_from_seed::("Charlie//stash"), ( crate::chain_spec::tss_account_id::CHARLIE.clone(), crate::chain_spec::tss_x25519_public_key::BOB, // TODO (Nando): Should be Charlie @@ -160,7 +159,7 @@ pub fn integration_tests_genesis_config( ), ), ( - crate::chain_spec::get_account_id_from_seed::("Dave//stash"), + get_account_id_from_seed::("Dave//stash"), ( crate::chain_spec::tss_account_id::DAVE.clone(), crate::chain_spec::tss_x25519_public_key::BOB, // TODO (Nando): Should be Dave @@ -172,20 +171,11 @@ pub fn integration_tests_genesis_config( ( 0, vec![ - crate::chain_spec::get_account_id_from_seed::( - "Alice//stash", - ), - crate::chain_spec::get_account_id_from_seed::( - "Charlie//stash", - ), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Charlie//stash"), ], ), - ( - 1, - vec![crate::chain_spec::get_account_id_from_seed::( - "Bob//stash", - )], - ), + (1, vec![get_account_id_from_seed::("Bob//stash")]), ], proactive_refresh_validators: vec![ entropy_shared::ValidatorInfo { @@ -237,16 +227,16 @@ pub fn integration_tests_genesis_config( treasury: Default::default(), relayer: RelayerConfig { registered_accounts: vec![ - (crate::chain_spec::get_account_id_from_seed::("Dave"), 0, None), + (get_account_id_from_seed::("Dave"), 0, None), ( - crate::chain_spec::get_account_id_from_seed::("Eve"), + get_account_id_from_seed::("Eve"), 1, Some([ 28, 63, 144, 84, 78, 147, 195, 214, 190, 234, 111, 101, 117, 133, 9, 198, 96, 96, 76, 140, 152, 251, 255, 28, 167, 38, 157, 185, 192, 42, 201, 82, ]), ), - (crate::chain_spec::get_account_id_from_seed::("Ferdie"), 2, None), + (get_account_id_from_seed::("Ferdie"), 2, None), ], }, vesting: Default::default(), diff --git a/node/cli/src/chain_spec/testnet.rs b/node/cli/src/chain_spec/testnet.rs index 7c307a29e..3fd09a13e 100644 --- a/node/cli/src/chain_spec/testnet.rs +++ b/node/cli/src/chain_spec/testnet.rs @@ -13,6 +13,7 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . +use crate::chain_spec::get_account_id_from_seed; use crate::endowed_accounts::endowed_accounts_dev; use entropy_runtime::{ @@ -141,7 +142,7 @@ pub fn testnet_local_config() -> crate::chain_spec::ChainSpec { testnet_genesis_config( testnet_local_initial_authorities(), vec![], - crate::chain_spec::get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Alice"), ) }, vec![], @@ -265,7 +266,7 @@ pub fn testnet_genesis_config( staking_extension: StakingExtensionConfig { threshold_servers: vec![ ( - crate::chain_spec::get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Alice//stash"), ( crate::chain_spec::tss_account_id::ALICE.clone(), crate::chain_spec::tss_x25519_public_key::ALICE, @@ -273,7 +274,7 @@ pub fn testnet_genesis_config( ), ), ( - crate::chain_spec::get_account_id_from_seed::("Bob//stash"), + get_account_id_from_seed::("Bob//stash"), ( crate::chain_spec::tss_account_id::BOB.clone(), crate::chain_spec::tss_x25519_public_key::BOB, @@ -282,18 +283,8 @@ pub fn testnet_genesis_config( ), ], signing_groups: vec![ - ( - 0, - vec![crate::chain_spec::get_account_id_from_seed::( - "Alice//stash", - )], - ), - ( - 1, - vec![crate::chain_spec::get_account_id_from_seed::( - "Bob//stash", - )], - ), + (0, vec![get_account_id_from_seed::("Alice//stash")]), + (1, vec![get_account_id_from_seed::("Bob//stash")]), ], proactive_refresh_validators: vec![], }, @@ -328,16 +319,16 @@ pub fn testnet_genesis_config( treasury: Default::default(), relayer: RelayerConfig { registered_accounts: vec![ - (crate::chain_spec::get_account_id_from_seed::("Dave"), 0, None), + (get_account_id_from_seed::("Dave"), 0, None), ( - crate::chain_spec::get_account_id_from_seed::("Eve"), + get_account_id_from_seed::("Eve"), 1, Some([ 28, 63, 144, 84, 78, 147, 195, 214, 190, 234, 111, 101, 117, 133, 9, 198, 96, 96, 76, 140, 152, 251, 255, 28, 167, 38, 157, 185, 192, 42, 201, 82, ]), ), - (crate::chain_spec::get_account_id_from_seed::("Ferdie"), 2, None), + (get_account_id_from_seed::("Ferdie"), 2, None), ], }, vesting: Default::default(), From 856daf25febbba917f349107104910b7a2cb40c9 Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Tue, 16 Jan 2024 18:11:37 -0700 Subject: [PATCH 19/28] Add `Charlie` X25519 public key --- node/cli/src/chain_spec/integration_tests.rs | 6 ++++-- node/cli/src/chain_spec/mod.rs | 7 +++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/node/cli/src/chain_spec/integration_tests.rs b/node/cli/src/chain_spec/integration_tests.rs index 7d8a6dfae..6088e41ef 100644 --- a/node/cli/src/chain_spec/integration_tests.rs +++ b/node/cli/src/chain_spec/integration_tests.rs @@ -154,7 +154,7 @@ pub fn integration_tests_genesis_config( get_account_id_from_seed::("Charlie//stash"), ( crate::chain_spec::tss_account_id::CHARLIE.clone(), - crate::chain_spec::tss_x25519_public_key::BOB, // TODO (Nando): Should be Charlie + crate::chain_spec::tss_x25519_public_key::CHARLIE, "127.0.0.1:3002".as_bytes().to_vec(), ), ), @@ -162,7 +162,9 @@ pub fn integration_tests_genesis_config( get_account_id_from_seed::("Dave//stash"), ( crate::chain_spec::tss_account_id::DAVE.clone(), - crate::chain_spec::tss_x25519_public_key::BOB, // TODO (Nando): Should be Dave + // This should be a `Dave` account, but we use `Bob` since Dave's mnemonic + // is unavailable right now. + crate::chain_spec::tss_x25519_public_key::BOB, "127.0.0.1:3002".as_bytes().to_vec(), ), ), diff --git a/node/cli/src/chain_spec/mod.rs b/node/cli/src/chain_spec/mod.rs index 13ae72b9d..2c4b4d297 100644 --- a/node/cli/src/chain_spec/mod.rs +++ b/node/cli/src/chain_spec/mod.rs @@ -100,6 +100,13 @@ pub mod tss_x25519_public_key { 225, 48, 135, 211, 227, 213, 170, 21, 1, 189, 118, 158, 255, 87, 245, 89, 36, 170, 169, 181, 68, 201, 210, 178, 237, 247, 101, 80, 153, 136, 102, 10, ]; + + /// The `DEFAULT_CHARLIE_MNEMONIC` is used to derive the public key. + /// Mnemonic: "lake carry still awful point mention bike category tornado plate brass lock" + pub const CHARLIE: [u8; 32] = [ + 245, 222, 99, 201, 89, 227, 119, 236, 142, 217, 74, 171, 58, 162, 140, 165, 7, 104, 210, + 36, 196, 227, 208, 254, 175, 100, 226, 50, 239, 84, 141, 13, + ]; } fn entropy_properties() -> Properties { From 1e8035974d53ad941eb3ea05141aa5c81c9e6893 Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Tue, 16 Jan 2024 18:26:29 -0700 Subject: [PATCH 20/28] Update comments around what each network is made up of --- node/cli/src/chain_spec/dev.rs | 5 ++++- node/cli/src/chain_spec/integration_tests.rs | 14 +++++++++++--- node/cli/src/chain_spec/testnet.rs | 10 ++++++++-- node/cli/src/command.rs | 11 ++++++----- 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/node/cli/src/chain_spec/dev.rs b/node/cli/src/chain_spec/dev.rs index fb69b8a03..6758a6d86 100644 --- a/node/cli/src/chain_spec/dev.rs +++ b/node/cli/src/chain_spec/dev.rs @@ -32,7 +32,10 @@ use sp_consensus_babe::AuthorityId as BabeId; use sp_core::sr25519; use sp_runtime::Perbill; -/// Development config (single validator Alice) +/// The configuration used for development. +/// +/// Since Entropy requires at least two signing groups to work properly we spin up this network with +/// two validators, Alice and Bob. pub fn development_config() -> crate::chain_spec::ChainSpec { crate::chain_spec::ChainSpec::from_genesis( "Development", diff --git a/node/cli/src/chain_spec/integration_tests.rs b/node/cli/src/chain_spec/integration_tests.rs index 6088e41ef..8c3e07b2f 100644 --- a/node/cli/src/chain_spec/integration_tests.rs +++ b/node/cli/src/chain_spec/integration_tests.rs @@ -32,11 +32,16 @@ use sp_consensus_babe::AuthorityId as BabeId; use sp_core::sr25519; use sp_runtime::Perbill; -/// Testing config (single validator Alice) +/// The configuration used for the Threshold Signature Scheme server integration tests. +/// +/// Since Entropy requires at least two signing groups to work properly we spin up this network with +/// two validators, Alice and Bob. +/// +/// There are also some changes around the proactive refresh validators. pub fn integration_tests_config() -> crate::chain_spec::ChainSpec { crate::chain_spec::ChainSpec::from_genesis( "Testing", - "test", + "integration-tests", ChainType::Development, || { integration_tests_genesis_config( @@ -154,7 +159,10 @@ pub fn integration_tests_genesis_config( get_account_id_from_seed::("Charlie//stash"), ( crate::chain_spec::tss_account_id::CHARLIE.clone(), - crate::chain_spec::tss_x25519_public_key::CHARLIE, + crate::chain_spec::tss_x25519_public_key::CHARLIE, // TODO (Nando) ... I + // wonder if this needs + // to be a validator + // actually... "127.0.0.1:3002".as_bytes().to_vec(), ), ), diff --git a/node/cli/src/chain_spec/testnet.rs b/node/cli/src/chain_spec/testnet.rs index 3fd09a13e..18bd3b35c 100644 --- a/node/cli/src/chain_spec/testnet.rs +++ b/node/cli/src/chain_spec/testnet.rs @@ -133,6 +133,8 @@ pub fn testnet_initial_authorities( ] } +/// The local testnet configuration uses the same general setup as the testnet, with the exception +/// that it is using two well-known accounts (Alice and Bob) as the authorities. pub fn testnet_local_config() -> crate::chain_spec::ChainSpec { crate::chain_spec::ChainSpec::from_genesis( "EntropyTestnetLocal", @@ -160,7 +162,12 @@ pub fn testnet_local_config() -> crate::chain_spec::ChainSpec { ) } -/// Development config (single validator Alice) +/// The testnet configuration uses four validator nodes with private keys controlled by the deployer +/// of the network (so Entropy in this case). +/// +/// If you want to run your own version you can either: +/// - Update all the accounts here using keys you control, or +/// - Run the `testnet-local` config, which uses well-known keys pub fn testnet_config() -> crate::chain_spec::ChainSpec { crate::chain_spec::ChainSpec::from_genesis( "EntropyTestnet", @@ -188,7 +195,6 @@ pub fn testnet_config() -> crate::chain_spec::ChainSpec { ) } -/// Helper function to create RuntimeGenesisConfig for testing pub fn testnet_genesis_config( initial_authorities: Vec<( AccountId, diff --git a/node/cli/src/command.rs b/node/cli/src/command.rs index e6574d00f..f4572bba1 100644 --- a/node/cli/src/command.rs +++ b/node/cli/src/command.rs @@ -67,11 +67,12 @@ impl SubstrateCli for Cli { 2022 } - // | --chain | Description | - // |-----------------|----------- | - // | dev | Single node, Alice, Development Configuration | - // | testnet-local | Two Nodes, Alice and Bob, Testnet Configuration | - // | testnet | Four Nodes, Own Seed, Testnet Configuration | + // | --chain | Description | + // |----------------- |----------- | + // | dev | Two nodes, Two threshold servers, Alice and Bob, Development Configuration | + // | integration-tests | Two nodes, Four threshold servers, Alice and Bob, Development Configuration | + // | testnet-local | Two Nodes, Two threhold servers, Alice and Bob, Testnet Configuration | + // | testnet | Four nodes, Two threshold servers, Own Seed, Testnet Configuration | fn load_spec(&self, id: &str) -> Result, String> { Ok(match id { "" | "dev" => Box::new(chain_spec::dev::development_config()), From ab3fc2c4446203d4b3184c188afa7dbe8cb3eb8f Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Tue, 16 Jan 2024 19:58:54 -0700 Subject: [PATCH 21/28] It doesn't need to be a validator for tests to pass --- node/cli/src/chain_spec/integration_tests.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/node/cli/src/chain_spec/integration_tests.rs b/node/cli/src/chain_spec/integration_tests.rs index 8c3e07b2f..3aeb4e841 100644 --- a/node/cli/src/chain_spec/integration_tests.rs +++ b/node/cli/src/chain_spec/integration_tests.rs @@ -159,10 +159,7 @@ pub fn integration_tests_genesis_config( get_account_id_from_seed::("Charlie//stash"), ( crate::chain_spec::tss_account_id::CHARLIE.clone(), - crate::chain_spec::tss_x25519_public_key::CHARLIE, // TODO (Nando) ... I - // wonder if this needs - // to be a validator - // actually... + crate::chain_spec::tss_x25519_public_key::CHARLIE, "127.0.0.1:3002".as_bytes().to_vec(), ), ), From fe4063677e7c55531e787677affc6ea1998f57b6 Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Tue, 16 Jan 2024 19:59:32 -0700 Subject: [PATCH 22/28] Clean up unused re-export --- node/cli/src/chain_spec/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/cli/src/chain_spec/mod.rs b/node/cli/src/chain_spec/mod.rs index 2c4b4d297..d99ca0995 100644 --- a/node/cli/src/chain_spec/mod.rs +++ b/node/cli/src/chain_spec/mod.rs @@ -36,7 +36,7 @@ pub mod integration_tests; pub mod testnet; pub use entropy_runtime::RuntimeGenesisConfig; -pub use node_primitives::{AccountId, Balance, Signature}; +pub use node_primitives::{AccountId, Signature}; use entropy_runtime::{Block, SessionKeys}; use grandpa_primitives::AuthorityId as GrandpaId; From 63c07062d5bb1ae0367cea9055ba81b7203e8e5c Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Tue, 16 Jan 2024 20:00:48 -0700 Subject: [PATCH 23/28] Update some comments --- node/cli/src/chain_spec/dev.rs | 1 - node/cli/src/command.rs | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/node/cli/src/chain_spec/dev.rs b/node/cli/src/chain_spec/dev.rs index 6758a6d86..80a0093d5 100644 --- a/node/cli/src/chain_spec/dev.rs +++ b/node/cli/src/chain_spec/dev.rs @@ -60,7 +60,6 @@ pub fn development_config() -> crate::chain_spec::ChainSpec { ) } -/// Helper function to create RuntimeGenesisConfig for development pub fn development_genesis_config( initial_authorities: Vec<( AccountId, diff --git a/node/cli/src/command.rs b/node/cli/src/command.rs index f4572bba1..6fa487b9b 100644 --- a/node/cli/src/command.rs +++ b/node/cli/src/command.rs @@ -68,10 +68,10 @@ impl SubstrateCli for Cli { } // | --chain | Description | - // |----------------- |----------- | + // |----------------- |----------- | // | dev | Two nodes, Two threshold servers, Alice and Bob, Development Configuration | // | integration-tests | Two nodes, Four threshold servers, Alice and Bob, Development Configuration | - // | testnet-local | Two Nodes, Two threhold servers, Alice and Bob, Testnet Configuration | + // | testnet-local | Two Nodes, Two threshold servers, Alice and Bob, Testnet Configuration | // | testnet | Four nodes, Two threshold servers, Own Seed, Testnet Configuration | fn load_spec(&self, id: &str) -> Result, String> { Ok(match id { From 38cfa27a2b2e793f754289174804f79662118705 Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Tue, 16 Jan 2024 20:09:11 -0700 Subject: [PATCH 24/28] Replace more hex accounts with named accounts --- node/cli/src/endowed_accounts.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/node/cli/src/endowed_accounts.rs b/node/cli/src/endowed_accounts.rs index eefc2b0f0..e8d6b6867 100644 --- a/node/cli/src/endowed_accounts.rs +++ b/node/cli/src/endowed_accounts.rs @@ -13,7 +13,6 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . -use hex_literal::hex; pub use node_primitives::AccountId; use sp_core::sr25519; @@ -37,8 +36,8 @@ pub fn endowed_accounts_dev() -> Vec { get_account_id_from_seed::("Ferdie//stash"), get_account_id_from_seed::("One//stash"), get_account_id_from_seed::("Two//stash"), - hex!["e0543c102def9f6ef0e8b8ffa31aa259167a9391566929fd718a1ccdaabdb876"].into(), - hex!["2a8200850770290c7ea3b50a8ff64c6761c882ff8393dc95fccb5d1475eff17f"].into(), - hex!["14d223daeec68671f07298c66c9458980a48bb89fb8a85d5df31131acad8d611"].into(), + crate::chain_spec::tss_account_id::ALICE.clone(), + crate::chain_spec::tss_account_id::BOB.clone(), + crate::chain_spec::tss_account_id::CHARLIE.clone(), ] } From 83bec8b6b8be2eea804c9ec2672d26d610e5adcf Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Wed, 17 Jan 2024 13:59:15 -0700 Subject: [PATCH 25/28] Pull out `Eve` X25519 public key into const --- node/cli/src/chain_spec/dev.rs | 5 +---- node/cli/src/chain_spec/integration_tests.rs | 5 +---- node/cli/src/chain_spec/mod.rs | 9 ++++++++- node/cli/src/chain_spec/testnet.rs | 5 +---- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/node/cli/src/chain_spec/dev.rs b/node/cli/src/chain_spec/dev.rs index 80a0093d5..5e6702f2b 100644 --- a/node/cli/src/chain_spec/dev.rs +++ b/node/cli/src/chain_spec/dev.rs @@ -194,10 +194,7 @@ pub fn development_genesis_config( ( get_account_id_from_seed::("Eve"), 1, - Some([ - 28, 63, 144, 84, 78, 147, 195, 214, 190, 234, 111, 101, 117, 133, 9, 198, - 96, 96, 76, 140, 152, 251, 255, 28, 167, 38, 157, 185, 192, 42, 201, 82, - ]), + Some(crate::chain_spec::tss_x25519_public_key::EVE), ), (get_account_id_from_seed::("Ferdie"), 2, None), ], diff --git a/node/cli/src/chain_spec/integration_tests.rs b/node/cli/src/chain_spec/integration_tests.rs index 3aeb4e841..13084c50c 100644 --- a/node/cli/src/chain_spec/integration_tests.rs +++ b/node/cli/src/chain_spec/integration_tests.rs @@ -238,10 +238,7 @@ pub fn integration_tests_genesis_config( ( get_account_id_from_seed::("Eve"), 1, - Some([ - 28, 63, 144, 84, 78, 147, 195, 214, 190, 234, 111, 101, 117, 133, 9, 198, - 96, 96, 76, 140, 152, 251, 255, 28, 167, 38, 157, 185, 192, 42, 201, 82, - ]), + Some(crate::chain_spec::tss_x25519_public_key::EVE), ), (get_account_id_from_seed::("Ferdie"), 2, None), ], diff --git a/node/cli/src/chain_spec/mod.rs b/node/cli/src/chain_spec/mod.rs index d99ca0995..743a90dd4 100644 --- a/node/cli/src/chain_spec/mod.rs +++ b/node/cli/src/chain_spec/mod.rs @@ -76,7 +76,7 @@ pub mod tss_account_id { pub static ref CHARLIE: sp_runtime::AccountId32 = super::hex!["14d223daeec68671f07298c66c9458980a48bb89fb8a85d5df31131acad8d611"].into(); - /// Not sure what mneminic is used to derive the following `AccountId`. + /// Not sure what mnemonic is used to derive the following `AccountId`. /// Mnemonic: "????" pub static ref DAVE: sp_runtime::AccountId32 = super::hex!["5212c5f562f4a43b89caadfeb9f5896dd4084700afa72aa55ca306d689523f3a"].into(); @@ -107,6 +107,13 @@ pub mod tss_x25519_public_key { 245, 222, 99, 201, 89, 227, 119, 236, 142, 217, 74, 171, 58, 162, 140, 165, 7, 104, 210, 36, 196, 227, 208, 254, 175, 100, 226, 50, 239, 84, 141, 13, ]; + + /// Not sure what mnemonic is used to derive the following public key. + /// Mnemonic: "????" + pub const EVE: [u8; 32] = [ + 28, 63, 144, 84, 78, 147, 195, 214, 190, 234, 111, 101, 117, 133, 9, 198, 96, 96, 76, 140, + 152, 251, 255, 28, 167, 38, 157, 185, 192, 42, 201, 82, + ]; } fn entropy_properties() -> Properties { diff --git a/node/cli/src/chain_spec/testnet.rs b/node/cli/src/chain_spec/testnet.rs index 18bd3b35c..48250a79e 100644 --- a/node/cli/src/chain_spec/testnet.rs +++ b/node/cli/src/chain_spec/testnet.rs @@ -329,10 +329,7 @@ pub fn testnet_genesis_config( ( get_account_id_from_seed::("Eve"), 1, - Some([ - 28, 63, 144, 84, 78, 147, 195, 214, 190, 234, 111, 101, 117, 133, 9, 198, - 96, 96, 76, 140, 152, 251, 255, 28, 167, 38, 157, 185, 192, 42, 201, 82, - ]), + Some(crate::chain_spec::tss_x25519_public_key::EVE), ), (get_account_id_from_seed::("Ferdie"), 2, None), ], From 3be8e60cc504e3c68fb42f23d9cceae71ea11c79 Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Wed, 17 Jan 2024 14:24:06 -0700 Subject: [PATCH 26/28] Add `devnet-local` configuration back This is meant to be compatible with the hostname scheme expected by the local `docker-compose` setup. --- docker-compose.yaml | 6 +++--- node/cli/src/chain_spec/dev.rs | 36 ++++++++++++++++++++++++++++++++-- node/cli/src/command.rs | 2 ++ 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index 9871fdaa0..4d62eb428 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -8,7 +8,7 @@ # a more canonical set of environments and configuration files. --- version: "3.8" -name: entropy-local-devnet +name: entropy-devnet-local secrets: credentials: @@ -38,7 +38,7 @@ services: - "127.0.0.1:9944:9944/tcp" # "RPC Port." command: - "--chain" - - "local-devnet" + - "devnet-local" - "--alice" # Shortcut for `--name Alice --validator` - "--base-path" - ".entropy/alice" @@ -74,7 +74,7 @@ services: - "127.0.0.1:9945:9944/tcp" command: - "--chain" - - "local-devnet" + - "devnet-local" - "--bob" # Shortcut for `--name Bob --validator` - "--base-path" - ".entropy/bob" diff --git a/node/cli/src/chain_spec/dev.rs b/node/cli/src/chain_spec/dev.rs index 5e6702f2b..f92423097 100644 --- a/node/cli/src/chain_spec/dev.rs +++ b/node/cli/src/chain_spec/dev.rs @@ -49,6 +49,37 @@ pub fn development_config() -> crate::chain_spec::ChainSpec { ], vec![], get_account_id_from_seed::("Alice"), + vec!["127.0.0.1:3001", "127.0.0.1:3002"], + ) + }, + vec![], + None, + None, + None, + None, + Default::default(), + ) +} + +/// The configuration used for a local development network spun up with the `docker-compose` setup +/// provided in this repository. +/// +/// Since Entropy requires at least two signing groups to work properly we spin up this network with +/// two validators, Alice and Bob. +pub fn devnet_local_config() -> crate::chain_spec::ChainSpec { + crate::chain_spec::ChainSpec::from_genesis( + "DevelopmentNetwork", + "DevnetLocal", + ChainType::Development, + || { + development_genesis_config( + vec![ + crate::chain_spec::authority_keys_from_seed("Alice"), + crate::chain_spec::authority_keys_from_seed("Bob"), + ], + vec![], + get_account_id_from_seed::("Alice"), + vec!["alice-tss-server:3001", "bob-tss-server:3002"], ) }, vec![], @@ -71,6 +102,7 @@ pub fn development_genesis_config( )>, initial_nominators: Vec, root_key: AccountId, + threshold_server_endpoints: Vec<&str>, ) -> RuntimeGenesisConfig { let mut endowed_accounts = endowed_accounts_dev(); // endow all authorities and nominators. @@ -141,7 +173,7 @@ pub fn development_genesis_config( ( crate::chain_spec::tss_account_id::ALICE.clone(), crate::chain_spec::tss_x25519_public_key::ALICE, - "127.0.0.1:3001".as_bytes().to_vec(), + threshold_server_endpoints[0].as_bytes().to_vec(), ), ), ( @@ -149,7 +181,7 @@ pub fn development_genesis_config( ( crate::chain_spec::tss_account_id::BOB.clone(), crate::chain_spec::tss_x25519_public_key::BOB, - "127.0.0.1:3002".as_bytes().to_vec(), + threshold_server_endpoints[1].as_bytes().to_vec(), ), ), ], diff --git a/node/cli/src/command.rs b/node/cli/src/command.rs index 6fa487b9b..6a701a81c 100644 --- a/node/cli/src/command.rs +++ b/node/cli/src/command.rs @@ -70,12 +70,14 @@ impl SubstrateCli for Cli { // | --chain | Description | // |----------------- |----------- | // | dev | Two nodes, Two threshold servers, Alice and Bob, Development Configuration | + // | devnet-local | Two nodes, Two threshold servers, Alice and Bob, Development Configuration, Docker Compatible | // | integration-tests | Two nodes, Four threshold servers, Alice and Bob, Development Configuration | // | testnet-local | Two Nodes, Two threshold servers, Alice and Bob, Testnet Configuration | // | testnet | Four nodes, Two threshold servers, Own Seed, Testnet Configuration | fn load_spec(&self, id: &str) -> Result, String> { Ok(match id { "" | "dev" => Box::new(chain_spec::dev::development_config()), + "devnet-local" => Box::new(chain_spec::dev::devnet_local_config()), "integration-tests" => { Box::new(chain_spec::integration_tests::integration_tests_config()) }, From f0b5785143a7d3aec9fb75ecba582148a8056c56 Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Wed, 17 Jan 2024 14:30:48 -0700 Subject: [PATCH 27/28] Change `testnet-local` address to use Docker addresses --- node/cli/src/chain_spec/testnet.rs | 14 ++++++++++---- node/cli/src/command.rs | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/node/cli/src/chain_spec/testnet.rs b/node/cli/src/chain_spec/testnet.rs index 48250a79e..8a95695cd 100644 --- a/node/cli/src/chain_spec/testnet.rs +++ b/node/cli/src/chain_spec/testnet.rs @@ -133,8 +133,11 @@ pub fn testnet_initial_authorities( ] } -/// The local testnet configuration uses the same general setup as the testnet, with the exception -/// that it is using two well-known accounts (Alice and Bob) as the authorities. +/// The configuration used for a local testnet network spun up using the `docker-compose` setup +/// provided in this repository. +/// +/// Its configuration matches the same setup as the `testnet`, with the exception that is uses +/// two well-known accounts (Alice and Bob) as the authorities. pub fn testnet_local_config() -> crate::chain_spec::ChainSpec { crate::chain_spec::ChainSpec::from_genesis( "EntropyTestnetLocal", @@ -145,6 +148,7 @@ pub fn testnet_local_config() -> crate::chain_spec::ChainSpec { testnet_local_initial_authorities(), vec![], get_account_id_from_seed::("Alice"), + vec!["alice-tss-server:3001", "bob-tss-server:3002"], ) }, vec![], @@ -178,6 +182,7 @@ pub fn testnet_config() -> crate::chain_spec::ChainSpec { testnet_initial_authorities(), vec![], hex!["6a16ded05ff7a50716e1ca943f0467c60b4b71c2a7fd7f75b6333b8af80b6e6f"].into(), + vec!["127.0.0.1:3001", "127.0.0.1:3002"], ) }, vec![], @@ -206,6 +211,7 @@ pub fn testnet_genesis_config( )>, initial_nominators: Vec, root_key: AccountId, + threshold_server_endpoints: Vec<&str>, ) -> RuntimeGenesisConfig { let mut endowed_accounts = endowed_accounts_dev(); // endow all authorities and nominators. @@ -276,7 +282,7 @@ pub fn testnet_genesis_config( ( crate::chain_spec::tss_account_id::ALICE.clone(), crate::chain_spec::tss_x25519_public_key::ALICE, - "127.0.0.1:3001".as_bytes().to_vec(), + threshold_server_endpoints[0].as_bytes().to_vec(), ), ), ( @@ -284,7 +290,7 @@ pub fn testnet_genesis_config( ( crate::chain_spec::tss_account_id::BOB.clone(), crate::chain_spec::tss_x25519_public_key::BOB, - "127.0.0.1:3002".as_bytes().to_vec(), + threshold_server_endpoints[1].as_bytes().to_vec(), ), ), ], diff --git a/node/cli/src/command.rs b/node/cli/src/command.rs index 6a701a81c..032147dea 100644 --- a/node/cli/src/command.rs +++ b/node/cli/src/command.rs @@ -72,7 +72,7 @@ impl SubstrateCli for Cli { // | dev | Two nodes, Two threshold servers, Alice and Bob, Development Configuration | // | devnet-local | Two nodes, Two threshold servers, Alice and Bob, Development Configuration, Docker Compatible | // | integration-tests | Two nodes, Four threshold servers, Alice and Bob, Development Configuration | - // | testnet-local | Two Nodes, Two threshold servers, Alice and Bob, Testnet Configuration | + // | testnet-local | Two Nodes, Two threshold servers, Alice and Bob, Testnet Configuration, Docker Compatible | // | testnet | Four nodes, Two threshold servers, Own Seed, Testnet Configuration | fn load_spec(&self, id: &str) -> Result, String> { Ok(match id { From 0e9eb27df3a67a61ad50b385b7ddce6f1de6d74c Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Wed, 17 Jan 2024 15:10:20 -0700 Subject: [PATCH 28/28] Make note about breaking changes in `CHANGELOG` --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index becfabc7c..d8f20ee97 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,9 @@ At the moment this project **does not** adhere to - Wasm API to functions formerly in the x25515chacha20poly1305 repo also now have camelCase function names ([#563](https://github.com/entropyxyz/entropy-core/pull/563)) - Register and change program pointer interface changed to accept a vecotor of programs. As well pass an index for which containts the hashing code if it custom hashing ([#568](https://github.com/entropyxyz/entropy-core/pull/568)) - If a user is sending additive data through it now needs to be in a vector and the index needs to match up with where the program pointer is in the program pointer vector. ([#577](https://github.com/entropyxyz/entropy-core/pull/577)) +- In [#592](https://github.com/entropyxyz/entropy-core/pull/592), the `local-devnet` chain-type was + renamed to `devnet-local`. Additionally, the default chain type when none is specified is now + `dev` instead of `local`. ### Added - Test CLI which calls the same code as in integration tests ([#417](https://github.com/entropyxyz/entropy-core/pull/417)) @@ -40,6 +43,7 @@ At the moment this project **does not** adhere to - Additive programs ([#568](https://github.com/entropyxyz/entropy-core/pull/568)) - Additional `hash` field in `/sign_tx` JSON body indicates which hashing algorithm to use for signing ([#553](https://github.com/entropyxyz/entropy-core/pull/553)) - Additive aux data ([#577](https://github.com/entropyxyz/entropy-core/pull/577)) +- Refactor Rust-based chain specs ([#592](https://github.com/entropyxyz/entropy-core/pull/592)) ### Fixed - Fix inconsistency between interactive and file based passwords ([#589](https://github.com/entropyxyz/entropy-core/pull/589))