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

use RuntimeGenesisConfig in genesis config presets #451

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

### Changed

- Allow signed origins to send arbitrary XCMs from some system chains ([polkadot-fellows/runtimes#407](https://github.com/polkadot-fellows/runtimes/pull/407))
- Allow signed origins to send arbitrary XCMs from some system chains ([polkadot-fellows/runtimes#407](https://github.com/polkadot-fellows/runtimes/pull/407)).
- Genesis config presets: Make use of RuntimeGenesisConfig to construct genesis config values for all runtimes ([polkadot-fellows/runtimes#451](https://github.com/polkadot-fellows/runtimes/pull/451)).

### Fixed

Expand Down
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 @@ -28,41 +28,50 @@ fn asset_hub_kusama_genesis(
endowed_accounts: Vec<AccountId>,
id: ParaId,
) -> serde_json::Value {
serde_json::json!({
"balances": BalancesConfig {
let config = RuntimeGenesisConfig {
system: Default::default(),
balances: BalancesConfig {
balances: endowed_accounts
.iter()
.cloned()
.map(|k| (k, ASSET_HUB_KUSAMA_ED * 4096 * 4096))
.collect(),
},
"parachainInfo": ParachainInfoConfig {
parachain_id: id,
..Default::default()
},
"collatorSelection": CollatorSelectionConfig {
transaction_payment: Default::default(),
parachain_info: ParachainInfoConfig { parachain_id: id, ..Default::default() },
collator_selection: CollatorSelectionConfig {
invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(),
candidacy_bond: ASSET_HUB_KUSAMA_ED * 16,
..Default::default()
},
"session": SessionConfig {
session: SessionConfig {
keys: invulnerables
.into_iter()
.map(|(acc, aura)| {
(
acc.clone(), // account id
acc, // validator id
SessionKeys { aura }, // session keys
acc.clone(), // account id
acc, // validator id
SessionKeys { aura }, // session keys
)
})
.collect(),
},
"polkadotXcm": {
"safeXcmVersion": Some(SAFE_XCM_VERSION),
},
// no need to pass anything to aura, in fact it will panic if we do. Session will take care
// of this. `aura: Default::default()`
})
aura: Default::default(),
aura_ext: Default::default(),
polkadot_xcm: PolkadotXcmConfig {
_config: Default::default(),
safe_xcm_version: Some(SAFE_XCM_VERSION),
},
assets: Default::default(),
foreign_assets: Default::default(),
parachain_system: Default::default(),
vesting: Default::default(),
pool_assets: Default::default(),
Comment on lines +61 to +71
Copy link
Contributor

@bkontur bkontur Sep 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dharjeezy Is it intentional to name all the genesis fields here? Could we just use ..Default::default(), for them? Every time we add a new pallet to the runtime, we would also need to add xyz = Default::default() here.

Suggested change
aura: Default::default(),
aura_ext: Default::default(),
polkadot_xcm: PolkadotXcmConfig {
_config: Default::default(),
safe_xcm_version: Some(SAFE_XCM_VERSION),
},
assets: Default::default(),
foreign_assets: Default::default(),
parachain_system: Default::default(),
vesting: Default::default(),
pool_assets: Default::default(),
polkadot_xcm: PolkadotXcmConfig {
_config: Default::default(),
safe_xcm_version: Some(SAFE_XCM_VERSION),
},
..Default::default(),

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@michalkucharczyk wdyt here also?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

..Default::default() shall be used.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also adding link to related discussion: paritytech/polkadot-sdk#5327 (comment)

};

serde_json::to_value(config).expect("Could not build genesis config.")
}

pub fn asset_hub_kusama_local_testnet_genesis(para_id: ParaId) -> serde_json::Value {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,41 +44,50 @@ fn asset_hub_polkadot_genesis(
endowed_accounts: Vec<AccountId>,
id: ParaId,
) -> serde_json::Value {
serde_json::json!({
"balances": BalancesConfig {
let config = RuntimeGenesisConfig {
system: Default::default(),
balances: BalancesConfig {
balances: endowed_accounts
.iter()
.cloned()
.map(|k| (k, ASSET_HUB_POLKADOT_ED * 4096 * 4096))
.collect(),
},
"parachainInfo": ParachainInfoConfig {
parachain_id: id,
..Default::default()
},
"collatorSelection": CollatorSelectionConfig {
transaction_payment: Default::default(),
parachain_info: ParachainInfoConfig { parachain_id: id, ..Default::default() },
collator_selection: CollatorSelectionConfig {
invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(),
candidacy_bond: ASSET_HUB_POLKADOT_ED * 16,
..Default::default()
},
"session": SessionConfig {
session: SessionConfig {
keys: invulnerables
.into_iter()
.map(|(acc, aura)| {
(
acc.clone(), // account id
acc, // validator id
SessionKeys { aura }, // session keys
acc.clone(), // account id
acc, // validator id
SessionKeys { aura }, // session keys
)
})
.collect(),
},
"polkadotXcm": {
"safeXcmVersion": Some(SAFE_XCM_VERSION),
},
// no need to pass anything to aura, in fact it will panic if we do. Session will take care
// of this. `aura: Default::default()`
})
aura: Default::default(),
aura_ext: Default::default(),
polkadot_xcm: PolkadotXcmConfig {
_config: Default::default(),
safe_xcm_version: Some(SAFE_XCM_VERSION),
},
assets: Default::default(),
foreign_assets: Default::default(),
parachain_system: Default::default(),
vesting: Default::default(),
pool_assets: Default::default(),
};

serde_json::to_value(config).expect("Could not build genesis config.")
}

pub fn asset_hub_polkadot_local_testnet_genesis(para_id: ParaId) -> serde_json::Value {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,41 +28,52 @@ fn bridge_hub_kusama_genesis(
endowed_accounts: Vec<AccountId>,
id: ParaId,
) -> serde_json::Value {
serde_json::json!({
"balances": BalancesConfig {
let config = RuntimeGenesisConfig {
system: Default::default(),
balances: BalancesConfig {
balances: endowed_accounts
.iter()
.cloned()
.map(|k| (k, BRIDGE_HUB_KUSAMA_ED * 4096 * 4096))
.collect(),
},
"parachainInfo": ParachainInfoConfig {
parachain_id: id,
..Default::default()
},
"collatorSelection": CollatorSelectionConfig {
parachain_info: ParachainInfoConfig { parachain_id: id, ..Default::default() },
collator_selection: CollatorSelectionConfig {
invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(),
candidacy_bond: BRIDGE_HUB_KUSAMA_ED * 16,
..Default::default()
},
"session": SessionConfig {
session: SessionConfig {
keys: invulnerables
.into_iter()
.map(|(acc, aura)| {
(
acc.clone(), // account id
acc, // validator id
SessionKeys { aura }, // session keys
acc.clone(), // account id
acc, // validator id
SessionKeys { aura }, // session keys
)
})
.collect(),
},
"polkadotXcm": {
"safeXcmVersion": Some(SAFE_XCM_VERSION),
},
// no need to pass anything to aura, in fact it will panic if we do. Session will take care
// of this. `aura: Default::default()`
})
aura: Default::default(),
aura_ext: Default::default(),
polkadot_xcm: PolkadotXcmConfig {
_config: Default::default(),
safe_xcm_version: Some(SAFE_XCM_VERSION),
},
bridge_polkadot_grandpa: Default::default(),
bridge_polkadot_parachains: Default::default(),
parachain_system: Default::default(),
transaction_payment: Default::default(),
bridge_polkadot_messages: Default::default(),
};

let mut config_values = serde_json::to_value(config).expect("Could not build genesis config.");
remove_phantom_fields(&mut config_values);

config_values
}

pub fn bridge_hub_kusama_local_testnet_genesis(para_id: ParaId) -> serde_json::Value {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,46 +28,57 @@ fn bridge_hub_polkadot_genesis(
endowed_accounts: Vec<AccountId>,
id: ParaId,
) -> serde_json::Value {
serde_json::json!({
"balances": BalancesConfig {
let config = RuntimeGenesisConfig {
system: Default::default(),
balances: BalancesConfig {
balances: endowed_accounts
.iter()
.cloned()
.map(|k| (k, BRIDGE_HUB_POLKADOT_ED * 4096 * 4096))
.collect(),
},
"parachainInfo": ParachainInfoConfig {
parachain_id: id,
..Default::default()
},
"collatorSelection": CollatorSelectionConfig {
parachain_info: ParachainInfoConfig { parachain_id: id, ..Default::default() },
collator_selection: CollatorSelectionConfig {
invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(),
candidacy_bond: BRIDGE_HUB_POLKADOT_ED * 16,
..Default::default()
},
"session": SessionConfig {
session: SessionConfig {
keys: invulnerables
.into_iter()
.map(|(acc, aura)| {
(
acc.clone(), // account id
acc, // validator id
acc.clone(), // account id
acc, // validator id
SessionKeys { aura }, // session keys
)
})
.collect(),
},
"polkadotXcm": {
"safeXcmVersion": Some(SAFE_XCM_VERSION),
aura: Default::default(),
aura_ext: Default::default(),
polkadot_xcm: PolkadotXcmConfig {
_config: Default::default(),
safe_xcm_version: Some(SAFE_XCM_VERSION),
},
"ethereumSystem": EthereumSystemConfig {
bridge_kusama_grandpa: Default::default(),
bridge_kusama_parachains: Default::default(),
bridge_kusama_messages: Default::default(),
ethereum_system: EthereumSystemConfig {
para_id: id,
asset_hub_para_id: polkadot_runtime_constants::system_parachain::ASSET_HUB_ID.into(),
..Default::default()
},
// no need to pass anything to aura, in fact it will panic if we do. Session will take care
// of this. `aura: Default::default()`
})
parachain_system: Default::default(),
transaction_payment: Default::default(),
};

let mut config_values = serde_json::to_value(config).expect("Could not build genesis config.");
remove_phantom_fields(&mut config_values);

config_values
}

pub fn bridge_hub_polkadot_local_testnet_genesis(para_id: ParaId) -> serde_json::Value {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,41 +28,53 @@ fn collectives_polkadot_genesis(
endowed_accounts: Vec<AccountId>,
id: ParaId,
) -> serde_json::Value {
serde_json::json!({
"balances": BalancesConfig {
let config = RuntimeGenesisConfig {
system: Default::default(),
balances: BalancesConfig {
balances: endowed_accounts
.iter()
.cloned()
.map(|k| (k, COLLECTIVES_POLKADOT_ED * 4096 * 4096))
.collect(),
},
"parachainInfo": ParachainInfoConfig {
parachain_id: id,
..Default::default()
},
"collatorSelection": CollatorSelectionConfig {
parachain_info: ParachainInfoConfig { parachain_id: id, ..Default::default() },
collator_selection: CollatorSelectionConfig {
invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(),
candidacy_bond: COLLECTIVES_POLKADOT_ED * 16,
..Default::default()
},
"session": SessionConfig {
session: SessionConfig {
keys: invulnerables
.into_iter()
.map(|(acc, aura)| {
(
acc.clone(), // account id
acc, // validator id
SessionKeys { aura }, // session keys
acc.clone(), // account id
acc, // validator id
SessionKeys { aura }, // session keys
)
})
.collect(),
},
"polkadotXcm": {
"safeXcmVersion": Some(SAFE_XCM_VERSION),
},
// no need to pass anything to aura, in fact it will panic if we do. Session will take care
// of this. `aura: Default::default()`
})
aura: Default::default(),
aura_ext: Default::default(),
polkadot_xcm: PolkadotXcmConfig {
_config: Default::default(),
safe_xcm_version: Some(SAFE_XCM_VERSION),
},
alliance: Default::default(),
alliance_motion: Default::default(),
fellowship_treasury: Default::default(),
parachain_system: Default::default(),
transaction_payment: Default::default(),
ambassador_treasury: Default::default(),
};

let mut config_values = serde_json::to_value(config).expect("Could not build genesis config.");
remove_phantom_fields(&mut config_values);

config_values
}

pub fn collectives_polkadot_local_testnet_genesis(para_id: ParaId) -> serde_json::Value {
Expand Down
1 change: 1 addition & 0 deletions system-parachains/constants/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ sp-core = { workspace = true }
sp-runtime = { workspace = true }
sp-std = { workspace = true }
xcm = { workspace = true }
serde_json = { features = ["alloc"], workspace = true }

[features]
default = ["std"]
Expand Down
18 changes: 18 additions & 0 deletions system-parachains/constants/src/genesis_presets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

use parachains_common::AuraId;
use polkadot_primitives::{AccountId, AccountPublic};
use serde_json::Value;
use sp_core::{sr25519, Pair, Public};
use sp_runtime::traits::IdentifyAccount;
#[cfg(not(feature = "std"))]
Expand Down Expand Up @@ -66,3 +67,20 @@ where

/// The default XCM version to set in genesis config.
pub const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION;

pub fn remove_phantom_fields(value: &mut Value) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dharjeezy I think that we don't need to remove anything here, e.g. these phantoms... so I would revert remove_phantom_fields stuff. It is not enough just phantom, e.g. some of the pallets use _config or config or _phantom. The pallet's GeneisConfig should not serialize those, e.g. paritytech/polkadot-sdk@6226e84

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@michalkucharczyk wdyt here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[#serde(skip)] shall be used for phantom fields.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means i have to open a PR in polkadot-sdk to include the [#serde(skip)] annotation for these pallets because they don't actually have them example is the pallet-bridge-messages pallet? @michalkucharczyk @bkontur

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, PR shall be opened. In that case, IMO we could keep this function until clean-up PR is merged (some annotations would be nice).

As alternative (and probably better solution) you could experiment with removing the fields that were not customized from the final JSON (see this discussion).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means i have to open a PR in polkadot-sdk to include the [#serde(skip)] annotation for these pallets because they don't actually have them example is the pallet-bridge-messages pallet? @michalkucharczyk @bkontur

@dharjeezy actually, this pallet was fixed already in the master: https://github.com/paritytech/polkadot-sdk/blob/master/bridges/modules/messages/src/lib.rs#L539-L540, but if you have there any others, please feel free to open PR to polkadot-sdk

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i just saw that it is now added, we will have to wait for a new release.

match value {
Value::Object(map) => {
map.remove("phantom");

for (_, v) in map.iter_mut() {
remove_phantom_fields(v);
}
},
Value::Array(arr) =>
for v in arr.iter_mut() {
remove_phantom_fields(v);
},
_ => {},
}
}
Loading
Loading