Skip to content

Commit

Permalink
Use correct set of endowed accounts in genesis (#834)
Browse files Browse the repository at this point in the history
* Split endowment functions into dev and external account functions

* Use correct endowed accounts in chainspec genesis config

* Add CI check for building the testnet chainspec

* Push external and dev accounts directly to `balances` key

* Format the iterator chain a bit better

* Also check the other chainspecs

Looks like I broke them

* Temporarily stop piping stuff into `/dev/null`

* Ensure that genesis balances are unique
  • Loading branch information
HCastano authored May 14, 2024
1 parent ce3ab55 commit dd2996d
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 39 deletions.
15 changes: 15 additions & 0 deletions .circleci/then.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,18 @@ jobs:
steps:
- install-dependencies-and-checkout
- run: cargo doc --no-deps
check-chainspecs:
machine:
image: ubuntu-2204:2022.10.2
resource_class: xlarge
steps:
- install-dependencies-and-checkout
- run:
command: |
cargo run -p entropy -- build-spec --raw --chain dev > chainspec-dev-raw.json
cargo run -p entropy -- build-spec --raw --chain integration-tests > chainspec-integration-raw.json
cargo run -p entropy -- build-spec --raw --chain testnet > chainspec-testnet-raw.json
parameters:
crates:
Expand Down Expand Up @@ -172,6 +184,9 @@ workflows:
- << pipeline.parameters.pallets >>
- << pipeline.parameters.runtime >>
- pipeline.parameters.crates
chainspecs:
jobs:
- check-chainspecs
documentation:
jobs:
- check-doc-build
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ clap ={ version="4.0.9", features=["derive"], optional=true }
codec ={ package="parity-scale-codec", version="3.0.0" }
futures ="0.3.30"
hex-literal ="0.4.1"
itertools ="0.12.1"
jsonrpsee ={ version="0.20.3", features=["server"] }
lazy_static ={ version="1.4.0", features=["spin_no_std"] }
log ="0.4.21"
Expand Down
15 changes: 13 additions & 2 deletions node/cli/src/chain_spec/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use entropy_shared::{
INITIAL_MAX_INSTRUCTIONS_PER_PROGRAM,
};
use grandpa_primitives::AuthorityId as GrandpaId;
use itertools::Itertools;
use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
use sc_service::ChainType;
use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId;
Expand Down Expand Up @@ -92,7 +93,11 @@ pub fn development_genesis_config(
root_key: AccountId,
threshold_server_endpoints: Vec<&str>,
) -> serde_json::Value {
let (mut endowed_accounts, funded_accounts) = endowed_accounts_dev(false);
// Note that any endowed_accounts added here will be included in the `elections` and
// `technical_committee` genesis configs. If you don't want that, don't push those accounts to
// this list.
let mut endowed_accounts = vec![];

// endow all authorities and nominators.
initial_authorities.iter().map(|x| &x.0).chain(initial_nominators.iter()).for_each(|x| {
if !endowed_accounts.contains(x) {
Expand Down Expand Up @@ -125,7 +130,13 @@ pub fn development_genesis_config(

serde_json::json!({
"balances": BalancesConfig {
balances: funded_accounts.iter().cloned().map(|x| (x, ENDOWMENT)).collect(),
balances: endowed_accounts
.iter()
.chain(endowed_accounts_dev().iter())
.cloned()
.map(|x| (x, ENDOWMENT))
.unique()
.collect(),
},
"indices": IndicesConfig { indices: vec![] },
"session": SessionConfig {
Expand Down
15 changes: 13 additions & 2 deletions node/cli/src/chain_spec/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use entropy_shared::{
INITIAL_MAX_INSTRUCTIONS_PER_PROGRAM,
};
use grandpa_primitives::AuthorityId as GrandpaId;
use itertools::Itertools;
use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
use sc_service::ChainType;
use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId;
Expand Down Expand Up @@ -71,7 +72,11 @@ pub fn integration_tests_genesis_config(
initial_nominators: Vec<AccountId>,
root_key: AccountId,
) -> serde_json::Value {
let (mut endowed_accounts, funded_accounts) = endowed_accounts_dev(false);
// Note that any endowed_accounts added here will be included in the `elections` and
// `technical_committee` genesis configs. If you don't want that, don't push those accounts to
// this list.
let mut endowed_accounts = vec![];

// endow all authorities and nominators.
initial_authorities.iter().map(|x| &x.0).chain(initial_nominators.iter()).for_each(|x| {
if !endowed_accounts.contains(x) {
Expand Down Expand Up @@ -104,7 +109,13 @@ pub fn integration_tests_genesis_config(

serde_json::json!( {
"balances": BalancesConfig {
balances: funded_accounts.iter().cloned().map(|x| (x, ENDOWMENT)).collect(),
balances: endowed_accounts
.iter()
.chain(endowed_accounts_dev().iter())
.cloned()
.map(|x| (x, ENDOWMENT))
.unique()
.collect(),
},
"indices": IndicesConfig { indices: vec![] },
"session": SessionConfig {
Expand Down
21 changes: 13 additions & 8 deletions node/cli/src/chain_spec/testnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use crate::chain_spec::{get_account_id_from_seed, ChainSpec};
use crate::endowed_accounts::endowed_accounts_dev;
use crate::endowed_accounts::endowed_testnet_accounts;

use entropy_runtime::{
constants::currency::*, wasm_binary_unwrap, AuthorityDiscoveryConfig, BabeConfig,
Expand All @@ -29,6 +29,7 @@ use entropy_shared::{
};
use grandpa_primitives::AuthorityId as GrandpaId;
use hex_literal::hex;
use itertools::Itertools;
use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
use sc_service::ChainType;
use sc_telemetry::TelemetryEndpoints;
Expand Down Expand Up @@ -298,18 +299,17 @@ pub fn testnet_genesis_config(
"Each validator node needs to have an accompanying threshold server."
);

let (mut endowed_accounts, mut funded_accounts) = endowed_accounts_dev(true);
// Note that any endowed_accounts added here will be included in the `elections` and
// `technical_committee` genesis configs. If you don't want that, don't push those accounts to
// this list.
let mut endowed_accounts = vec![];

// Ensure that the `testnet-local` config doesn't have a duplicate balance since `Alice` is
// both a validator and root.
if !endowed_accounts.contains(&root_key) {
endowed_accounts.push(root_key.clone());
}

if !funded_accounts.contains(&root_key) {
funded_accounts.push(root_key.clone());
}

// We endow the:
// - Initial TSS server accounts
// - Initial the validator stash accounts
Expand Down Expand Up @@ -359,9 +359,14 @@ pub fn testnet_genesis_config(
const SIGNING_GROUPS: usize = 2;

serde_json::json!( {

"balances": BalancesConfig {
balances: funded_accounts.iter().cloned().map(|x| (x, ENDOWMENT)).collect(),
balances: endowed_accounts
.iter()
.chain(endowed_testnet_accounts().iter())
.cloned()
.map(|x| (x, ENDOWMENT))
.unique()
.collect(),
},
"indices": IndicesConfig { indices: vec![] },
"session": SessionConfig {
Expand Down
57 changes: 30 additions & 27 deletions node/cli/src/endowed_accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ pub struct AddressStruct {
name: String,
}

pub fn endowed_accounts_dev(is_prod: bool) -> (Vec<AccountId>, Vec<AccountId>) {
/// These are accounts which are populated from an external source, with the intention of them
/// being funded an ready to use in a `testnet` configuration.
pub fn endowed_testnet_accounts() -> Vec<AccountId> {
// handle user submitted file for tokens
let mut externally_endowed_accounts: Vec<AddressStruct> = Vec::new();
let project_root = get_project_root();
Expand All @@ -40,37 +42,38 @@ pub fn endowed_accounts_dev(is_prod: bool) -> (Vec<AccountId>, Vec<AccountId>) {
serde_json::from_str(&data).expect("JSON parse error");
externally_endowed_accounts.append(&mut incoming_accounts)
};
let mut inital_accounts = vec![];
if !is_prod {
inital_accounts = vec![
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_account_id_from_seed::<sr25519::Public>("Bob"),
get_account_id_from_seed::<sr25519::Public>("Charlie"),
get_account_id_from_seed::<sr25519::Public>("Dave"),
get_account_id_from_seed::<sr25519::Public>("Eve"),
get_account_id_from_seed::<sr25519::Public>("Ferdie"),
get_account_id_from_seed::<sr25519::Public>("One"),
get_account_id_from_seed::<sr25519::Public>("Two"),
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),
get_account_id_from_seed::<sr25519::Public>("Dave//stash"),
get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
get_account_id_from_seed::<sr25519::Public>("One//stash"),
get_account_id_from_seed::<sr25519::Public>("Two//stash"),
crate::chain_spec::tss_account_id::ALICE.clone(),
crate::chain_spec::tss_account_id::BOB.clone(),
crate::chain_spec::tss_account_id::CHARLIE.clone(),
];
}

let mut funded_accounts = inital_accounts.clone();
let mut funded_accounts = vec![];
for address in externally_endowed_accounts {
funded_accounts.push(AccountId::from_string(&address.address).unwrap_or_else(|_| {
panic!("failed to convert a testnet_address address: {:?}", address)
}))
}

(inital_accounts, funded_accounts)
funded_accounts
}

/// Development accounts which correspond to our usual cast of characters (e.g `//Alice`, `//Bob`).
pub fn endowed_accounts_dev() -> Vec<AccountId> {
vec![
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_account_id_from_seed::<sr25519::Public>("Bob"),
get_account_id_from_seed::<sr25519::Public>("Charlie"),
get_account_id_from_seed::<sr25519::Public>("Dave"),
get_account_id_from_seed::<sr25519::Public>("Eve"),
get_account_id_from_seed::<sr25519::Public>("Ferdie"),
get_account_id_from_seed::<sr25519::Public>("One"),
get_account_id_from_seed::<sr25519::Public>("Two"),
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),
get_account_id_from_seed::<sr25519::Public>("Dave//stash"),
get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
get_account_id_from_seed::<sr25519::Public>("One//stash"),
get_account_id_from_seed::<sr25519::Public>("Two//stash"),
crate::chain_spec::tss_account_id::ALICE.clone(),
crate::chain_spec::tss_account_id::BOB.clone(),
crate::chain_spec::tss_account_id::CHARLIE.clone(),
]
}

0 comments on commit dd2996d

Please sign in to comment.