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

RuntimeGenesiConfig: json macro added #5813

Merged
merged 23 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use crate::*;
use alloc::{vec, vec::Vec};
use cumulus_primitives_core::ParaId;
use frame_support::build_struct_json_patch;
use hex_literal::hex;
use parachains_common::{AccountId, AuraId};
use sp_core::crypto::UncheckedInto;
Expand All @@ -33,15 +34,14 @@ fn asset_hub_rococo_genesis(
endowment: Balance,
id: ParaId,
) -> serde_json::Value {
let config = RuntimeGenesisConfig {
build_struct_json_patch!(RuntimeGenesisConfig {
balances: BalancesConfig {
balances: endowed_accounts.iter().cloned().map(|k| (k, endowment)).collect(),
},
parachain_info: ParachainInfoConfig { parachain_id: id, ..Default::default() },
parachain_info: ParachainInfoConfig { parachain_id: id },
collator_selection: CollatorSelectionConfig {
invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(),
candidacy_bond: ASSET_HUB_ROCOCO_ED * 16,
..Default::default()
},
session: SessionConfig {
keys: invulnerables
Expand All @@ -54,16 +54,9 @@ fn asset_hub_rococo_genesis(
)
})
.collect(),
..Default::default()
},
polkadot_xcm: PolkadotXcmConfig {
safe_xcm_version: Some(SAFE_XCM_VERSION),
..Default::default()
},
..Default::default()
};

serde_json::to_value(config).expect("Could not build genesis config.")
polkadot_xcm: PolkadotXcmConfig { safe_xcm_version: Some(SAFE_XCM_VERSION) },
})
}

/// Encapsulates names of predefined presets.
Expand Down
17 changes: 5 additions & 12 deletions polkadot/runtime/westend/src/genesis_config_presets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use crate::{
#[cfg(not(feature = "std"))]
use alloc::format;
use alloc::{vec, vec::Vec};
use frame_support::build_struct_json_patch;
use pallet_staking::{Forcing, StakerStatus};
use polkadot_primitives::{AccountId, AssignmentId, SchedulerParams, ValidatorId};
use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId;
Expand Down Expand Up @@ -170,7 +171,7 @@ fn westend_testnet_genesis(
const ENDOWMENT: u128 = 1_000_000 * WND;
const STASH: u128 = 100 * WND;

let config = RuntimeGenesisConfig {
build_struct_json_patch!(RuntimeGenesisConfig {
bkontur marked this conversation as resolved.
Show resolved Hide resolved
balances: BalancesConfig {
balances: endowed_accounts.iter().map(|k| (k.clone(), ENDOWMENT)).collect::<Vec<_>>(),
},
Expand All @@ -192,7 +193,6 @@ fn westend_testnet_genesis(
)
})
.collect::<Vec<_>>(),
..Default::default()
},
staking: StakingConfig {
minimum_validator_count: 1,
Expand All @@ -204,19 +204,12 @@ fn westend_testnet_genesis(
invulnerables: initial_authorities.iter().map(|x| x.0.clone()).collect::<Vec<_>>(),
force_era: Forcing::NotForcing,
slash_reward_fraction: Perbill::from_percent(10),
..Default::default()
},
babe: BabeConfig { epoch_config: BABE_GENESIS_EPOCH_CONFIG, ..Default::default() },
babe: BabeConfig { epoch_config: BABE_GENESIS_EPOCH_CONFIG },
sudo: SudoConfig { key: Some(root_key) },
configuration: ConfigurationConfig { config: default_parachains_host_configuration() },
registrar: RegistrarConfig {
next_free_para_id: polkadot_primitives::LOWEST_PUBLIC_ID,
..Default::default()
},
..Default::default()
};

serde_json::to_value(config).expect("Could not build genesis config.")
registrar: RegistrarConfig { next_free_para_id: polkadot_primitives::LOWEST_PUBLIC_ID },
})
}

// staging_testnet
Expand Down
18 changes: 18 additions & 0 deletions prdoc/pr_5813.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
title: "build_struct_json_patch macro added"

doc:
- audience: Runtime Dev
description: |
This PR adds a macro that allows to construct a RuntimeGenesisConfig preset
containing only provided fields, while performing the validation of the
entire struct.

Related issue: https://github.com/paritytech/polkadot-sdk/issues/5700

crates:
- name: frame-support
bump: minor
- name: asset-hub-rococo-runtime
bump: patch
- name: westend-runtime
bump: patch
1 change: 1 addition & 0 deletions substrate/frame/support/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ pretty_assertions = { workspace = true }
sp-timestamp = { workspace = true }
frame-system = { workspace = true, default-features = true }
sp-crypto-hashing = { workspace = true, default-features = true }
Inflector = { workspace = true }

[features]
default = ["std"]
Expand Down
Loading
Loading