Skip to content

Commit

Permalink
L1-273: chain-bootstrapper cmd line fixes (#1785)
Browse files Browse the repository at this point in the history
# Description

This PR fixes following issues:
* it makes sure `--authorities-accounts-ids` is a subset of
`--account-ids`
* `--accounts-ids` should have at least one account
* initial endowment is not in `u64` range when `--accounts-ids` ==
`--authorities-accounts-ids` == `--sudo account`. This should have been
fixed in `polkadot 1.6.0`, but investigation why not is not in the scope
of this task.

## Type of change

Please delete options that are not relevant.

- Bug fix (non-breaking change which fixes an issue)
  • Loading branch information
Marcin-Radecki authored Jul 22, 2024
1 parent 2858c3e commit e44450f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion bin/chain-bootstrapper/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "chain-bootstrapper"
version = "0.1.0"
version = "0.1.1"
authors.workspace = true
edition.workspace = true
homepage.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion bin/chain-bootstrapper/src/chain_spec/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fn calculate_initial_endowment(accounts: &[AccountId]) -> u128 {
// (A0-4258) due to known issue https://github.com/paritytech/polkadot-sdk/pull/2987/files,
// we need to make sure returned number is in u64 range, otherwise serde_json::json macro fails
// this is fixed in polkadot-sdk 1.6.0
total_issuance / (accounts.len() as u128) / 10
total_issuance / (accounts.len() as u128) / 100
}

/// Configure initial storage state for FRAME modules.
Expand Down
8 changes: 4 additions & 4 deletions bin/chain-bootstrapper/src/chain_spec/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ pub struct ChainSpecParams {
token_symbol: String,

/// all account ids that needs to have session keys generated when bootstraping chain (comma delimited)
#[arg(long, value_delimiter = ',', value_parser = parse_account_id, num_args = 1..)]
#[arg(long, value_delimiter = ',', value_parser = parse_account_id)]
account_ids: Vec<AccountId>,

/// AccountIds of authorities forming the committee at the genesis (comma delimited)
/// If empty, then `--account-ids` are used as authorities.
/// If not empty, it should ba a subset of `--account-ids`.
#[arg(long, value_delimiter = ',', value_parser = parse_account_id, num_args = 1..)]
/// If not empty, it should be a subset of `--account-ids`.
#[arg(long, value_delimiter = ',', value_parser = parse_account_id)]
authorities_account_ids: Vec<AccountId>,

/// AccountId of the sudo account
#[arg(long, value_parser = parse_account_id, default_value(DEFAULT_SUDO_ACCOUNT_ALICE))]
sudo_account_id: AccountId,

/// Accounts that will receive initial endowment in genesis block
#[arg(long, value_delimiter = ',', value_parser = parse_account_id, num_args = 1..)]
#[arg(long, value_delimiter = ',', value_parser = parse_account_id)]
rich_account_ids: Option<Vec<AccountId>>,

/// Finality version at chain inception.
Expand Down
12 changes: 12 additions & 0 deletions bin/chain-bootstrapper/src/chain_spec/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,19 @@ impl BootstrapChainCmd {
let account_ids = self.chain_spec_params.account_ids();
let mut authorities = self.chain_spec_params.authorities_account_ids();
if authorities.is_empty() {
if account_ids.is_empty() {
return Err(
("Both --account-ids and --authorities-account-ids are empty. \
Please specify at least one account.")
.into(),
);
}
authorities = account_ids.clone();
} else if !authorities
.iter()
.all(|authority| account_ids.contains(authority))
{
return Err("--authorities-account-ids must be a subset of --accounts-ids.".into());
}

let account_session_keys = self
Expand Down

0 comments on commit e44450f

Please sign in to comment.