Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Balances: Configurable Number of Genesis Accounts with Specified Balances for Benchmarking #6267

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion bridges/modules/messages/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ pub fn inbound_unrewarded_relayers_state(lane: TestLaneIdType) -> UnrewardedRela
/// Return test externalities to use in tests.
pub fn new_test_ext() -> sp_io::TestExternalities {
let mut t = frame_system::GenesisConfig::<TestRuntime>::default().build_storage().unwrap();
pallet_balances::GenesisConfig::<TestRuntime> { balances: vec![(ENDOWED_ACCOUNT, 1_000_000)] }
pallet_balances::GenesisConfig::<TestRuntime> { balances: vec![(ENDOWED_ACCOUNT, 1_000_000)], ..Default::default() }
.assimilate_storage(&mut t)
.unwrap();
sp_io::TestExternalities::new(t)
Expand Down
2 changes: 1 addition & 1 deletion cumulus/pallets/collator-selection/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
invulnerables,
};
let session = pallet_session::GenesisConfig::<Test> { keys, ..Default::default() };
pallet_balances::GenesisConfig::<Test> { balances }
pallet_balances::GenesisConfig::<Test> { balances, ..Default::default() }
.assimilate_storage(&mut t)
.unwrap();
// collator selection must be initialized before session.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn asset_hub_rococo_genesis(
) -> serde_json::Value {
build_struct_json_patch!(RuntimeGenesisConfig {
balances: BalancesConfig {
balances: endowed_accounts.iter().cloned().map(|k| (k, endowment)).collect(),
balances: endowed_accounts.iter().cloned().map(|k| (k, endowment)).collect()
},
parachain_info: ParachainInfoConfig { parachain_id: id },
collator_selection: CollatorSelectionConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn asset_hub_westend_genesis(
) -> serde_json::Value {
build_struct_json_patch!(RuntimeGenesisConfig {
balances: BalancesConfig {
balances: endowed_accounts.iter().cloned().map(|k| (k, endowment)).collect(),
balances: endowed_accounts.iter().cloned().map(|k| (k, endowment)).collect()
},
parachain_info: ParachainInfoConfig { parachain_id: id },
collator_selection: CollatorSelectionConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn bridge_hub_rococo_genesis(
.iter()
.cloned()
.map(|k| (k, 1u128 << 60))
.collect::<Vec<_>>(),
.collect::<Vec<_>>()
},
parachain_info: ParachainInfoConfig { parachain_id: id },
collator_selection: CollatorSelectionConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn bridge_hub_westend_genesis(
.iter()
.cloned()
.map(|k| (k, 1u128 << 60))
.collect::<Vec<_>>(),
.collect::<Vec<_>>()
},
parachain_info: ParachainInfoConfig { parachain_id: id },
collator_selection: CollatorSelectionConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn collectives_westend_genesis(
.iter()
.cloned()
.map(|k| (k, COLLECTIVES_WESTEND_ED * 4096))
.collect::<Vec<_>>(),
.collect::<Vec<_>>()
},
parachain_info: ParachainInfoConfig { parachain_id: id },
collator_selection: CollatorSelectionConfig {
Expand Down
1 change: 1 addition & 0 deletions polkadot/runtime/common/src/assigned_slots/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,7 @@ mod tests {
let mut t = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap();
pallet_balances::GenesisConfig::<Test> {
balances: vec![(1, 10), (2, 20), (3, 30), (4, 40), (5, 50), (6, 60)],
..Default::default()
}
.assimilate_storage(&mut t)
.unwrap();
Expand Down
1 change: 1 addition & 0 deletions polkadot/runtime/common/src/auctions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,7 @@ mod tests {
let mut t = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap();
pallet_balances::GenesisConfig::<Test> {
balances: vec![(1, 10), (2, 20), (3, 30), (4, 40), (5, 50), (6, 60)],
..Default::default()
}
.assimilate_storage(&mut t)
.unwrap();
Expand Down
1 change: 1 addition & 0 deletions polkadot/runtime/common/src/crowdloan/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,7 @@ mod tests {
let mut t = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap();
pallet_balances::GenesisConfig::<Test> {
balances: vec![(1, 1000), (2, 2000), (3, 3000), (4, 4000)],
..Default::default()
}
.assimilate_storage(&mut t)
.unwrap();
Expand Down
1 change: 1 addition & 0 deletions polkadot/runtime/common/src/paras_registrar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,7 @@ mod tests {

pallet_balances::GenesisConfig::<Test> {
balances: vec![(1, 10_000_000), (2, 10_000_000), (3, 10_000_000)],
..Default::default()
}
.assimilate_storage(&mut t)
.unwrap();
Expand Down
1 change: 1 addition & 0 deletions polkadot/runtime/common/src/slots/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,7 @@ mod tests {
let mut t = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap();
pallet_balances::GenesisConfig::<Test> {
balances: vec![(1, 10), (2, 20), (3, 30), (4, 40), (5, 50), (6, 60)],
..Default::default()
}
.assimilate_storage(&mut t)
.unwrap();
Expand Down
4 changes: 2 additions & 2 deletions polkadot/runtime/rococo/src/genesis_config_presets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ fn rococo_testnet_genesis(

build_struct_json_patch!(RuntimeGenesisConfig {
balances: BalancesConfig {
balances: endowed_accounts.iter().map(|k| (k.clone(), ENDOWMENT)).collect::<Vec<_>>(),
balances: endowed_accounts.iter().map(|k| (k.clone(), ENDOWMENT)).collect::<Vec<_>>()
},
session: SessionConfig {
keys: initial_authorities
Expand Down Expand Up @@ -427,7 +427,7 @@ fn rococo_staging_testnet_config_genesis() -> serde_json::Value {
.iter()
.map(|k: &AccountId| (k.clone(), ENDOWMENT))
.chain(initial_authorities.iter().map(|x| (x.0.clone(), STASH)))
.collect::<Vec<_>>(),
.collect::<Vec<_>>()
},
session: SessionConfig {
keys: initial_authorities
Expand Down
4 changes: 2 additions & 2 deletions polkadot/runtime/westend/src/genesis_config_presets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ fn westend_testnet_genesis(

build_struct_json_patch!(RuntimeGenesisConfig {
balances: BalancesConfig {
balances: endowed_accounts.iter().map(|k| (k.clone(), ENDOWMENT)).collect::<Vec<_>>(),
balances: endowed_accounts.iter().map(|k| (k.clone(), ENDOWMENT)).collect::<Vec<_>>()
},
session: SessionConfig {
keys: initial_authorities
Expand Down Expand Up @@ -344,7 +344,7 @@ fn westend_staging_testnet_config_genesis() -> serde_json::Value {
.iter()
.map(|k: &AccountId| (k.clone(), ENDOWMENT))
.chain(initial_authorities.iter().map(|x| (x.0.clone(), STASH)))
.collect::<Vec<_>>(),
.collect::<Vec<_>>()
},
session: SessionConfig {
keys: initial_authorities
Expand Down
2 changes: 1 addition & 1 deletion polkadot/xcm/pallet-xcm/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ pub(crate) fn new_test_ext_with_balances_and_xcm_version(
) -> sp_io::TestExternalities {
let mut t = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap();

pallet_balances::GenesisConfig::<Test> { balances }
pallet_balances::GenesisConfig::<Test> { balances, ..Default::default() }
.assimilate_storage(&mut t)
.unwrap();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities {

pallet_balances::GenesisConfig::<Runtime> {
balances: vec![(0, INITIAL_BALANCE), (1, INITIAL_BALANCE), (2, INITIAL_BALANCE)],
..Default::default()
}
.assimilate_storage(&mut t)
.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion polkadot/xcm/xcm-builder/tests/mock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ construct_runtime!(
pub fn kusama_like_with_balances(balances: Vec<(AccountId, Balance)>) -> sp_io::TestExternalities {
let mut t = frame_system::GenesisConfig::<Runtime>::default().build_storage().unwrap();

pallet_balances::GenesisConfig::<Runtime> { balances }
pallet_balances::GenesisConfig::<Runtime> { balances, ..Default::default() }
.assimilate_storage(&mut t)
.unwrap();

Expand Down
4 changes: 2 additions & 2 deletions polkadot/xcm/xcm-runtime-apis/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ impl pallet_xcm::Config for TestRuntime {
pub fn new_test_ext_with_balances(balances: Vec<(AccountId, Balance)>) -> sp_io::TestExternalities {
let mut t = frame_system::GenesisConfig::<TestRuntime>::default().build_storage().unwrap();

pallet_balances::GenesisConfig::<TestRuntime> { balances }
pallet_balances::GenesisConfig::<TestRuntime> { balances, ..Default::default() }
.assimilate_storage(&mut t)
.unwrap();

Expand All @@ -380,7 +380,7 @@ pub fn new_test_ext_with_balances_and_assets(
) -> sp_io::TestExternalities {
let mut t = frame_system::GenesisConfig::<TestRuntime>::default().build_storage().unwrap();

pallet_balances::GenesisConfig::<TestRuntime> { balances }
pallet_balances::GenesisConfig::<TestRuntime> { balances, ..Default::default() }
.assimilate_storage(&mut t)
.unwrap();

Expand Down
2 changes: 2 additions & 0 deletions polkadot/xcm/xcm-simulator/example/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ pub fn para_ext(para_id: u32) -> sp_io::TestExternalities {

pallet_balances::GenesisConfig::<Runtime> {
balances: vec![(ALICE, INITIAL_BALANCE), (parent_account_id(), INITIAL_BALANCE)],
..Default::default()
}
.assimilate_storage(&mut t)
.unwrap();
Expand All @@ -125,6 +126,7 @@ pub fn relay_ext() -> sp_io::TestExternalities {
(child_account_id(1), INITIAL_BALANCE),
(child_account_id(2), INITIAL_BALANCE),
],
..Default::default()
}
.assimilate_storage(&mut t)
.unwrap();
Expand Down
3 changes: 2 additions & 1 deletion polkadot/xcm/xcm-simulator/fuzzer/src/fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ pub fn para_ext(para_id: u32) -> sp_io::TestExternalities {

pallet_balances::GenesisConfig::<Runtime> {
balances: (0..6).map(|i| ([i; 32].into(), INITIAL_BALANCE)).collect(),
..Default::default()
}
.assimilate_storage(&mut t)
.unwrap();
Expand All @@ -138,7 +139,7 @@ pub fn relay_ext() -> sp_io::TestExternalities {
balances.append(&mut (1..=3).map(|i| (para_account_id(i), INITIAL_BALANCE)).collect());
balances.append(&mut (0..6).map(|i| ([i; 32].into(), INITIAL_BALANCE)).collect());

pallet_balances::GenesisConfig::<Runtime> { balances }
pallet_balances::GenesisConfig::<Runtime> { balances, ..Default::default() }
.assimilate_storage(&mut t)
.unwrap();

Expand Down
121 changes: 121 additions & 0 deletions prdoc/pr_6267.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json

title: Allow configurable number of genesis accounts with specified balances for benchmarking.

doc:
- audience: Runtime Dev
description: |
This pull request adds an additional field `dev_accounts` to the `GenesisConfig`
of the balances pallet, feature gated by `runtime-benchmarks`.

Bringing about an abitrary number of derived dev accounts when building the genesis
state. Runtime developers should supply a derivation path that includes an index placeholder
(i.e. "//Sender/{}") to generate multiple accounts from the same root in a consistent
manner.

crates:
- name: substrate-test-runtime
bump: minor
- name: pallet-vesting
bump: minor
- name: pallet-utility
bump: minor
- name: pallet-tx-pause
bump: minor
- name: pallet-treasury
bump: minor
- name: pallet-transaction-storage
bump: minor
- name: pallet-transaction-payment
bump: minor
- name: pallet-asset-conversion-tx-payment
bump: minor
- name: pallet-asset-tx-payment
bump: minor
- name: pallet-tips
bump: minor
- name: pallet-state-trie-migration
bump: minor
- name: pallet-staking
bump: minor
- name: pallet-society
bump: minor
- name: pallet-safe-mode
bump: minor
- name: pallet-root-offences
bump: minor
- name: pallet-revive
bump: minor
- name: pallet-revive-mock-network
bump: minor
- name: pallet-referenda
bump: minor
- name: pallet-recovery
bump: minor
- name: pallet-proxy
bump: minor
- name: pallet-preimage
bump: minor
- name: pallet-nis
bump: minor
- name: pallet-multisig
bump: minor
- name: pallet-lottery
bump: minor
- name: pallet-indices
bump: minor
- name: pallet-identity
bump: minor
- name: pallet-grandpa
bump: minor
- name: pallet-fast-unstake
bump: minor
- name: pallet-elections-phragmen
bump: minor
- name: pallet-election-provider-multi-phase
bump: minor
- name: pallet-democracy
bump: minor
- name: pallet-delegated-staking
bump: minor
- name: pallet-conviction-voting
bump: minor
- name: pallet-contracts
bump: minor
- name: pallet-contracts-mock-network
bump: minor
- name: pallet-collective
bump: minor
- name: pallet-child-bounties
bump: minor
- name: pallet-bounties
bump: minor
- name: pallet-balances
bump: minor
- name: pallet-babe
bump: minor
- name: pallet-asset-conversion
bump: minor
- name: pallet-asset-conversion-ops
bump: minor
- name: pallet-alliance
bump: minor
- name: node-testing
bump: minor
- name: xcm-simulator-fuzzer
bump: minor
- name: xcm-simulator-example
bump: minor
- name: xcm-runtime-apis
bump: minor
- name: staging-xcm-builder
bump: minor
- name: pallet-xcm
bump: minor
- name: polkadot-runtime-common
bump: minor
- name: pallet-collator-selection
bump: minor
- name: pallet-bridge-messages
bump: minor
1 change: 1 addition & 0 deletions substrate/frame/alliance/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
(8, 1000),
(9, 1000),
],
..Default::default()
}
.assimilate_storage(&mut t)
.unwrap();
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/asset-conversion/ops/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ pub(crate) fn new_test_ext() -> sp_io::TestExternalities {

pallet_balances::GenesisConfig::<Test> {
balances: vec![(1, 10000), (2, 20000), (3, 30000), (4, 40000)],
..Default::default()
}
.assimilate_storage(&mut t)
.unwrap();
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/asset-conversion/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ pub(crate) fn new_test_ext() -> sp_io::TestExternalities {

pallet_balances::GenesisConfig::<Test> {
balances: vec![(1, 10000), (2, 20000), (3, 30000), (4, 40000)],
..Default::default()
}
.assimilate_storage(&mut t)
.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/babe/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ pub fn new_test_ext_raw_authorities(authorities: Vec<AuthorityId>) -> sp_io::Tes

let balances: Vec<_> = (0..authorities.len()).map(|i| (i as u64, 10_000_000)).collect();

pallet_balances::GenesisConfig::<Test> { balances }
pallet_balances::GenesisConfig::<Test> { balances, ..Default::default() }
.assimilate_storage(&mut t)
.unwrap();

Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/balances/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ frame-support = { workspace = true }
frame-system = { workspace = true }
sp-runtime = { workspace = true }
docify = { workspace = true }
sp-core = { workspace = true }

[dev-dependencies]
pallet-transaction-payment = { workspace = true, default-features = true }
frame-support = { features = ["experimental"], workspace = true, default-features = true }
sp-core = { workspace = true, default-features = true }
sp-io = { workspace = true, default-features = true }
paste = { workspace = true, default-features = true }

Expand Down
Loading