From b3b45095ae48dc82359a392629386e73a93e0044 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Fri, 17 Jan 2025 18:10:06 +0100 Subject: [PATCH 01/33] refactor: :recycle: update deprecated options in command `moonbeam benchmark pallet` --- scripts/run-benches-for-runtime.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/run-benches-for-runtime.sh b/scripts/run-benches-for-runtime.sh index e94a2d31f6..aada596b7c 100755 --- a/scripts/run-benches-for-runtime.sh +++ b/scripts/run-benches-for-runtime.sh @@ -39,7 +39,9 @@ for PALLET in "${PALLETS[@]}"; do OUTPUT=$( ./target/${profile}/moonbeam benchmark pallet \ - --chain="${runtime}-dev" \ + --runtime="./target/${profile}/wbuild/${runtime}-runtime/${runtime}_runtime.wasm" \ + --genesis-builder=runtime \ + --genesis-builder-preset=development \ --steps=50 \ --repeat=20 \ --pallet="$PALLET" \ From aeecd0d04d161e2cac3e4ec449d49254cfeaa3ee Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Fri, 17 Jan 2025 18:49:37 +0100 Subject: [PATCH 02/33] refactor: :recycle: update deprecated options in both invocations of the command within the script --- scripts/run-benches-for-runtime.sh | 36 +++++++++++++++++------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/scripts/run-benches-for-runtime.sh b/scripts/run-benches-for-runtime.sh index aada596b7c..f35c251b6e 100755 --- a/scripts/run-benches-for-runtime.sh +++ b/scripts/run-benches-for-runtime.sh @@ -13,11 +13,15 @@ cargo build --profile=$profile --locked --features=runtime-benchmarks # Load all pallet names in an array. PALLETS=($( - ./target/${profile}/moonbeam benchmark pallet --list --chain="${runtime}-dev" |\ - tail -n+2 |\ - cut -d',' -f1 |\ - sort |\ - uniq + ./target/${profile}/moonbeam benchmark pallet \ + --list \ + --runtime="./target/${profile}/wbuild/${runtime}-runtime/${runtime}_runtime.wasm" \ + --genesis-builder=runtime \ + --genesis-builder-preset=development |\ + tail -n+2 |\ + cut -d',' -f1 |\ + sort |\ + uniq )) echo "[+] Benchmarking ${#PALLETS[@]} pallets for runtime $runtime with $profile profile" @@ -39,17 +43,17 @@ for PALLET in "${PALLETS[@]}"; do OUTPUT=$( ./target/${profile}/moonbeam benchmark pallet \ - --runtime="./target/${profile}/wbuild/${runtime}-runtime/${runtime}_runtime.wasm" \ - --genesis-builder=runtime \ - --genesis-builder-preset=development \ - --steps=50 \ - --repeat=20 \ - --pallet="$PALLET" \ - --extrinsic="*" \ - --wasm-execution=compiled \ - --header=./file_header.txt \ - --template=./benchmarking/frame-weight-template.hbs \ - --output="./runtime/${output}/src/weights/${output_file}" 2>&1 + --runtime="./target/${profile}/wbuild/${runtime}-runtime/${runtime}_runtime.wasm" \ + --genesis-builder=runtime \ + --genesis-builder-preset=development \ + --steps=50 \ + --repeat=20 \ + --pallet="$PALLET" \ + --extrinsic="*" \ + --wasm-execution=compiled \ + --header=./file_header.txt \ + --template=./benchmarking/frame-weight-template.hbs \ + --output="./runtime/${output}/src/weights/${output_file}" 2>&1 ) if [ $? -ne 0 ]; then echo "$OUTPUT" >> "$ERR_FILE" From 52436cb9e0a2a428022123d15bd0bb3f103ea009 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Tue, 21 Jan 2025 12:21:49 +0100 Subject: [PATCH 03/33] feat: :sparkles: add default preset for RuntimeGenesisConfig --- Cargo.lock | 2 ++ runtime/common/Cargo.toml | 4 ++++ runtime/common/src/apis.rs | 16 ++++++++++++++-- scripts/run-benches-for-runtime.sh | 4 +--- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a1645e4030..51b69d588c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6913,6 +6913,8 @@ dependencies = [ "parity-scale-codec", "precompile-utils", "scale-info", + "serde", + "serde_json", "sp-api", "sp-consensus-slots", "sp-core", diff --git a/runtime/common/Cargo.toml b/runtime/common/Cargo.toml index d3c3027be3..fa45e6ba3c 100644 --- a/runtime/common/Cargo.toml +++ b/runtime/common/Cargo.toml @@ -11,6 +11,8 @@ version = "0.8.0-dev" hex-literal = "0.3.4" impl-trait-for-tuples = "0.2.1" log = "0.4" +serde = { workspace = true, default-features = false } +serde_json = { workspace = true, default-features = false } # Moonbeam moonbeam-core-primitives = { workspace = true } @@ -121,6 +123,8 @@ std = [ "parity-scale-codec/std", "scale-info/std", "precompile-utils/std", + "serde/std", + "serde_json/std", "sp-consensus-slots/std", "sp-core/std", "sp-io/std", diff --git a/runtime/common/src/apis.rs b/runtime/common/src/apis.rs index 144a82f966..24f778395a 100644 --- a/runtime/common/src/apis.rs +++ b/runtime/common/src/apis.rs @@ -43,6 +43,17 @@ macro_rules! impl_runtime_apis_plus_common { } } + fn default_preset() -> Option> { + let config = T::default(); + let config = serde_json::to_value(config).expect("Could not build genesis config."); + + Some( + serde_json::to_string(&config) + .expect("Could not build genesis config.") + .into_bytes(), + ) + } + impl_runtime_apis! { $($custom)* @@ -116,16 +127,17 @@ macro_rules! impl_runtime_apis_plus_common { } impl sp_genesis_builder::GenesisBuilder for Runtime { + fn build_state(config: Vec) -> sp_genesis_builder::Result { frame_support::genesis_builder_helper::build_state::(config) } fn get_preset(id: &Option) -> Option> { - frame_support::genesis_builder_helper::get_preset::(id, |_| None) + frame_support::genesis_builder_helper::get_preset::(id, default_preset::) } fn preset_names() -> Vec { - vec![] + vec![sp_genesis_builder::PresetId::from(sp_genesis_builder::DEV_RUNTIME_PRESET)] } } diff --git a/scripts/run-benches-for-runtime.sh b/scripts/run-benches-for-runtime.sh index f35c251b6e..20d22fdd52 100755 --- a/scripts/run-benches-for-runtime.sh +++ b/scripts/run-benches-for-runtime.sh @@ -16,8 +16,7 @@ PALLETS=($( ./target/${profile}/moonbeam benchmark pallet \ --list \ --runtime="./target/${profile}/wbuild/${runtime}-runtime/${runtime}_runtime.wasm" \ - --genesis-builder=runtime \ - --genesis-builder-preset=development |\ + --genesis-builder=runtime |\ tail -n+2 |\ cut -d',' -f1 |\ sort |\ @@ -45,7 +44,6 @@ for PALLET in "${PALLETS[@]}"; do ./target/${profile}/moonbeam benchmark pallet \ --runtime="./target/${profile}/wbuild/${runtime}-runtime/${runtime}_runtime.wasm" \ --genesis-builder=runtime \ - --genesis-builder-preset=development \ --steps=50 \ --repeat=20 \ --pallet="$PALLET" \ From 1c4e1d0e223ea3f16655b2c087ff4332bfb3ecfc Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Tue, 21 Jan 2025 14:15:30 +0100 Subject: [PATCH 04/33] Revert "feat: :sparkles: add default preset for RuntimeGenesisConfig" This reverts commit 52436cb9e0a2a428022123d15bd0bb3f103ea009. --- Cargo.lock | 2 -- runtime/common/Cargo.toml | 4 ---- runtime/common/src/apis.rs | 16 ++-------------- scripts/run-benches-for-runtime.sh | 4 +++- 4 files changed, 5 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 51b69d588c..a1645e4030 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6913,8 +6913,6 @@ dependencies = [ "parity-scale-codec", "precompile-utils", "scale-info", - "serde", - "serde_json", "sp-api", "sp-consensus-slots", "sp-core", diff --git a/runtime/common/Cargo.toml b/runtime/common/Cargo.toml index fa45e6ba3c..d3c3027be3 100644 --- a/runtime/common/Cargo.toml +++ b/runtime/common/Cargo.toml @@ -11,8 +11,6 @@ version = "0.8.0-dev" hex-literal = "0.3.4" impl-trait-for-tuples = "0.2.1" log = "0.4" -serde = { workspace = true, default-features = false } -serde_json = { workspace = true, default-features = false } # Moonbeam moonbeam-core-primitives = { workspace = true } @@ -123,8 +121,6 @@ std = [ "parity-scale-codec/std", "scale-info/std", "precompile-utils/std", - "serde/std", - "serde_json/std", "sp-consensus-slots/std", "sp-core/std", "sp-io/std", diff --git a/runtime/common/src/apis.rs b/runtime/common/src/apis.rs index 24f778395a..144a82f966 100644 --- a/runtime/common/src/apis.rs +++ b/runtime/common/src/apis.rs @@ -43,17 +43,6 @@ macro_rules! impl_runtime_apis_plus_common { } } - fn default_preset() -> Option> { - let config = T::default(); - let config = serde_json::to_value(config).expect("Could not build genesis config."); - - Some( - serde_json::to_string(&config) - .expect("Could not build genesis config.") - .into_bytes(), - ) - } - impl_runtime_apis! { $($custom)* @@ -127,17 +116,16 @@ macro_rules! impl_runtime_apis_plus_common { } impl sp_genesis_builder::GenesisBuilder for Runtime { - fn build_state(config: Vec) -> sp_genesis_builder::Result { frame_support::genesis_builder_helper::build_state::(config) } fn get_preset(id: &Option) -> Option> { - frame_support::genesis_builder_helper::get_preset::(id, default_preset::) + frame_support::genesis_builder_helper::get_preset::(id, |_| None) } fn preset_names() -> Vec { - vec![sp_genesis_builder::PresetId::from(sp_genesis_builder::DEV_RUNTIME_PRESET)] + vec![] } } diff --git a/scripts/run-benches-for-runtime.sh b/scripts/run-benches-for-runtime.sh index 20d22fdd52..f35c251b6e 100755 --- a/scripts/run-benches-for-runtime.sh +++ b/scripts/run-benches-for-runtime.sh @@ -16,7 +16,8 @@ PALLETS=($( ./target/${profile}/moonbeam benchmark pallet \ --list \ --runtime="./target/${profile}/wbuild/${runtime}-runtime/${runtime}_runtime.wasm" \ - --genesis-builder=runtime |\ + --genesis-builder=runtime \ + --genesis-builder-preset=development |\ tail -n+2 |\ cut -d',' -f1 |\ sort |\ @@ -44,6 +45,7 @@ for PALLET in "${PALLETS[@]}"; do ./target/${profile}/moonbeam benchmark pallet \ --runtime="./target/${profile}/wbuild/${runtime}-runtime/${runtime}_runtime.wasm" \ --genesis-builder=runtime \ + --genesis-builder-preset=development \ --steps=50 \ --repeat=20 \ --pallet="$PALLET" \ From 31d874007d24b6e598b79f1f08d2a8defbceebf2 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Tue, 21 Jan 2025 16:50:56 +0100 Subject: [PATCH 05/33] feat: :sparkles: add genesis builder dummy development preset --- Cargo.lock | 4 ++++ runtime/common/Cargo.toml | 1 + runtime/common/src/apis.rs | 20 ++++++++++++++++++-- runtime/moonbase/Cargo.toml | 1 + runtime/moonbeam/Cargo.toml | 1 + runtime/moonriver/Cargo.toml | 1 + 6 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a1645e4030..a13536f44a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6308,6 +6308,7 @@ dependencies = [ "rlp", "scale-info", "serde", + "serde_json", "session-keys-primitives", "sha3", "smallvec", @@ -6821,6 +6822,7 @@ dependencies = [ "rlp", "scale-info", "serde", + "serde_json", "session-keys-primitives", "sha3", "smallvec", @@ -6913,6 +6915,7 @@ dependencies = [ "parity-scale-codec", "precompile-utils", "scale-info", + "serde_json", "sp-api", "sp-consensus-slots", "sp-core", @@ -7251,6 +7254,7 @@ dependencies = [ "rlp", "scale-info", "serde", + "serde_json", "session-keys-primitives", "sha3", "smallvec", diff --git a/runtime/common/Cargo.toml b/runtime/common/Cargo.toml index d3c3027be3..19f46062b1 100644 --- a/runtime/common/Cargo.toml +++ b/runtime/common/Cargo.toml @@ -11,6 +11,7 @@ version = "0.8.0-dev" hex-literal = "0.3.4" impl-trait-for-tuples = "0.2.1" log = "0.4" +serde_json = { version = "1.0.114", default-features = false } # Moonbeam moonbeam-core-primitives = { workspace = true } diff --git a/runtime/common/src/apis.rs b/runtime/common/src/apis.rs index 144a82f966..8768edd419 100644 --- a/runtime/common/src/apis.rs +++ b/runtime/common/src/apis.rs @@ -43,6 +43,12 @@ macro_rules! impl_runtime_apis_plus_common { } } + fn testnet_genesis() -> serde_json::Value { + let config = RuntimeGenesisConfig::default(); + + serde_json::to_value(config).expect("Could not build genesis config.") + } + impl_runtime_apis! { $($custom)* @@ -121,11 +127,21 @@ macro_rules! impl_runtime_apis_plus_common { } fn get_preset(id: &Option) -> Option> { - frame_support::genesis_builder_helper::get_preset::(id, |_| None) + frame_support::genesis_builder_helper::get_preset::(id, |id| { + let patch = match id.try_into() { + Ok(sp_genesis_builder::DEV_RUNTIME_PRESET) => testnet_genesis(), + _ => return None, + }; + Some( + serde_json::to_string(&patch) + .expect("serialization to json is expected to work. qed.") + .into_bytes(), + ) + }) } fn preset_names() -> Vec { - vec![] + vec![sp_genesis_builder::PresetId::from(sp_genesis_builder::DEV_RUNTIME_PRESET)] } } diff --git a/runtime/moonbase/Cargo.toml b/runtime/moonbase/Cargo.toml index 8d334d43ad..3763413aba 100644 --- a/runtime/moonbase/Cargo.toml +++ b/runtime/moonbase/Cargo.toml @@ -14,6 +14,7 @@ log = { workspace = true } num_enum = { workspace = true } rlp = { workspace = true, optional = true } serde = { workspace = true, features = ["derive"] } +serde_json = { version = "1.0.114", default-features = false } sha3 = { workspace = true, optional = true } smallvec = { workspace = true } strum = { workspace = true } diff --git a/runtime/moonbeam/Cargo.toml b/runtime/moonbeam/Cargo.toml index 1f87feabe2..249c4f3310 100644 --- a/runtime/moonbeam/Cargo.toml +++ b/runtime/moonbeam/Cargo.toml @@ -14,6 +14,7 @@ log = { workspace = true } num_enum = { workspace = true } rlp = { workspace = true, optional = true } serde = { workspace = true, features = ["derive"] } +serde_json = { version = "1.0.114", default-features = false } sha3 = { workspace = true, optional = true } smallvec = { workspace = true } strum = { workspace = true } diff --git a/runtime/moonriver/Cargo.toml b/runtime/moonriver/Cargo.toml index 7ac5e41d7d..10faba487d 100644 --- a/runtime/moonriver/Cargo.toml +++ b/runtime/moonriver/Cargo.toml @@ -14,6 +14,7 @@ log = { workspace = true } num_enum = { workspace = true } rlp = { workspace = true, optional = true } serde = { workspace = true, features = ["derive"] } +serde_json = { version = "1.0.114", default-features = false } sha3 = { workspace = true, optional = true } smallvec = { workspace = true } strum = { workspace = true } From 94bc298b3df389e80765a4c0daf6dc6a8d9377fd Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Tue, 21 Jan 2025 17:34:53 +0100 Subject: [PATCH 06/33] refactor: :recycle: implement GenesisBuilder within each runtime --- runtime/common/src/apis.rs | 30 ------------------------------ runtime/moonbase/src/lib.rs | 27 +++++++++++++++++++++++++++ runtime/moonbeam/src/lib.rs | 27 +++++++++++++++++++++++++++ runtime/moonriver/src/lib.rs | 27 +++++++++++++++++++++++++++ 4 files changed, 81 insertions(+), 30 deletions(-) diff --git a/runtime/common/src/apis.rs b/runtime/common/src/apis.rs index 8768edd419..0ea4d99df3 100644 --- a/runtime/common/src/apis.rs +++ b/runtime/common/src/apis.rs @@ -43,12 +43,6 @@ macro_rules! impl_runtime_apis_plus_common { } } - fn testnet_genesis() -> serde_json::Value { - let config = RuntimeGenesisConfig::default(); - - serde_json::to_value(config).expect("Could not build genesis config.") - } - impl_runtime_apis! { $($custom)* @@ -121,30 +115,6 @@ macro_rules! impl_runtime_apis_plus_common { } } - impl sp_genesis_builder::GenesisBuilder for Runtime { - fn build_state(config: Vec) -> sp_genesis_builder::Result { - frame_support::genesis_builder_helper::build_state::(config) - } - - fn get_preset(id: &Option) -> Option> { - frame_support::genesis_builder_helper::get_preset::(id, |id| { - let patch = match id.try_into() { - Ok(sp_genesis_builder::DEV_RUNTIME_PRESET) => testnet_genesis(), - _ => return None, - }; - Some( - serde_json::to_string(&patch) - .expect("serialization to json is expected to work. qed.") - .into_bytes(), - ) - }) - } - - fn preset_names() -> Vec { - vec![sp_genesis_builder::PresetId::from(sp_genesis_builder::DEV_RUNTIME_PRESET)] - } - } - impl frame_system_rpc_runtime_api::AccountNonceApi for Runtime { fn account_nonce(account: AccountId) -> Index { System::account_nonce(account) diff --git a/runtime/moonbase/src/lib.rs b/runtime/moonbase/src/lib.rs index 9774af7bca..bf1eee73a3 100644 --- a/runtime/moonbase/src/lib.rs +++ b/runtime/moonbase/src/lib.rs @@ -1582,6 +1582,33 @@ moonbeam_runtime_common::impl_runtime_apis_plus_common! { ConsensusHook::can_build_upon(included_hash, slot) } } + + impl sp_genesis_builder::GenesisBuilder for Runtime { + fn build_state(config: Vec) -> sp_genesis_builder::Result { + frame_support::genesis_builder_helper::build_state::(config) + } + + fn get_preset(id: &Option) -> Option> { + frame_support::genesis_builder_helper::get_preset::(id, |id| { + let patch = match id.try_into() { + Ok(sp_genesis_builder::DEV_RUNTIME_PRESET) => { + let config = RuntimeGenesisConfig::default(); + serde_json::to_value(config).expect("Could not build genesis config.") + }, + _ => return None, + }; + Some( + serde_json::to_string(&patch) + .expect("serialization to json is expected to work. qed.") + .into_bytes(), + ) + }) + } + + fn preset_names() -> Vec { + vec![sp_genesis_builder::PresetId::from(sp_genesis_builder::DEV_RUNTIME_PRESET)] + } + } } struct CheckInherents; diff --git a/runtime/moonbeam/src/lib.rs b/runtime/moonbeam/src/lib.rs index a4892e32d0..cd7e9e931a 100644 --- a/runtime/moonbeam/src/lib.rs +++ b/runtime/moonbeam/src/lib.rs @@ -1621,6 +1621,33 @@ moonbeam_runtime_common::impl_runtime_apis_plus_common! { ConsensusHook::can_build_upon(included_hash, slot) } } + + impl sp_genesis_builder::GenesisBuilder for Runtime { + fn build_state(config: Vec) -> sp_genesis_builder::Result { + frame_support::genesis_builder_helper::build_state::(config) + } + + fn get_preset(id: &Option) -> Option> { + frame_support::genesis_builder_helper::get_preset::(id, |id| { + let patch = match id.try_into() { + Ok(sp_genesis_builder::DEV_RUNTIME_PRESET) => { + let config = RuntimeGenesisConfig::default(); + serde_json::to_value(config).expect("Could not build genesis config.") + }, + _ => return None, + }; + Some( + serde_json::to_string(&patch) + .expect("serialization to json is expected to work. qed.") + .into_bytes(), + ) + }) + } + + fn preset_names() -> Vec { + vec![sp_genesis_builder::PresetId::from(sp_genesis_builder::DEV_RUNTIME_PRESET)] + } + } } struct CheckInherents; diff --git a/runtime/moonriver/src/lib.rs b/runtime/moonriver/src/lib.rs index 3c30809b75..b2b5f2bc9e 100644 --- a/runtime/moonriver/src/lib.rs +++ b/runtime/moonriver/src/lib.rs @@ -1622,6 +1622,33 @@ moonbeam_runtime_common::impl_runtime_apis_plus_common! { ConsensusHook::can_build_upon(included_hash, slot) } } + + impl sp_genesis_builder::GenesisBuilder for Runtime { + fn build_state(config: Vec) -> sp_genesis_builder::Result { + frame_support::genesis_builder_helper::build_state::(config) + } + + fn get_preset(id: &Option) -> Option> { + frame_support::genesis_builder_helper::get_preset::(id, |id| { + let patch = match id.try_into() { + Ok(sp_genesis_builder::DEV_RUNTIME_PRESET) => { + let config = RuntimeGenesisConfig::default(); + serde_json::to_value(config).expect("Could not build genesis config.") + }, + _ => return None, + }; + Some( + serde_json::to_string(&patch) + .expect("serialization to json is expected to work. qed.") + .into_bytes(), + ) + }) + } + + fn preset_names() -> Vec { + vec![sp_genesis_builder::PresetId::from(sp_genesis_builder::DEV_RUNTIME_PRESET)] + } + } } struct CheckInherents; From dc562fa979a4c26a0e1edb50c1e4000b3e0bf59e Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Wed, 22 Jan 2025 15:53:00 +0100 Subject: [PATCH 07/33] refactor: :recycle: move moonbase runtime test config to runtime --- runtime/moonbase/Cargo.toml | 4 +- runtime/moonbase/src/genesis_config_preset.rs | 166 ++++++++++++++++++ runtime/moonbase/src/lib.rs | 44 ++++- 3 files changed, 208 insertions(+), 6 deletions(-) create mode 100644 runtime/moonbase/src/genesis_config_preset.rs diff --git a/runtime/moonbase/Cargo.toml b/runtime/moonbase/Cargo.toml index 3763413aba..ef47809855 100644 --- a/runtime/moonbase/Cargo.toml +++ b/runtime/moonbase/Cargo.toml @@ -14,7 +14,9 @@ log = { workspace = true } num_enum = { workspace = true } rlp = { workspace = true, optional = true } serde = { workspace = true, features = ["derive"] } -serde_json = { version = "1.0.114", default-features = false } +serde_json = { version = "1.0.114", default-features = false, features = [ + "alloc", +] } sha3 = { workspace = true, optional = true } smallvec = { workspace = true } strum = { workspace = true } diff --git a/runtime/moonbase/src/genesis_config_preset.rs b/runtime/moonbase/src/genesis_config_preset.rs new file mode 100644 index 0000000000..739be1ae7c --- /dev/null +++ b/runtime/moonbase/src/genesis_config_preset.rs @@ -0,0 +1,166 @@ +extern crate alloc; + +use crate::{ + currency::UNIT, AccountId, AuthorFilterConfig, AuthorMappingConfig, Balance, BalancesConfig, + CrowdloanRewardsConfig, EVMConfig, EligibilityValue, EthereumChainIdConfig, EthereumConfig, + InflationInfo, MaintenanceModeConfig, MoonbeamOrbitersConfig, + OpenTechCommitteeCollectiveConfig, ParachainInfoConfig, ParachainStakingConfig, + PolkadotXcmConfig, Precompiles, Range, RuntimeGenesisConfig, SudoConfig, + TransactionPaymentConfig, TreasuryCouncilCollectiveConfig, XcmTransactorConfig, HOURS, +}; +use alloc::{vec, vec::Vec}; +use cumulus_primitives_core::ParaId; +pub use fp_evm::GenesisAccount; +use nimbus_primitives::NimbusId; +use pallet_transaction_payment::Multiplier; +use sp_runtime::{traits::One, Perbill, Percent}; + +const COLLATOR_COMMISSION: Perbill = Perbill::from_percent(20); +const PARACHAIN_BOND_RESERVE_PERCENT: Percent = Percent::from_percent(30); +const BLOCKS_PER_ROUND: u32 = 2 * HOURS; +const BLOCKS_PER_YEAR: u32 = 31_557_600 / 6; +const NUM_SELECTED_CANDIDATES: u32 = 8; +pub fn moonbase_inflation_config() -> InflationInfo { + fn to_round_inflation(annual: Range) -> Range { + use pallet_parachain_staking::inflation::perbill_annual_to_perbill_round; + perbill_annual_to_perbill_round( + annual, + // rounds per year + BLOCKS_PER_YEAR / BLOCKS_PER_ROUND, + ) + } + let annual = Range { + min: Perbill::from_percent(4), + ideal: Perbill::from_percent(5), + max: Perbill::from_percent(5), + }; + InflationInfo { + // staking expectations + expect: Range { + min: 100_000 * UNIT, + ideal: 200_000 * UNIT, + max: 500_000 * UNIT, + }, + // annual inflation + annual, + round: to_round_inflation(annual), + } +} + +pub fn testnet_genesis( + root_key: AccountId, + treasury_council_members: Vec, + open_tech_committee_members: Vec, + candidates: Vec<(AccountId, NimbusId, Balance)>, + delegations: Vec<(AccountId, AccountId, Balance, Percent)>, + endowed_accounts: Vec, + crowdloan_fund_pot: Balance, + para_id: ParaId, + chain_id: u64, +) -> serde_json::Value { + // This is the simplest bytecode to revert without returning any data. + // We will pre-deploy it under all of our precompiles to ensure they can be called from + // within contracts. + // (PUSH1 0x00 PUSH1 0x00 REVERT) + let revert_bytecode = vec![0x60, 0x00, 0x60, 0x00, 0xFD]; + + let config = RuntimeGenesisConfig { + system: Default::default(), + balances: BalancesConfig { + balances: endowed_accounts + .iter() + .cloned() + .map(|k| (k, 1 << 80)) + .collect(), + }, + crowdloan_rewards: CrowdloanRewardsConfig { + funded_amount: crowdloan_fund_pot, + }, + sudo: SudoConfig { + key: Some(root_key), + }, + parachain_info: ParachainInfoConfig { + parachain_id: para_id, + ..Default::default() + }, + ethereum_chain_id: EthereumChainIdConfig { + chain_id, + ..Default::default() + }, + evm: EVMConfig { + // We need _some_ code inserted at the precompile address so that + // the evm will actually call the address. + accounts: Precompiles::used_addresses() + .map(|addr| { + ( + addr.into(), + GenesisAccount { + nonce: Default::default(), + balance: Default::default(), + storage: Default::default(), + code: revert_bytecode.clone(), + }, + ) + }) + .collect(), + ..Default::default() + }, + ethereum: EthereumConfig { + ..Default::default() + }, + parachain_staking: ParachainStakingConfig { + candidates: candidates + .iter() + .cloned() + .map(|(account, _, bond)| (account, bond)) + .collect(), + delegations, + inflation_config: moonbase_inflation_config(), + collator_commission: COLLATOR_COMMISSION, + parachain_bond_reserve_percent: PARACHAIN_BOND_RESERVE_PERCENT, + blocks_per_round: BLOCKS_PER_ROUND, + num_selected_candidates: NUM_SELECTED_CANDIDATES, + }, + treasury_council_collective: TreasuryCouncilCollectiveConfig { + phantom: Default::default(), + members: treasury_council_members, + }, + open_tech_committee_collective: OpenTechCommitteeCollectiveConfig { + phantom: Default::default(), + members: open_tech_committee_members, + }, + author_filter: AuthorFilterConfig { + eligible_count: EligibilityValue::new_unchecked(50), + ..Default::default() + }, + author_mapping: AuthorMappingConfig { + mappings: candidates + .iter() + .cloned() + .map(|(account_id, author_id, _)| (author_id, account_id)) + .collect(), + }, + proxy_genesis_companion: Default::default(), + treasury: Default::default(), + migrations: Default::default(), + maintenance_mode: MaintenanceModeConfig { + start_in_maintenance_mode: false, + ..Default::default() + }, + // This should initialize it to whatever we have set in the pallet + polkadot_xcm: PolkadotXcmConfig::default(), + transaction_payment: TransactionPaymentConfig { + multiplier: Multiplier::from(8u128), + ..Default::default() + }, + moonbeam_orbiters: MoonbeamOrbitersConfig { + min_orbiter_deposit: One::one(), + }, + xcm_transactor: XcmTransactorConfig { + relay_indices: moonbeam_relay_encoder::westend::WESTEND_RELAY_INDICES, + ..Default::default() + }, + }; + + serde_json::to_value(&config).expect("Could not build genesis config.") +} diff --git a/runtime/moonbase/src/lib.rs b/runtime/moonbase/src/lib.rs index 5fa48a909b..53b52b0deb 100644 --- a/runtime/moonbase/src/lib.rs +++ b/runtime/moonbase/src/lib.rs @@ -29,6 +29,7 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); pub mod asset_config; +mod genesis_config_preset; pub mod governance; pub mod runtime_params; pub mod xcm_config; @@ -80,7 +81,7 @@ use frame_system::{EnsureRoot, EnsureSigned}; use governance::councils::*; use moonbeam_rpc_primitives_txpool::TxPoolResponse; use moonbeam_runtime_common::timestamp::{ConsensusHookWrapperForRelayTimestamp, RelayTimestamp}; -use nimbus_primitives::CanAuthor; +use nimbus_primitives::{CanAuthor, NimbusId}; use pallet_ethereum::Call::transact; use pallet_ethereum::{PostLogContent, Transaction as EthereumTransaction}; use pallet_evm::{ @@ -89,6 +90,7 @@ use pallet_evm::{ OnChargeEVMTransaction as OnChargeEVMTransactionT, Runner, }; use pallet_transaction_payment::{FungibleAdapter, Multiplier, TargetedFeeAdjustment}; +use parachains_common::genesis_config_helpers::get_from_seed; use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; use runtime_params::*; use scale_info::TypeInfo; @@ -1592,10 +1594,42 @@ moonbeam_runtime_common::impl_runtime_apis_plus_common! { fn get_preset(id: &Option) -> Option> { frame_support::genesis_builder_helper::get_preset::(id, |id| { let patch = match id.try_into() { - Ok(sp_genesis_builder::DEV_RUNTIME_PRESET) => { - let config = RuntimeGenesisConfig::default(); - serde_json::to_value(config).expect("Could not build genesis config.") - }, + Ok(sp_genesis_builder::DEV_RUNTIME_PRESET) => genesis_config_preset::testnet_genesis( + // Alith is Sudo + AccountId::from(sp_core::hex2array!("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac")), + // Treasury Council members: Baltathar, Charleth and Dorothy + vec![ + AccountId::from(sp_core::hex2array!("3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0")), + AccountId::from(sp_core::hex2array!("798d4Ba9baf0064Ec19eB4F0a1a45785ae9D6DFc")), + AccountId::from(sp_core::hex2array!("773539d4Ac0e786233D90A233654ccEE26a613D9")), + ], + // Open Tech committee members: Alith and Baltathar + vec![ + AccountId::from(sp_core::hex2array!("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac")), + AccountId::from(sp_core::hex2array!("3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0")), + ], + // Collator Candidates + vec![ + // Alice -> Alith + ( + AccountId::from(sp_core::hex2array!("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac")), + get_from_seed::("Alice"), + 1_000 * currency::UNIT, + ), + ], + // Delegations + vec![], + // Endowed: Alith, Baltathar, Charleth and Dorothy + vec![ + AccountId::from(sp_core::hex2array!("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac")), + AccountId::from(sp_core::hex2array!("3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0")), + AccountId::from(sp_core::hex2array!("798d4Ba9baf0064Ec19eB4F0a1a45785ae9D6DFc")), + AccountId::from(sp_core::hex2array!("773539d4Ac0e786233D90A233654ccEE26a613D9")), + ], + 3_000_000 * currency::UNIT, + Default::default(), // para_id + 1280, //ChainId + ), _ => return None, }; Some( From 1b7338629f737e5a73e91eec3a1bb2fcb5e17b8c Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Wed, 22 Jan 2025 16:38:12 +0100 Subject: [PATCH 08/33] refactor: :art: improve structure --- runtime/moonbase/src/genesis_config_preset.rs | 63 +++++++++++++++++++ runtime/moonbase/src/lib.rs | 40 +----------- 2 files changed, 65 insertions(+), 38 deletions(-) diff --git a/runtime/moonbase/src/genesis_config_preset.rs b/runtime/moonbase/src/genesis_config_preset.rs index 739be1ae7c..8b3568815c 100644 --- a/runtime/moonbase/src/genesis_config_preset.rs +++ b/runtime/moonbase/src/genesis_config_preset.rs @@ -13,6 +13,7 @@ use cumulus_primitives_core::ParaId; pub use fp_evm::GenesisAccount; use nimbus_primitives::NimbusId; use pallet_transaction_payment::Multiplier; +use parachains_common::genesis_config_helpers::get_from_seed; use sp_runtime::{traits::One, Perbill, Percent}; const COLLATOR_COMMISSION: Perbill = Perbill::from_percent(20); @@ -20,6 +21,7 @@ const PARACHAIN_BOND_RESERVE_PERCENT: Percent = Percent::from_percent(30); const BLOCKS_PER_ROUND: u32 = 2 * HOURS; const BLOCKS_PER_YEAR: u32 = 31_557_600 / 6; const NUM_SELECTED_CANDIDATES: u32 = 8; + pub fn moonbase_inflation_config() -> InflationInfo { fn to_round_inflation(annual: Range) -> Range { use pallet_parachain_staking::inflation::perbill_annual_to_perbill_round; @@ -164,3 +166,64 @@ pub fn testnet_genesis( serde_json::to_value(&config).expect("Could not build genesis config.") } + +pub fn development() -> serde_json::Value { + testnet_genesis( + // Alith is Sudo + AccountId::from(sp_core::hex2array!( + "f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac" + )), + // Treasury Council members: Baltathar, Charleth and Dorothy + vec![ + AccountId::from(sp_core::hex2array!( + "3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0" + )), + AccountId::from(sp_core::hex2array!( + "798d4Ba9baf0064Ec19eB4F0a1a45785ae9D6DFc" + )), + AccountId::from(sp_core::hex2array!( + "773539d4Ac0e786233D90A233654ccEE26a613D9" + )), + ], + // Open Tech committee members: Alith and Baltathar + vec![ + AccountId::from(sp_core::hex2array!( + "f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac" + )), + AccountId::from(sp_core::hex2array!( + "3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0" + )), + ], + // Collator Candidates + vec![ + // Alice -> Alith + ( + AccountId::from(sp_core::hex2array!( + "f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac" + )), + get_from_seed::("Alice"), + 1_000 * UNIT, + ), + ], + // Delegations + vec![], + // Endowed: Alith, Baltathar, Charleth and Dorothy + vec![ + AccountId::from(sp_core::hex2array!( + "f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac" + )), + AccountId::from(sp_core::hex2array!( + "3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0" + )), + AccountId::from(sp_core::hex2array!( + "798d4Ba9baf0064Ec19eB4F0a1a45785ae9D6DFc" + )), + AccountId::from(sp_core::hex2array!( + "773539d4Ac0e786233D90A233654ccEE26a613D9" + )), + ], + 3_000_000 * UNIT, + Default::default(), // para_id + 1280, //ChainId + ) +} diff --git a/runtime/moonbase/src/lib.rs b/runtime/moonbase/src/lib.rs index 53b52b0deb..7495107ad5 100644 --- a/runtime/moonbase/src/lib.rs +++ b/runtime/moonbase/src/lib.rs @@ -81,7 +81,7 @@ use frame_system::{EnsureRoot, EnsureSigned}; use governance::councils::*; use moonbeam_rpc_primitives_txpool::TxPoolResponse; use moonbeam_runtime_common::timestamp::{ConsensusHookWrapperForRelayTimestamp, RelayTimestamp}; -use nimbus_primitives::{CanAuthor, NimbusId}; +use nimbus_primitives::CanAuthor; use pallet_ethereum::Call::transact; use pallet_ethereum::{PostLogContent, Transaction as EthereumTransaction}; use pallet_evm::{ @@ -90,7 +90,6 @@ use pallet_evm::{ OnChargeEVMTransaction as OnChargeEVMTransactionT, Runner, }; use pallet_transaction_payment::{FungibleAdapter, Multiplier, TargetedFeeAdjustment}; -use parachains_common::genesis_config_helpers::get_from_seed; use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; use runtime_params::*; use scale_info::TypeInfo; @@ -1594,42 +1593,7 @@ moonbeam_runtime_common::impl_runtime_apis_plus_common! { fn get_preset(id: &Option) -> Option> { frame_support::genesis_builder_helper::get_preset::(id, |id| { let patch = match id.try_into() { - Ok(sp_genesis_builder::DEV_RUNTIME_PRESET) => genesis_config_preset::testnet_genesis( - // Alith is Sudo - AccountId::from(sp_core::hex2array!("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac")), - // Treasury Council members: Baltathar, Charleth and Dorothy - vec![ - AccountId::from(sp_core::hex2array!("3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0")), - AccountId::from(sp_core::hex2array!("798d4Ba9baf0064Ec19eB4F0a1a45785ae9D6DFc")), - AccountId::from(sp_core::hex2array!("773539d4Ac0e786233D90A233654ccEE26a613D9")), - ], - // Open Tech committee members: Alith and Baltathar - vec![ - AccountId::from(sp_core::hex2array!("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac")), - AccountId::from(sp_core::hex2array!("3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0")), - ], - // Collator Candidates - vec![ - // Alice -> Alith - ( - AccountId::from(sp_core::hex2array!("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac")), - get_from_seed::("Alice"), - 1_000 * currency::UNIT, - ), - ], - // Delegations - vec![], - // Endowed: Alith, Baltathar, Charleth and Dorothy - vec![ - AccountId::from(sp_core::hex2array!("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac")), - AccountId::from(sp_core::hex2array!("3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0")), - AccountId::from(sp_core::hex2array!("798d4Ba9baf0064Ec19eB4F0a1a45785ae9D6DFc")), - AccountId::from(sp_core::hex2array!("773539d4Ac0e786233D90A233654ccEE26a613D9")), - ], - 3_000_000 * currency::UNIT, - Default::default(), // para_id - 1280, //ChainId - ), + Ok(sp_genesis_builder::DEV_RUNTIME_PRESET) => genesis_config_preset::development(), _ => return None, }; Some( From c5170a375b1ce51d3041f91172e6ff71ec99e2f7 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Wed, 22 Jan 2025 17:10:06 +0100 Subject: [PATCH 09/33] refactor: :recycle: move moonbeam runtime test config to runtime --- runtime/moonbase/src/genesis_config_preset.rs | 2 +- runtime/moonbase/src/lib.rs | 1 + runtime/moonbeam/src/genesis_config_preset.rs | 230 ++++++++++++++++++ runtime/moonbeam/src/lib.rs | 6 +- 4 files changed, 234 insertions(+), 5 deletions(-) create mode 100644 runtime/moonbeam/src/genesis_config_preset.rs diff --git a/runtime/moonbase/src/genesis_config_preset.rs b/runtime/moonbase/src/genesis_config_preset.rs index 8b3568815c..8cb1a5fb1c 100644 --- a/runtime/moonbase/src/genesis_config_preset.rs +++ b/runtime/moonbase/src/genesis_config_preset.rs @@ -10,7 +10,7 @@ use crate::{ }; use alloc::{vec, vec::Vec}; use cumulus_primitives_core::ParaId; -pub use fp_evm::GenesisAccount; +use fp_evm::GenesisAccount; use nimbus_primitives::NimbusId; use pallet_transaction_payment::Multiplier; use parachains_common::genesis_config_helpers::get_from_seed; diff --git a/runtime/moonbase/src/lib.rs b/runtime/moonbase/src/lib.rs index 7495107ad5..b356c34231 100644 --- a/runtime/moonbase/src/lib.rs +++ b/runtime/moonbase/src/lib.rs @@ -1596,6 +1596,7 @@ moonbeam_runtime_common::impl_runtime_apis_plus_common! { Ok(sp_genesis_builder::DEV_RUNTIME_PRESET) => genesis_config_preset::development(), _ => return None, }; + Some( serde_json::to_string(&patch) .expect("serialization to json is expected to work. qed.") diff --git a/runtime/moonbeam/src/genesis_config_preset.rs b/runtime/moonbeam/src/genesis_config_preset.rs new file mode 100644 index 0000000000..fca4106699 --- /dev/null +++ b/runtime/moonbeam/src/genesis_config_preset.rs @@ -0,0 +1,230 @@ +// Copyright 2019-2022 PureStake Inc. +// This file is part of Moonbeam. + +// Moonbeam is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Moonbeam is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Moonbeam. If not, see . + +//! Moonbeam Chain Specifications and utilities for building them. +//! +//! Learn more about Substrate chain specifications at +//! https://substrate.dev/docs/en/knowledgebase/integrate/chain-spec +extern crate alloc; + +use crate::{ + currency::GLMR, currency::SUPPLY_FACTOR, AccountId, AuthorFilterConfig, AuthorMappingConfig, + Balance, BalancesConfig, CrowdloanRewardsConfig, EVMConfig, EligibilityValue, + EthereumChainIdConfig, EthereumConfig, InflationInfo, MaintenanceModeConfig, + OpenTechCommitteeCollectiveConfig, ParachainInfoConfig, ParachainStakingConfig, + PolkadotXcmConfig, Precompiles, Range, RuntimeGenesisConfig, TransactionPaymentConfig, + TreasuryCouncilCollectiveConfig, HOURS, +}; +use alloc::{vec, vec::Vec}; +use cumulus_primitives_core::ParaId; +use fp_evm::GenesisAccount; +use nimbus_primitives::NimbusId; +use pallet_transaction_payment::Multiplier; +use parachains_common::genesis_config_helpers::get_from_seed; +use sp_runtime::{Perbill, Percent}; + +const COLLATOR_COMMISSION: Perbill = Perbill::from_percent(20); +const PARACHAIN_BOND_RESERVE_PERCENT: Percent = Percent::from_percent(30); +const BLOCKS_PER_ROUND: u32 = 6 * HOURS; +const BLOCKS_PER_YEAR: u32 = 31_557_600 / 12; +const NUM_SELECTED_CANDIDATES: u32 = 8; +pub fn moonbeam_inflation_config() -> InflationInfo { + fn to_round_inflation(annual: Range) -> Range { + use pallet_parachain_staking::inflation::perbill_annual_to_perbill_round; + perbill_annual_to_perbill_round( + annual, + // rounds per year + BLOCKS_PER_YEAR / BLOCKS_PER_ROUND, + ) + } + let annual = Range { + min: Perbill::from_percent(4), + ideal: Perbill::from_percent(5), + max: Perbill::from_percent(5), + }; + InflationInfo { + // staking expectations + expect: Range { + min: 100_000 * GLMR * SUPPLY_FACTOR, + ideal: 200_000 * GLMR * SUPPLY_FACTOR, + max: 500_000 * GLMR * SUPPLY_FACTOR, + }, + // annual inflation + annual, + round: to_round_inflation(annual), + } +} + +pub fn testnet_genesis( + treasury_council_members: Vec, + open_tech_committee_members: Vec, + candidates: Vec<(AccountId, NimbusId, Balance)>, + delegations: Vec<(AccountId, AccountId, Balance, Percent)>, + endowed_accounts: Vec, + crowdloan_fund_pot: Balance, + para_id: ParaId, + chain_id: u64, +) -> serde_json::Value { + // This is the simplest bytecode to revert without returning any data. + // We will pre-deploy it under all of our precompiles to ensure they can be called from + // within contracts. + // (PUSH1 0x00 PUSH1 0x00 REVERT) + let revert_bytecode = vec![0x60, 0x00, 0x60, 0x00, 0xFD]; + + let config = RuntimeGenesisConfig { + system: Default::default(), + balances: BalancesConfig { + balances: endowed_accounts + .iter() + .cloned() + .map(|k| (k, 1 << 110)) + .collect(), + }, + crowdloan_rewards: CrowdloanRewardsConfig { + funded_amount: crowdloan_fund_pot, + }, + parachain_info: ParachainInfoConfig { + parachain_id: para_id, + ..Default::default() + }, + ethereum_chain_id: EthereumChainIdConfig { + chain_id, + ..Default::default() + }, + evm: EVMConfig { + // We need _some_ code inserted at the precompile address so that + // the evm will actually call the address. + accounts: Precompiles::used_addresses() + .map(|addr| { + ( + addr.into(), + GenesisAccount { + nonce: Default::default(), + balance: Default::default(), + storage: Default::default(), + code: revert_bytecode.clone(), + }, + ) + }) + .collect(), + ..Default::default() + }, + ethereum: EthereumConfig { + ..Default::default() + }, + parachain_staking: ParachainStakingConfig { + candidates: candidates + .iter() + .cloned() + .map(|(account, _, bond)| (account, bond)) + .collect(), + delegations, + inflation_config: moonbeam_inflation_config(), + collator_commission: COLLATOR_COMMISSION, + parachain_bond_reserve_percent: PARACHAIN_BOND_RESERVE_PERCENT, + blocks_per_round: BLOCKS_PER_ROUND, + num_selected_candidates: NUM_SELECTED_CANDIDATES, + }, + treasury_council_collective: TreasuryCouncilCollectiveConfig { + phantom: Default::default(), + members: treasury_council_members, + }, + open_tech_committee_collective: OpenTechCommitteeCollectiveConfig { + phantom: Default::default(), + members: open_tech_committee_members, + }, + author_filter: AuthorFilterConfig { + eligible_count: EligibilityValue::new_unchecked(50), + ..Default::default() + }, + author_mapping: AuthorMappingConfig { + mappings: candidates + .iter() + .cloned() + .map(|(account_id, author_id, _)| (author_id, account_id)) + .collect(), + }, + proxy_genesis_companion: Default::default(), + treasury: Default::default(), + migrations: Default::default(), + maintenance_mode: MaintenanceModeConfig { + start_in_maintenance_mode: false, + ..Default::default() + }, + // This should initialize it to whatever we have set in the pallet + polkadot_xcm: PolkadotXcmConfig::default(), + transaction_payment: TransactionPaymentConfig { + multiplier: Multiplier::from(8u128), + ..Default::default() + }, + }; + + serde_json::to_value(&config).expect("Could not build genesis config.") +} + +/// Generate a chain spec for use with the development service. +pub fn development() -> serde_json::Value { + testnet_genesis( + // Treasury Council members: Baltathar, Charleth and Dorothy + vec![ + AccountId::from(sp_core::hex2array!( + "3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0" + )), + AccountId::from(sp_core::hex2array!( + "798d4Ba9baf0064Ec19eB4F0a1a45785ae9D6DFc" + )), + AccountId::from(sp_core::hex2array!( + "773539d4Ac0e786233D90A233654ccEE26a613D9" + )), + ], + // Open Tech committee members: Alith and Baltathar + vec![ + AccountId::from(sp_core::hex2array!( + "f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac" + )), + AccountId::from(sp_core::hex2array!( + "3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0" + )), + ], + // Collator Candidate: Alice -> Alith + vec![( + AccountId::from(sp_core::hex2array!( + "f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac" + )), + get_from_seed::("Alice"), + 20_000 * GLMR * SUPPLY_FACTOR, + )], + // Delegations + vec![], + vec![ + AccountId::from(sp_core::hex2array!( + "f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac" + )), + AccountId::from(sp_core::hex2array!( + "3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0" + )), + AccountId::from(sp_core::hex2array!( + "798d4Ba9baf0064Ec19eB4F0a1a45785ae9D6DFc" + )), + AccountId::from(sp_core::hex2array!( + "773539d4Ac0e786233D90A233654ccEE26a613D9" + )), + ], + 1_500_000 * GLMR * SUPPLY_FACTOR, + Default::default(), // para_id + 1281, //ChainId + ) +} diff --git a/runtime/moonbeam/src/lib.rs b/runtime/moonbeam/src/lib.rs index 2c6cbc9954..dddff15e53 100644 --- a/runtime/moonbeam/src/lib.rs +++ b/runtime/moonbeam/src/lib.rs @@ -119,6 +119,7 @@ pub use sp_runtime::BuildStorage; pub type Precompiles = MoonbeamPrecompiles; pub mod asset_config; +pub mod genesis_config_preset; pub mod governance; pub mod runtime_params; mod weights; @@ -1632,10 +1633,7 @@ moonbeam_runtime_common::impl_runtime_apis_plus_common! { fn get_preset(id: &Option) -> Option> { frame_support::genesis_builder_helper::get_preset::(id, |id| { let patch = match id.try_into() { - Ok(sp_genesis_builder::DEV_RUNTIME_PRESET) => { - let config = RuntimeGenesisConfig::default(); - serde_json::to_value(config).expect("Could not build genesis config.") - }, + Ok(sp_genesis_builder::DEV_RUNTIME_PRESET) => genesis_config_preset::development(), _ => return None, }; Some( From ba403b4ef018b95006f3b3f215963e5683ffb35f Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Wed, 22 Jan 2025 17:21:11 +0100 Subject: [PATCH 10/33] refactor: :recycle: move moonriver runtime test config to runtime --- .../moonriver/src/genesis_config_preset.rs | 230 ++++++++++++++++++ runtime/moonriver/src/lib.rs | 6 +- 2 files changed, 232 insertions(+), 4 deletions(-) create mode 100644 runtime/moonriver/src/genesis_config_preset.rs diff --git a/runtime/moonriver/src/genesis_config_preset.rs b/runtime/moonriver/src/genesis_config_preset.rs new file mode 100644 index 0000000000..1e6d3f07a8 --- /dev/null +++ b/runtime/moonriver/src/genesis_config_preset.rs @@ -0,0 +1,230 @@ +// Copyright 2019-2022 PureStake Inc. +// This file is part of Moonbeam. + +// Moonbeam is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Moonbeam is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Moonbeam. If not, see . + +//! Moonriver Chain Specifications and utilities for building them. +//! +//! Learn more about Substrate chain specifications at +//! https://substrate.dev/docs/en/knowledgebase/integrate/chain-spec +extern crate alloc; + +use crate::{ + currency::MOVR, AccountId, AuthorFilterConfig, AuthorMappingConfig, Balance, BalancesConfig, + CrowdloanRewardsConfig, EVMConfig, EligibilityValue, EthereumChainIdConfig, EthereumConfig, + InflationInfo, MaintenanceModeConfig, OpenTechCommitteeCollectiveConfig, ParachainInfoConfig, + ParachainStakingConfig, PolkadotXcmConfig, Precompiles, Range, RuntimeGenesisConfig, + TransactionPaymentConfig, TreasuryCouncilCollectiveConfig, HOURS, +}; +use alloc::{vec, vec::Vec}; +use cumulus_primitives_core::ParaId; +use fp_evm::GenesisAccount; +use nimbus_primitives::NimbusId; +use pallet_transaction_payment::Multiplier; +use parachains_common::genesis_config_helpers::get_from_seed; +use sp_runtime::{Perbill, Percent}; + +const COLLATOR_COMMISSION: Perbill = Perbill::from_percent(20); +const PARACHAIN_BOND_RESERVE_PERCENT: Percent = Percent::from_percent(30); +const BLOCKS_PER_ROUND: u32 = 2 * HOURS; +const BLOCKS_PER_YEAR: u32 = 31_557_600 / 12; +const NUM_SELECTED_CANDIDATES: u32 = 8; + +pub fn moonriver_inflation_config() -> InflationInfo { + fn to_round_inflation(annual: Range) -> Range { + use pallet_parachain_staking::inflation::perbill_annual_to_perbill_round; + perbill_annual_to_perbill_round( + annual, + // rounds per year + BLOCKS_PER_YEAR / BLOCKS_PER_ROUND, + ) + } + let annual = Range { + min: Perbill::from_percent(4), + ideal: Perbill::from_percent(5), + max: Perbill::from_percent(5), + }; + InflationInfo { + // staking expectations + expect: Range { + min: 100_000 * MOVR, + ideal: 200_000 * MOVR, + max: 500_000 * MOVR, + }, + // annual inflation + annual, + round: to_round_inflation(annual), + } +} + +pub fn testnet_genesis( + treasury_council_members: Vec, + open_tech_committee_members: Vec, + candidates: Vec<(AccountId, NimbusId, Balance)>, + delegations: Vec<(AccountId, AccountId, Balance, Percent)>, + endowed_accounts: Vec, + crowdloan_fund_pot: Balance, + para_id: ParaId, + chain_id: u64, +) -> serde_json::Value { + // This is the simplest bytecode to revert without returning any data. + // We will pre-deploy it under all of our precompiles to ensure they can be called from + // within contracts. + // (PUSH1 0x00 PUSH1 0x00 REVERT) + let revert_bytecode = vec![0x60, 0x00, 0x60, 0x00, 0xFD]; + + let config = RuntimeGenesisConfig { + system: Default::default(), + balances: BalancesConfig { + balances: endowed_accounts + .iter() + .cloned() + .map(|k| (k, 1 << 80)) + .collect(), + }, + crowdloan_rewards: CrowdloanRewardsConfig { + funded_amount: crowdloan_fund_pot, + }, + parachain_info: ParachainInfoConfig { + parachain_id: para_id, + ..Default::default() + }, + ethereum_chain_id: EthereumChainIdConfig { + chain_id, + ..Default::default() + }, + evm: EVMConfig { + // We need _some_ code inserted at the precompile address so that + // the evm will actually call the address. + accounts: Precompiles::used_addresses() + .map(|addr| { + ( + addr.into(), + GenesisAccount { + nonce: Default::default(), + balance: Default::default(), + storage: Default::default(), + code: revert_bytecode.clone(), + }, + ) + }) + .collect(), + ..Default::default() + }, + ethereum: EthereumConfig { + ..Default::default() + }, + parachain_staking: ParachainStakingConfig { + candidates: candidates + .iter() + .cloned() + .map(|(account, _, bond)| (account, bond)) + .collect(), + delegations, + inflation_config: moonriver_inflation_config(), + collator_commission: COLLATOR_COMMISSION, + parachain_bond_reserve_percent: PARACHAIN_BOND_RESERVE_PERCENT, + blocks_per_round: BLOCKS_PER_ROUND, + num_selected_candidates: NUM_SELECTED_CANDIDATES, + }, + treasury_council_collective: TreasuryCouncilCollectiveConfig { + phantom: Default::default(), + members: treasury_council_members, + }, + open_tech_committee_collective: OpenTechCommitteeCollectiveConfig { + phantom: Default::default(), + members: open_tech_committee_members, + }, + author_filter: AuthorFilterConfig { + eligible_count: EligibilityValue::new_unchecked(50), + ..Default::default() + }, + author_mapping: AuthorMappingConfig { + mappings: candidates + .iter() + .cloned() + .map(|(account_id, author_id, _)| (author_id, account_id)) + .collect(), + }, + proxy_genesis_companion: Default::default(), + treasury: Default::default(), + migrations: Default::default(), + maintenance_mode: MaintenanceModeConfig { + start_in_maintenance_mode: false, + ..Default::default() + }, + // This should initialize it to whatever we have set in the pallet + polkadot_xcm: PolkadotXcmConfig::default(), + transaction_payment: TransactionPaymentConfig { + multiplier: Multiplier::from(10u128), + ..Default::default() + }, + }; + + serde_json::to_value(&config).expect("Could not build genesis config.") +} + +/// Generate a chain spec for use with the development service. +pub fn development() -> serde_json::Value { + testnet_genesis( + // Treasury Council members: Baltathar, Charleth and Dorothy + vec![ + AccountId::from(sp_core::hex2array!( + "3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0" + )), + AccountId::from(sp_core::hex2array!( + "798d4Ba9baf0064Ec19eB4F0a1a45785ae9D6DFc" + )), + AccountId::from(sp_core::hex2array!( + "773539d4Ac0e786233D90A233654ccEE26a613D9" + )), + ], + // Open Tech committee members: Alith and Baltathar + vec![ + AccountId::from(sp_core::hex2array!( + "f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac" + )), + AccountId::from(sp_core::hex2array!( + "3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0" + )), + ], + // Collator Candidate: Alice -> Alith + vec![( + AccountId::from(sp_core::hex2array!( + "f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac" + )), + get_from_seed::("Alice"), + 100_000 * MOVR, + )], + // Delegations + vec![], + vec![ + AccountId::from(sp_core::hex2array!( + "f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac" + )), + AccountId::from(sp_core::hex2array!( + "3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0" + )), + AccountId::from(sp_core::hex2array!( + "798d4Ba9baf0064Ec19eB4F0a1a45785ae9D6DFc" + )), + AccountId::from(sp_core::hex2array!( + "773539d4Ac0e786233D90A233654ccEE26a613D9" + )), + ], + 3_000_000 * MOVR, + Default::default(), // para_id + 1281, //ChainId + ) +} diff --git a/runtime/moonriver/src/lib.rs b/runtime/moonriver/src/lib.rs index 509ad165d3..df5a3f6cbd 100644 --- a/runtime/moonriver/src/lib.rs +++ b/runtime/moonriver/src/lib.rs @@ -121,6 +121,7 @@ pub use sp_runtime::BuildStorage; pub type Precompiles = MoonriverPrecompiles; pub mod asset_config; +pub mod genesis_config_preset; pub mod governance; pub mod runtime_params; pub mod xcm_config; @@ -1633,10 +1634,7 @@ moonbeam_runtime_common::impl_runtime_apis_plus_common! { fn get_preset(id: &Option) -> Option> { frame_support::genesis_builder_helper::get_preset::(id, |id| { let patch = match id.try_into() { - Ok(sp_genesis_builder::DEV_RUNTIME_PRESET) => { - let config = RuntimeGenesisConfig::default(); - serde_json::to_value(config).expect("Could not build genesis config.") - }, + Ok(sp_genesis_builder::DEV_RUNTIME_PRESET) => genesis_config_preset::development(), _ => return None, }; Some( From 0236acf3a4b16c3c6b3a03d0027f22bb580701f5 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Wed, 22 Jan 2025 17:34:14 +0100 Subject: [PATCH 11/33] fix: :fire: remove unused dep --- Cargo.lock | 1 - runtime/common/Cargo.toml | 1 - 2 files changed, 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a13536f44a..952f4b6cf5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6915,7 +6915,6 @@ dependencies = [ "parity-scale-codec", "precompile-utils", "scale-info", - "serde_json", "sp-api", "sp-consensus-slots", "sp-core", diff --git a/runtime/common/Cargo.toml b/runtime/common/Cargo.toml index 19f46062b1..d3c3027be3 100644 --- a/runtime/common/Cargo.toml +++ b/runtime/common/Cargo.toml @@ -11,7 +11,6 @@ version = "0.8.0-dev" hex-literal = "0.3.4" impl-trait-for-tuples = "0.2.1" log = "0.4" -serde_json = { version = "1.0.114", default-features = false } # Moonbeam moonbeam-core-primitives = { workspace = true } From 57cea862f68923d3198507230a53f028faa0454e Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Thu, 23 Jan 2025 10:14:27 +0100 Subject: [PATCH 12/33] chore: :page_facing_up: add copyright --- runtime/moonbase/src/genesis_config_preset.rs | 16 ++++++++++++++++ runtime/moonbeam/src/genesis_config_preset.rs | 5 +---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/runtime/moonbase/src/genesis_config_preset.rs b/runtime/moonbase/src/genesis_config_preset.rs index 8cb1a5fb1c..9889953227 100644 --- a/runtime/moonbase/src/genesis_config_preset.rs +++ b/runtime/moonbase/src/genesis_config_preset.rs @@ -1,3 +1,19 @@ +// Copyright 2019-2022 PureStake Inc. +// This file is part of Moonbeam. + +// Moonbeam is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Moonbeam is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Moonbeam. If not, see . + extern crate alloc; use crate::{ diff --git a/runtime/moonbeam/src/genesis_config_preset.rs b/runtime/moonbeam/src/genesis_config_preset.rs index fca4106699..06f1c3867c 100644 --- a/runtime/moonbeam/src/genesis_config_preset.rs +++ b/runtime/moonbeam/src/genesis_config_preset.rs @@ -14,10 +14,6 @@ // You should have received a copy of the GNU General Public License // along with Moonbeam. If not, see . -//! Moonbeam Chain Specifications and utilities for building them. -//! -//! Learn more about Substrate chain specifications at -//! https://substrate.dev/docs/en/knowledgebase/integrate/chain-spec extern crate alloc; use crate::{ @@ -41,6 +37,7 @@ const PARACHAIN_BOND_RESERVE_PERCENT: Percent = Percent::from_percent(30); const BLOCKS_PER_ROUND: u32 = 6 * HOURS; const BLOCKS_PER_YEAR: u32 = 31_557_600 / 12; const NUM_SELECTED_CANDIDATES: u32 = 8; + pub fn moonbeam_inflation_config() -> InflationInfo { fn to_round_inflation(annual: Range) -> Range { use pallet_parachain_staking::inflation::perbill_annual_to_perbill_round; From a12ff6e40e69b47b5e88ae5f75c3c3c39b3cd587 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Thu, 23 Jan 2025 10:18:18 +0100 Subject: [PATCH 13/33] refactor: :fire: complete move of testnet_genesis functions to runtime --- node/service/src/chain_spec/moonbase.rs | 133 +---------------------- node/service/src/chain_spec/moonbeam.rs | 122 +-------------------- node/service/src/chain_spec/moonriver.rs | 122 +-------------------- node/service/src/chain_spec/test_spec.rs | 6 +- node/service/src/lib.rs | 4 +- runtime/moonbase/src/lib.rs | 2 +- 6 files changed, 16 insertions(+), 373 deletions(-) diff --git a/node/service/src/chain_spec/moonbase.rs b/node/service/src/chain_spec/moonbase.rs index 3d2d34af2a..07fad80ae6 100644 --- a/node/service/src/chain_spec/moonbase.rs +++ b/node/service/src/chain_spec/moonbase.rs @@ -25,20 +25,14 @@ use crate::chain_spec::{generate_accounts, get_from_seed, Extensions}; use cumulus_primitives_core::ParaId; use hex_literal::hex; use moonbase_runtime::{ - currency::UNIT, AccountId, AuthorFilterConfig, AuthorMappingConfig, Balance, BalancesConfig, - CrowdloanRewardsConfig, EVMConfig, EligibilityValue, EthereumChainIdConfig, EthereumConfig, - GenesisAccount, InflationInfo, MaintenanceModeConfig, MoonbeamOrbitersConfig, - OpenTechCommitteeCollectiveConfig, ParachainInfoConfig, ParachainStakingConfig, - PolkadotXcmConfig, Precompiles, Range, RuntimeGenesisConfig, SudoConfig, - TransactionPaymentConfig, TreasuryCouncilCollectiveConfig, XcmTransactorConfig, HOURS, - WASM_BINARY, + currency::UNIT, genesis_config_preset::testnet_genesis, AccountId, Balance, InflationInfo, + Range, HOURS, WASM_BINARY, }; use nimbus_primitives::NimbusId; -use pallet_transaction_payment::Multiplier; use sc_service::ChainType; #[cfg(test)] use sp_core::ecdsa; -use sp_runtime::{traits::One, Perbill, Percent}; +use sp_runtime::Perbill; /// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type. pub type ChainSpec = sc_service::GenericChainSpec; @@ -167,11 +161,8 @@ pub fn get_chain_spec(para_id: ParaId) -> ChainSpec { .build() } -const COLLATOR_COMMISSION: Perbill = Perbill::from_percent(20); -const PARACHAIN_BOND_RESERVE_PERCENT: Percent = Percent::from_percent(30); const BLOCKS_PER_ROUND: u32 = 2 * HOURS; const BLOCKS_PER_YEAR: u32 = 31_557_600 / 6; -const NUM_SELECTED_CANDIDATES: u32 = 8; pub fn moonbase_inflation_config() -> InflationInfo { fn to_round_inflation(annual: Range) -> Range { use pallet_parachain_staking::inflation::perbill_annual_to_perbill_round; @@ -199,124 +190,6 @@ pub fn moonbase_inflation_config() -> InflationInfo { } } -pub fn testnet_genesis( - root_key: AccountId, - treasury_council_members: Vec, - open_tech_committee_members: Vec, - candidates: Vec<(AccountId, NimbusId, Balance)>, - delegations: Vec<(AccountId, AccountId, Balance, Percent)>, - endowed_accounts: Vec, - crowdloan_fund_pot: Balance, - para_id: ParaId, - chain_id: u64, -) -> serde_json::Value { - // This is the simplest bytecode to revert without returning any data. - // We will pre-deploy it under all of our precompiles to ensure they can be called from - // within contracts. - // (PUSH1 0x00 PUSH1 0x00 REVERT) - let revert_bytecode = vec![0x60, 0x00, 0x60, 0x00, 0xFD]; - - let config = RuntimeGenesisConfig { - system: Default::default(), - balances: BalancesConfig { - balances: endowed_accounts - .iter() - .cloned() - .map(|k| (k, 1 << 80)) - .collect(), - }, - crowdloan_rewards: CrowdloanRewardsConfig { - funded_amount: crowdloan_fund_pot, - }, - sudo: SudoConfig { - key: Some(root_key), - }, - parachain_info: ParachainInfoConfig { - parachain_id: para_id, - ..Default::default() - }, - ethereum_chain_id: EthereumChainIdConfig { - chain_id, - ..Default::default() - }, - evm: EVMConfig { - // We need _some_ code inserted at the precompile address so that - // the evm will actually call the address. - accounts: Precompiles::used_addresses() - .map(|addr| { - ( - addr.into(), - GenesisAccount { - nonce: Default::default(), - balance: Default::default(), - storage: Default::default(), - code: revert_bytecode.clone(), - }, - ) - }) - .collect(), - ..Default::default() - }, - ethereum: EthereumConfig { - ..Default::default() - }, - parachain_staking: ParachainStakingConfig { - candidates: candidates - .iter() - .cloned() - .map(|(account, _, bond)| (account, bond)) - .collect(), - delegations, - inflation_config: moonbase_inflation_config(), - collator_commission: COLLATOR_COMMISSION, - parachain_bond_reserve_percent: PARACHAIN_BOND_RESERVE_PERCENT, - blocks_per_round: BLOCKS_PER_ROUND, - num_selected_candidates: NUM_SELECTED_CANDIDATES, - }, - treasury_council_collective: TreasuryCouncilCollectiveConfig { - phantom: Default::default(), - members: treasury_council_members, - }, - open_tech_committee_collective: OpenTechCommitteeCollectiveConfig { - phantom: Default::default(), - members: open_tech_committee_members, - }, - author_filter: AuthorFilterConfig { - eligible_count: EligibilityValue::new_unchecked(50), - ..Default::default() - }, - author_mapping: AuthorMappingConfig { - mappings: candidates - .iter() - .cloned() - .map(|(account_id, author_id, _)| (author_id, account_id)) - .collect(), - }, - proxy_genesis_companion: Default::default(), - treasury: Default::default(), - migrations: Default::default(), - maintenance_mode: MaintenanceModeConfig { - start_in_maintenance_mode: false, - ..Default::default() - }, - // This should initialize it to whatever we have set in the pallet - polkadot_xcm: PolkadotXcmConfig::default(), - transaction_payment: TransactionPaymentConfig { - multiplier: Multiplier::from(8u128), - ..Default::default() - }, - moonbeam_orbiters: MoonbeamOrbitersConfig { - min_orbiter_deposit: One::one(), - }, - xcm_transactor: XcmTransactorConfig { - relay_indices: moonbeam_relay_encoder::westend::WESTEND_RELAY_INDICES, - ..Default::default() - }, - }; - - serde_json::to_value(&config).expect("Could not build genesis config.") -} - #[cfg(test)] mod tests { use super::*; diff --git a/node/service/src/chain_spec/moonbeam.rs b/node/service/src/chain_spec/moonbeam.rs index 59205dc619..59948bbc28 100644 --- a/node/service/src/chain_spec/moonbeam.rs +++ b/node/service/src/chain_spec/moonbeam.rs @@ -25,19 +25,15 @@ use crate::chain_spec::{generate_accounts, get_from_seed, Extensions}; use cumulus_primitives_core::ParaId; use hex_literal::hex; use moonbeam_runtime::{ - currency::GLMR, currency::SUPPLY_FACTOR, AccountId, AuthorFilterConfig, AuthorMappingConfig, - Balance, BalancesConfig, CrowdloanRewardsConfig, EVMConfig, EligibilityValue, - EthereumChainIdConfig, EthereumConfig, GenesisAccount, InflationInfo, MaintenanceModeConfig, - OpenTechCommitteeCollectiveConfig, ParachainInfoConfig, ParachainStakingConfig, - PolkadotXcmConfig, Precompiles, Range, RuntimeGenesisConfig, TransactionPaymentConfig, - TreasuryCouncilCollectiveConfig, HOURS, WASM_BINARY, + currency::{GLMR, SUPPLY_FACTOR}, + genesis_config_preset::testnet_genesis, + AccountId, Balance, InflationInfo, Range, HOURS, WASM_BINARY, }; use nimbus_primitives::NimbusId; -use pallet_transaction_payment::Multiplier; use sc_service::ChainType; #[cfg(test)] use sp_core::ecdsa; -use sp_runtime::{Perbill, Percent}; +use sp_runtime::Perbill; /// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type. pub type ChainSpec = sc_service::GenericChainSpec; @@ -156,11 +152,8 @@ pub fn get_chain_spec(para_id: ParaId) -> ChainSpec { .build() } -const COLLATOR_COMMISSION: Perbill = Perbill::from_percent(20); -const PARACHAIN_BOND_RESERVE_PERCENT: Percent = Percent::from_percent(30); const BLOCKS_PER_ROUND: u32 = 6 * HOURS; const BLOCKS_PER_YEAR: u32 = 31_557_600 / 12; -const NUM_SELECTED_CANDIDATES: u32 = 8; pub fn moonbeam_inflation_config() -> InflationInfo { fn to_round_inflation(annual: Range) -> Range { use pallet_parachain_staking::inflation::perbill_annual_to_perbill_round; @@ -188,113 +181,6 @@ pub fn moonbeam_inflation_config() -> InflationInfo { } } -pub fn testnet_genesis( - treasury_council_members: Vec, - open_tech_committee_members: Vec, - candidates: Vec<(AccountId, NimbusId, Balance)>, - delegations: Vec<(AccountId, AccountId, Balance, Percent)>, - endowed_accounts: Vec, - crowdloan_fund_pot: Balance, - para_id: ParaId, - chain_id: u64, -) -> serde_json::Value { - // This is the simplest bytecode to revert without returning any data. - // We will pre-deploy it under all of our precompiles to ensure they can be called from - // within contracts. - // (PUSH1 0x00 PUSH1 0x00 REVERT) - let revert_bytecode = vec![0x60, 0x00, 0x60, 0x00, 0xFD]; - - let config = RuntimeGenesisConfig { - system: Default::default(), - balances: BalancesConfig { - balances: endowed_accounts - .iter() - .cloned() - .map(|k| (k, 1 << 110)) - .collect(), - }, - crowdloan_rewards: CrowdloanRewardsConfig { - funded_amount: crowdloan_fund_pot, - }, - parachain_info: ParachainInfoConfig { - parachain_id: para_id, - ..Default::default() - }, - ethereum_chain_id: EthereumChainIdConfig { - chain_id, - ..Default::default() - }, - evm: EVMConfig { - // We need _some_ code inserted at the precompile address so that - // the evm will actually call the address. - accounts: Precompiles::used_addresses() - .map(|addr| { - ( - addr.into(), - GenesisAccount { - nonce: Default::default(), - balance: Default::default(), - storage: Default::default(), - code: revert_bytecode.clone(), - }, - ) - }) - .collect(), - ..Default::default() - }, - ethereum: EthereumConfig { - ..Default::default() - }, - parachain_staking: ParachainStakingConfig { - candidates: candidates - .iter() - .cloned() - .map(|(account, _, bond)| (account, bond)) - .collect(), - delegations, - inflation_config: moonbeam_inflation_config(), - collator_commission: COLLATOR_COMMISSION, - parachain_bond_reserve_percent: PARACHAIN_BOND_RESERVE_PERCENT, - blocks_per_round: BLOCKS_PER_ROUND, - num_selected_candidates: NUM_SELECTED_CANDIDATES, - }, - treasury_council_collective: TreasuryCouncilCollectiveConfig { - phantom: Default::default(), - members: treasury_council_members, - }, - open_tech_committee_collective: OpenTechCommitteeCollectiveConfig { - phantom: Default::default(), - members: open_tech_committee_members, - }, - author_filter: AuthorFilterConfig { - eligible_count: EligibilityValue::new_unchecked(50), - ..Default::default() - }, - author_mapping: AuthorMappingConfig { - mappings: candidates - .iter() - .cloned() - .map(|(account_id, author_id, _)| (author_id, account_id)) - .collect(), - }, - proxy_genesis_companion: Default::default(), - treasury: Default::default(), - migrations: Default::default(), - maintenance_mode: MaintenanceModeConfig { - start_in_maintenance_mode: false, - ..Default::default() - }, - // This should initialize it to whatever we have set in the pallet - polkadot_xcm: PolkadotXcmConfig::default(), - transaction_payment: TransactionPaymentConfig { - multiplier: Multiplier::from(8u128), - ..Default::default() - }, - }; - - serde_json::to_value(&config).expect("Could not build genesis config.") -} - #[cfg(test)] mod tests { use super::*; diff --git a/node/service/src/chain_spec/moonriver.rs b/node/service/src/chain_spec/moonriver.rs index da02a35d4b..8bcf12dcda 100644 --- a/node/service/src/chain_spec/moonriver.rs +++ b/node/service/src/chain_spec/moonriver.rs @@ -25,19 +25,14 @@ use crate::chain_spec::{generate_accounts, get_from_seed, Extensions}; use cumulus_primitives_core::ParaId; use hex_literal::hex; use moonriver_runtime::{ - currency::MOVR, AccountId, AuthorFilterConfig, AuthorMappingConfig, Balance, BalancesConfig, - CrowdloanRewardsConfig, EVMConfig, EligibilityValue, EthereumChainIdConfig, EthereumConfig, - GenesisAccount, InflationInfo, MaintenanceModeConfig, OpenTechCommitteeCollectiveConfig, - ParachainInfoConfig, ParachainStakingConfig, PolkadotXcmConfig, Precompiles, Range, - RuntimeGenesisConfig, TransactionPaymentConfig, TreasuryCouncilCollectiveConfig, HOURS, - WASM_BINARY, + currency::MOVR, genesis_config_preset::testnet_genesis, AccountId, Balance, InflationInfo, + Range, HOURS, WASM_BINARY, }; use nimbus_primitives::NimbusId; -use pallet_transaction_payment::Multiplier; use sc_service::ChainType; #[cfg(test)] use sp_core::ecdsa; -use sp_runtime::{Perbill, Percent}; +use sp_runtime::Perbill; /// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type. pub type ChainSpec = sc_service::GenericChainSpec; @@ -156,11 +151,8 @@ pub fn get_chain_spec(para_id: ParaId) -> ChainSpec { .build() } -const COLLATOR_COMMISSION: Perbill = Perbill::from_percent(20); -const PARACHAIN_BOND_RESERVE_PERCENT: Percent = Percent::from_percent(30); const BLOCKS_PER_ROUND: u32 = 2 * HOURS; const BLOCKS_PER_YEAR: u32 = 31_557_600 / 12; -const NUM_SELECTED_CANDIDATES: u32 = 8; pub fn moonriver_inflation_config() -> InflationInfo { fn to_round_inflation(annual: Range) -> Range { use pallet_parachain_staking::inflation::perbill_annual_to_perbill_round; @@ -187,114 +179,6 @@ pub fn moonriver_inflation_config() -> InflationInfo { round: to_round_inflation(annual), } } - -pub fn testnet_genesis( - treasury_council_members: Vec, - open_tech_committee_members: Vec, - candidates: Vec<(AccountId, NimbusId, Balance)>, - delegations: Vec<(AccountId, AccountId, Balance, Percent)>, - endowed_accounts: Vec, - crowdloan_fund_pot: Balance, - para_id: ParaId, - chain_id: u64, -) -> serde_json::Value { - // This is the simplest bytecode to revert without returning any data. - // We will pre-deploy it under all of our precompiles to ensure they can be called from - // within contracts. - // (PUSH1 0x00 PUSH1 0x00 REVERT) - let revert_bytecode = vec![0x60, 0x00, 0x60, 0x00, 0xFD]; - - let config = RuntimeGenesisConfig { - system: Default::default(), - balances: BalancesConfig { - balances: endowed_accounts - .iter() - .cloned() - .map(|k| (k, 1 << 80)) - .collect(), - }, - crowdloan_rewards: CrowdloanRewardsConfig { - funded_amount: crowdloan_fund_pot, - }, - parachain_info: ParachainInfoConfig { - parachain_id: para_id, - ..Default::default() - }, - ethereum_chain_id: EthereumChainIdConfig { - chain_id, - ..Default::default() - }, - evm: EVMConfig { - // We need _some_ code inserted at the precompile address so that - // the evm will actually call the address. - accounts: Precompiles::used_addresses() - .map(|addr| { - ( - addr.into(), - GenesisAccount { - nonce: Default::default(), - balance: Default::default(), - storage: Default::default(), - code: revert_bytecode.clone(), - }, - ) - }) - .collect(), - ..Default::default() - }, - ethereum: EthereumConfig { - ..Default::default() - }, - parachain_staking: ParachainStakingConfig { - candidates: candidates - .iter() - .cloned() - .map(|(account, _, bond)| (account, bond)) - .collect(), - delegations, - inflation_config: moonriver_inflation_config(), - collator_commission: COLLATOR_COMMISSION, - parachain_bond_reserve_percent: PARACHAIN_BOND_RESERVE_PERCENT, - blocks_per_round: BLOCKS_PER_ROUND, - num_selected_candidates: NUM_SELECTED_CANDIDATES, - }, - treasury_council_collective: TreasuryCouncilCollectiveConfig { - phantom: Default::default(), - members: treasury_council_members, - }, - open_tech_committee_collective: OpenTechCommitteeCollectiveConfig { - phantom: Default::default(), - members: open_tech_committee_members, - }, - author_filter: AuthorFilterConfig { - eligible_count: EligibilityValue::new_unchecked(50), - ..Default::default() - }, - author_mapping: AuthorMappingConfig { - mappings: candidates - .iter() - .cloned() - .map(|(account_id, author_id, _)| (author_id, account_id)) - .collect(), - }, - proxy_genesis_companion: Default::default(), - treasury: Default::default(), - migrations: Default::default(), - maintenance_mode: MaintenanceModeConfig { - start_in_maintenance_mode: false, - ..Default::default() - }, - // This should initialize it to whatever we have set in the pallet - polkadot_xcm: PolkadotXcmConfig::default(), - transaction_payment: TransactionPaymentConfig { - multiplier: Multiplier::from(10u128), - ..Default::default() - }, - }; - - serde_json::to_value(&config).expect("Could not build genesis config.") -} - #[cfg(test)] mod tests { use super::*; diff --git a/node/service/src/chain_spec/test_spec.rs b/node/service/src/chain_spec/test_spec.rs index 0654030802..2bba38cefd 100644 --- a/node/service/src/chain_spec/test_spec.rs +++ b/node/service/src/chain_spec/test_spec.rs @@ -15,7 +15,7 @@ // along with Moonbeam. If not, see . //! Embedded specs for testing purposes, must be compiled with --features=test-spec -use crate::chain_spec::moonbase::{testnet_genesis, ChainSpec}; +use crate::chain_spec::moonbase::ChainSpec; use crate::chain_spec::{get_from_seed, Extensions}; use cumulus_primitives_core::ParaId; use hex_literal::hex; @@ -39,7 +39,7 @@ pub fn staking_spec(para_id: ParaId) -> ChainSpec { .with_properties( serde_json::from_str("{\"tokenDecimals\": 18}").expect("Provided valid json map"), ) - .with_genesis_config(testnet_genesis( + .with_genesis_config(moonbase_runtime::genesis_config_preset::testnet_genesis( // Root AccountId::from(hex!("6Be02d1d3665660d22FF9624b7BE0551ee1Ac91b")), // Treasury Council members: Baltathar, Charleth and Dorothy @@ -104,7 +104,7 @@ pub fn lazy_loading_spec_builder(para_id: ParaId) -> sc_chain_spec::ChainSpecBui ) .expect("Provided valid json map"), ) - .with_genesis_config(crate::chain_spec::moonbeam::testnet_genesis( + .with_genesis_config(moonbeam_runtime::genesis_config_preset::testnet_genesis( // Treasury Council members: Baltathar, Charleth and Dorothy vec![ AccountId::from(hex!("3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0")), diff --git a/node/service/src/lib.rs b/node/service/src/lib.rs index 31bdc4a083..165438f4eb 100644 --- a/node/service/src/lib.rs +++ b/node/service/src/lib.rs @@ -1627,7 +1627,7 @@ where #[cfg(test)] mod tests { - use crate::chain_spec::moonbase::{testnet_genesis, ChainSpec}; + use crate::chain_spec::moonbase::ChainSpec; use crate::chain_spec::Extensions; use jsonrpsee::server::BatchRequestConfig; use moonbase_runtime::{currency::UNIT, AccountId}; @@ -1814,7 +1814,7 @@ mod tests { .with_name("test") .with_id(chain_id) .with_chain_type(ChainType::Local) - .with_genesis_config(testnet_genesis( + .with_genesis_config(moonbase_runtime::genesis_config_preset::testnet_genesis( AccountId::from_str("6Be02d1d3665660d22FF9624b7BE0551ee1Ac91b").unwrap(), vec![], vec![], diff --git a/runtime/moonbase/src/lib.rs b/runtime/moonbase/src/lib.rs index b356c34231..15cdaba240 100644 --- a/runtime/moonbase/src/lib.rs +++ b/runtime/moonbase/src/lib.rs @@ -29,7 +29,7 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); pub mod asset_config; -mod genesis_config_preset; +pub mod genesis_config_preset; pub mod governance; pub mod runtime_params; pub mod xcm_config; From 3e42e86db65dc64d80f0f32beef4078d2ba7bbd4 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Thu, 23 Jan 2025 10:23:18 +0100 Subject: [PATCH 14/33] refactor: :coffin: remove dead functions *_inflation_config --- node/service/src/chain_spec/moonbase.rs | 33 +----------------------- node/service/src/chain_spec/moonbeam.rs | 32 +---------------------- node/service/src/chain_spec/moonriver.rs | 32 +---------------------- 3 files changed, 3 insertions(+), 94 deletions(-) diff --git a/node/service/src/chain_spec/moonbase.rs b/node/service/src/chain_spec/moonbase.rs index 07fad80ae6..02d2e11a48 100644 --- a/node/service/src/chain_spec/moonbase.rs +++ b/node/service/src/chain_spec/moonbase.rs @@ -25,14 +25,12 @@ use crate::chain_spec::{generate_accounts, get_from_seed, Extensions}; use cumulus_primitives_core::ParaId; use hex_literal::hex; use moonbase_runtime::{ - currency::UNIT, genesis_config_preset::testnet_genesis, AccountId, Balance, InflationInfo, - Range, HOURS, WASM_BINARY, + currency::UNIT, genesis_config_preset::testnet_genesis, AccountId, WASM_BINARY, }; use nimbus_primitives::NimbusId; use sc_service::ChainType; #[cfg(test)] use sp_core::ecdsa; -use sp_runtime::Perbill; /// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type. pub type ChainSpec = sc_service::GenericChainSpec; @@ -161,35 +159,6 @@ pub fn get_chain_spec(para_id: ParaId) -> ChainSpec { .build() } -const BLOCKS_PER_ROUND: u32 = 2 * HOURS; -const BLOCKS_PER_YEAR: u32 = 31_557_600 / 6; -pub fn moonbase_inflation_config() -> InflationInfo { - fn to_round_inflation(annual: Range) -> Range { - use pallet_parachain_staking::inflation::perbill_annual_to_perbill_round; - perbill_annual_to_perbill_round( - annual, - // rounds per year - BLOCKS_PER_YEAR / BLOCKS_PER_ROUND, - ) - } - let annual = Range { - min: Perbill::from_percent(4), - ideal: Perbill::from_percent(5), - max: Perbill::from_percent(5), - }; - InflationInfo { - // staking expectations - expect: Range { - min: 100_000 * UNIT, - ideal: 200_000 * UNIT, - max: 500_000 * UNIT, - }, - // annual inflation - annual, - round: to_round_inflation(annual), - } -} - #[cfg(test)] mod tests { use super::*; diff --git a/node/service/src/chain_spec/moonbeam.rs b/node/service/src/chain_spec/moonbeam.rs index 59948bbc28..0a458a9fd3 100644 --- a/node/service/src/chain_spec/moonbeam.rs +++ b/node/service/src/chain_spec/moonbeam.rs @@ -27,13 +27,12 @@ use hex_literal::hex; use moonbeam_runtime::{ currency::{GLMR, SUPPLY_FACTOR}, genesis_config_preset::testnet_genesis, - AccountId, Balance, InflationInfo, Range, HOURS, WASM_BINARY, + AccountId, WASM_BINARY, }; use nimbus_primitives::NimbusId; use sc_service::ChainType; #[cfg(test)] use sp_core::ecdsa; -use sp_runtime::Perbill; /// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type. pub type ChainSpec = sc_service::GenericChainSpec; @@ -152,35 +151,6 @@ pub fn get_chain_spec(para_id: ParaId) -> ChainSpec { .build() } -const BLOCKS_PER_ROUND: u32 = 6 * HOURS; -const BLOCKS_PER_YEAR: u32 = 31_557_600 / 12; -pub fn moonbeam_inflation_config() -> InflationInfo { - fn to_round_inflation(annual: Range) -> Range { - use pallet_parachain_staking::inflation::perbill_annual_to_perbill_round; - perbill_annual_to_perbill_round( - annual, - // rounds per year - BLOCKS_PER_YEAR / BLOCKS_PER_ROUND, - ) - } - let annual = Range { - min: Perbill::from_percent(4), - ideal: Perbill::from_percent(5), - max: Perbill::from_percent(5), - }; - InflationInfo { - // staking expectations - expect: Range { - min: 100_000 * GLMR * SUPPLY_FACTOR, - ideal: 200_000 * GLMR * SUPPLY_FACTOR, - max: 500_000 * GLMR * SUPPLY_FACTOR, - }, - // annual inflation - annual, - round: to_round_inflation(annual), - } -} - #[cfg(test)] mod tests { use super::*; diff --git a/node/service/src/chain_spec/moonriver.rs b/node/service/src/chain_spec/moonriver.rs index 8bcf12dcda..364d80e86a 100644 --- a/node/service/src/chain_spec/moonriver.rs +++ b/node/service/src/chain_spec/moonriver.rs @@ -25,14 +25,12 @@ use crate::chain_spec::{generate_accounts, get_from_seed, Extensions}; use cumulus_primitives_core::ParaId; use hex_literal::hex; use moonriver_runtime::{ - currency::MOVR, genesis_config_preset::testnet_genesis, AccountId, Balance, InflationInfo, - Range, HOURS, WASM_BINARY, + currency::MOVR, genesis_config_preset::testnet_genesis, AccountId, WASM_BINARY, }; use nimbus_primitives::NimbusId; use sc_service::ChainType; #[cfg(test)] use sp_core::ecdsa; -use sp_runtime::Perbill; /// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type. pub type ChainSpec = sc_service::GenericChainSpec; @@ -151,34 +149,6 @@ pub fn get_chain_spec(para_id: ParaId) -> ChainSpec { .build() } -const BLOCKS_PER_ROUND: u32 = 2 * HOURS; -const BLOCKS_PER_YEAR: u32 = 31_557_600 / 12; -pub fn moonriver_inflation_config() -> InflationInfo { - fn to_round_inflation(annual: Range) -> Range { - use pallet_parachain_staking::inflation::perbill_annual_to_perbill_round; - perbill_annual_to_perbill_round( - annual, - // rounds per year - BLOCKS_PER_YEAR / BLOCKS_PER_ROUND, - ) - } - let annual = Range { - min: Perbill::from_percent(4), - ideal: Perbill::from_percent(5), - max: Perbill::from_percent(5), - }; - InflationInfo { - // staking expectations - expect: Range { - min: 100_000 * MOVR, - ideal: 200_000 * MOVR, - max: 500_000 * MOVR, - }, - // annual inflation - annual, - round: to_round_inflation(annual), - } -} #[cfg(test)] mod tests { use super::*; From 3d0900c84924576b2bcd2606240f14c275238a21 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Thu, 23 Jan 2025 11:05:16 +0100 Subject: [PATCH 15/33] refactor: :recycle: add get_preset and preset_names functions --- runtime/moonbase/src/genesis_config_preset.rs | 19 +++++++++++++++++++ runtime/moonbase/src/lib.rs | 15 ++------------- runtime/moonbeam/src/genesis_config_preset.rs | 19 +++++++++++++++++++ runtime/moonbeam/src/lib.rs | 14 ++------------ .../moonriver/src/genesis_config_preset.rs | 19 +++++++++++++++++++ runtime/moonriver/src/lib.rs | 14 ++------------ 6 files changed, 63 insertions(+), 37 deletions(-) diff --git a/runtime/moonbase/src/genesis_config_preset.rs b/runtime/moonbase/src/genesis_config_preset.rs index 9889953227..7fef14d472 100644 --- a/runtime/moonbase/src/genesis_config_preset.rs +++ b/runtime/moonbase/src/genesis_config_preset.rs @@ -30,6 +30,7 @@ use fp_evm::GenesisAccount; use nimbus_primitives::NimbusId; use pallet_transaction_payment::Multiplier; use parachains_common::genesis_config_helpers::get_from_seed; +use sp_genesis_builder::PresetId; use sp_runtime::{traits::One, Perbill, Percent}; const COLLATOR_COMMISSION: Perbill = Perbill::from_percent(20); @@ -243,3 +244,21 @@ pub fn development() -> serde_json::Value { 1280, //ChainId ) } + +/// Provides the JSON representation of predefined genesis config for given `id`. +pub fn get_preset(id: &PresetId) -> Option> { + let patch = match id.try_into() { + Ok(sp_genesis_builder::DEV_RUNTIME_PRESET) => development(), + _ => return None, + }; + Some( + serde_json::to_string(&patch) + .expect("serialization to json is expected to work. qed.") + .into_bytes(), + ) +} + +/// List of supported presets. +pub fn preset_names() -> Vec { + vec![PresetId::from(sp_genesis_builder::DEV_RUNTIME_PRESET)] +} diff --git a/runtime/moonbase/src/lib.rs b/runtime/moonbase/src/lib.rs index 15cdaba240..da7cbbfa6a 100644 --- a/runtime/moonbase/src/lib.rs +++ b/runtime/moonbase/src/lib.rs @@ -1591,22 +1591,11 @@ moonbeam_runtime_common::impl_runtime_apis_plus_common! { } fn get_preset(id: &Option) -> Option> { - frame_support::genesis_builder_helper::get_preset::(id, |id| { - let patch = match id.try_into() { - Ok(sp_genesis_builder::DEV_RUNTIME_PRESET) => genesis_config_preset::development(), - _ => return None, - }; - - Some( - serde_json::to_string(&patch) - .expect("serialization to json is expected to work. qed.") - .into_bytes(), - ) - }) + frame_support::genesis_builder_helper::get_preset::(id, crate::genesis_config_preset::get_preset) } fn preset_names() -> Vec { - vec![sp_genesis_builder::PresetId::from(sp_genesis_builder::DEV_RUNTIME_PRESET)] + crate::genesis_config_preset::preset_names() } } } diff --git a/runtime/moonbeam/src/genesis_config_preset.rs b/runtime/moonbeam/src/genesis_config_preset.rs index 06f1c3867c..a478f9a932 100644 --- a/runtime/moonbeam/src/genesis_config_preset.rs +++ b/runtime/moonbeam/src/genesis_config_preset.rs @@ -30,6 +30,7 @@ use fp_evm::GenesisAccount; use nimbus_primitives::NimbusId; use pallet_transaction_payment::Multiplier; use parachains_common::genesis_config_helpers::get_from_seed; +use sp_genesis_builder::PresetId; use sp_runtime::{Perbill, Percent}; const COLLATOR_COMMISSION: Perbill = Perbill::from_percent(20); @@ -225,3 +226,21 @@ pub fn development() -> serde_json::Value { 1281, //ChainId ) } + +/// Provides the JSON representation of predefined genesis config for given `id`. +pub fn get_preset(id: &PresetId) -> Option> { + let patch = match id.try_into() { + Ok(sp_genesis_builder::DEV_RUNTIME_PRESET) => development(), + _ => return None, + }; + Some( + serde_json::to_string(&patch) + .expect("serialization to json is expected to work. qed.") + .into_bytes(), + ) +} + +/// List of supported presets. +pub fn preset_names() -> Vec { + vec![PresetId::from(sp_genesis_builder::DEV_RUNTIME_PRESET)] +} diff --git a/runtime/moonbeam/src/lib.rs b/runtime/moonbeam/src/lib.rs index dddff15e53..20d6a9f713 100644 --- a/runtime/moonbeam/src/lib.rs +++ b/runtime/moonbeam/src/lib.rs @@ -1631,21 +1631,11 @@ moonbeam_runtime_common::impl_runtime_apis_plus_common! { } fn get_preset(id: &Option) -> Option> { - frame_support::genesis_builder_helper::get_preset::(id, |id| { - let patch = match id.try_into() { - Ok(sp_genesis_builder::DEV_RUNTIME_PRESET) => genesis_config_preset::development(), - _ => return None, - }; - Some( - serde_json::to_string(&patch) - .expect("serialization to json is expected to work. qed.") - .into_bytes(), - ) - }) + frame_support::genesis_builder_helper::get_preset::(id, crate::genesis_config_preset::get_preset) } fn preset_names() -> Vec { - vec![sp_genesis_builder::PresetId::from(sp_genesis_builder::DEV_RUNTIME_PRESET)] + crate::genesis_config_preset::preset_names() } } } diff --git a/runtime/moonriver/src/genesis_config_preset.rs b/runtime/moonriver/src/genesis_config_preset.rs index 1e6d3f07a8..59ba3f10e8 100644 --- a/runtime/moonriver/src/genesis_config_preset.rs +++ b/runtime/moonriver/src/genesis_config_preset.rs @@ -33,6 +33,7 @@ use fp_evm::GenesisAccount; use nimbus_primitives::NimbusId; use pallet_transaction_payment::Multiplier; use parachains_common::genesis_config_helpers::get_from_seed; +use sp_genesis_builder::PresetId; use sp_runtime::{Perbill, Percent}; const COLLATOR_COMMISSION: Perbill = Perbill::from_percent(20); @@ -228,3 +229,21 @@ pub fn development() -> serde_json::Value { 1281, //ChainId ) } + +/// Provides the JSON representation of predefined genesis config for given `id`. +pub fn get_preset(id: &PresetId) -> Option> { + let patch = match id.try_into() { + Ok(sp_genesis_builder::DEV_RUNTIME_PRESET) => development(), + _ => return None, + }; + Some( + serde_json::to_string(&patch) + .expect("serialization to json is expected to work. qed.") + .into_bytes(), + ) +} + +/// List of supported presets. +pub fn preset_names() -> Vec { + vec![PresetId::from(sp_genesis_builder::DEV_RUNTIME_PRESET)] +} diff --git a/runtime/moonriver/src/lib.rs b/runtime/moonriver/src/lib.rs index df5a3f6cbd..091d7d1b67 100644 --- a/runtime/moonriver/src/lib.rs +++ b/runtime/moonriver/src/lib.rs @@ -1632,21 +1632,11 @@ moonbeam_runtime_common::impl_runtime_apis_plus_common! { } fn get_preset(id: &Option) -> Option> { - frame_support::genesis_builder_helper::get_preset::(id, |id| { - let patch = match id.try_into() { - Ok(sp_genesis_builder::DEV_RUNTIME_PRESET) => genesis_config_preset::development(), - _ => return None, - }; - Some( - serde_json::to_string(&patch) - .expect("serialization to json is expected to work. qed.") - .into_bytes(), - ) - }) + frame_support::genesis_builder_helper::get_preset::(id, crate::genesis_config_preset::get_preset) } fn preset_names() -> Vec { - vec![sp_genesis_builder::PresetId::from(sp_genesis_builder::DEV_RUNTIME_PRESET)] + crate::genesis_config_preset::preset_names() } } } From b23c7e034093444c7b68790247cd76cc9f4620fa Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Thu, 23 Jan 2025 11:20:37 +0100 Subject: [PATCH 16/33] build: :sparkles: --- runtime/moonbase/Cargo.toml | 1 + runtime/moonbeam/Cargo.toml | 1 + runtime/moonriver/Cargo.toml | 1 + 3 files changed, 3 insertions(+) diff --git a/runtime/moonbase/Cargo.toml b/runtime/moonbase/Cargo.toml index ef47809855..82f8f90546 100644 --- a/runtime/moonbase/Cargo.toml +++ b/runtime/moonbase/Cargo.toml @@ -303,6 +303,7 @@ std = [ "parity-scale-codec/std", "precompile-utils/std", "scale-info/std", + "serde_json/std", "session-keys-primitives/std", "sp-api/std", "sp-block-builder/std", diff --git a/runtime/moonbeam/Cargo.toml b/runtime/moonbeam/Cargo.toml index 249c4f3310..f73baa811a 100644 --- a/runtime/moonbeam/Cargo.toml +++ b/runtime/moonbeam/Cargo.toml @@ -295,6 +295,7 @@ std = [ "parity-scale-codec/std", "precompile-utils/std", "scale-info/std", + "serde_json/std", "session-keys-primitives/std", "sp-api/std", "sp-block-builder/std", diff --git a/runtime/moonriver/Cargo.toml b/runtime/moonriver/Cargo.toml index 10faba487d..cf7484efd0 100644 --- a/runtime/moonriver/Cargo.toml +++ b/runtime/moonriver/Cargo.toml @@ -295,6 +295,7 @@ std = [ "parity-scale-codec/std", "precompile-utils/std", "scale-info/std", + "serde_json/std", "session-keys-primitives/std", "sp-api/std", "sp-block-builder/std", From e61473f1780b1a8d53fb179662c5c3f611a6aa6a Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Thu, 23 Jan 2025 13:17:20 +0100 Subject: [PATCH 17/33] refactor: :recycle: correctly use with_genesis_config_preset_name in client code --- Cargo.lock | 1 + node/service/Cargo.toml | 1 + node/service/src/chain_spec/moonbase.rs | 43 +----------------------- node/service/src/chain_spec/moonbeam.rs | 41 +--------------------- node/service/src/chain_spec/moonriver.rs | 41 +--------------------- 5 files changed, 5 insertions(+), 122 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 952f4b6cf5..6a8ca31c0b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7046,6 +7046,7 @@ dependencies = [ "sp-consensus", "sp-core", "sp-externalities", + "sp-genesis-builder", "sp-inherents", "sp-io", "sp-keystore", diff --git a/node/service/Cargo.toml b/node/service/Cargo.toml index a749ab2307..068340ac79 100644 --- a/node/service/Cargo.toml +++ b/node/service/Cargo.toml @@ -93,6 +93,7 @@ sp-block-builder = { workspace = true, features = ["std"] } sp-blockchain = { workspace = true } sp-consensus = { workspace = true } sp-core = { workspace = true, features = ["std"] } +sp-genesis-builder = { workspace = true, features = ["std"] } sp-inherents = { workspace = true, features = ["std"] } sp-io = { workspace = true, features = ["std"] } sp-keystore = { workspace = true, features = ["std"] } diff --git a/node/service/src/chain_spec/moonbase.rs b/node/service/src/chain_spec/moonbase.rs index 02d2e11a48..b2a90873f2 100644 --- a/node/service/src/chain_spec/moonbase.rs +++ b/node/service/src/chain_spec/moonbase.rs @@ -114,48 +114,7 @@ pub fn get_chain_spec(para_id: ParaId) -> ChainSpec { ) .expect("Provided valid json map"), ) - .with_genesis_config(testnet_genesis( - // Alith is Sudo - AccountId::from(hex!("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac")), - // Treasury Council members: Baltathar, Charleth and Dorothy - vec![ - AccountId::from(hex!("3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0")), - AccountId::from(hex!("798d4Ba9baf0064Ec19eB4F0a1a45785ae9D6DFc")), - AccountId::from(hex!("773539d4Ac0e786233D90A233654ccEE26a613D9")), - ], - // Open Tech committee members: Alith and Baltathar - vec![ - AccountId::from(hex!("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac")), - AccountId::from(hex!("3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0")), - ], - // Collator Candidates - vec![ - // Alice -> Alith - ( - AccountId::from(hex!("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac")), - get_from_seed::("Alice"), - 1_000 * UNIT, - ), - // Bob -> Baltathar - ( - AccountId::from(hex!("3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0")), - get_from_seed::("Bob"), - 1_000 * UNIT, - ), - ], - // Delegations - vec![], - // Endowed: Alith, Baltathar, Charleth and Dorothy - vec![ - AccountId::from(hex!("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac")), - AccountId::from(hex!("3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0")), - AccountId::from(hex!("798d4Ba9baf0064Ec19eB4F0a1a45785ae9D6DFc")), - AccountId::from(hex!("773539d4Ac0e786233D90A233654ccEE26a613D9")), - ], - 3_000_000 * UNIT, - para_id, - 1280, //ChainId - )) + .with_genesis_config_preset_name(sp_genesis_builder::DEV_RUNTIME_PRESET) .build() } diff --git a/node/service/src/chain_spec/moonbeam.rs b/node/service/src/chain_spec/moonbeam.rs index 0a458a9fd3..7a2ee3dc67 100644 --- a/node/service/src/chain_spec/moonbeam.rs +++ b/node/service/src/chain_spec/moonbeam.rs @@ -108,46 +108,7 @@ pub fn get_chain_spec(para_id: ParaId) -> ChainSpec { ) .expect("Provided valid json map"), ) - .with_genesis_config(testnet_genesis( - // Treasury Council members: Baltathar, Charleth and Dorothy - vec![ - AccountId::from(hex!("3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0")), - AccountId::from(hex!("798d4Ba9baf0064Ec19eB4F0a1a45785ae9D6DFc")), - AccountId::from(hex!("773539d4Ac0e786233D90A233654ccEE26a613D9")), - ], - // Open Tech committee members: Alith and Baltathar - vec![ - AccountId::from(hex!("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac")), - AccountId::from(hex!("3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0")), - ], - // Collator Candidates - vec![ - // Alice -> Alith - ( - AccountId::from(hex!("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac")), - get_from_seed::("Alice"), - 20_000 * GLMR * SUPPLY_FACTOR, - ), - // Bob -> Baltathar - ( - AccountId::from(hex!("3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0")), - get_from_seed::("Bob"), - 20_000 * GLMR * SUPPLY_FACTOR, - ), - ], - // Delegations - vec![], - // Endowed: Alith, Baltathar, Charleth and Dorothy - vec![ - AccountId::from(hex!("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac")), - AccountId::from(hex!("3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0")), - AccountId::from(hex!("798d4Ba9baf0064Ec19eB4F0a1a45785ae9D6DFc")), - AccountId::from(hex!("773539d4Ac0e786233D90A233654ccEE26a613D9")), - ], - 1_500_000 * GLMR * SUPPLY_FACTOR, - para_id, - 1280, //ChainId - )) + .with_genesis_config_preset_name(sp_genesis_builder::DEV_RUNTIME_PRESET) .build() } diff --git a/node/service/src/chain_spec/moonriver.rs b/node/service/src/chain_spec/moonriver.rs index 364d80e86a..e35b3b0c00 100644 --- a/node/service/src/chain_spec/moonriver.rs +++ b/node/service/src/chain_spec/moonriver.rs @@ -106,46 +106,7 @@ pub fn get_chain_spec(para_id: ParaId) -> ChainSpec { ) .expect("Provided valid json map"), ) - .with_genesis_config(testnet_genesis( - // Treasury Council members: Baltathar, Charleth and Dorothy - vec![ - AccountId::from(hex!("3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0")), - AccountId::from(hex!("798d4Ba9baf0064Ec19eB4F0a1a45785ae9D6DFc")), - AccountId::from(hex!("773539d4Ac0e786233D90A233654ccEE26a613D9")), - ], - // Open Tech committee members: Alith and Baltathar - vec![ - AccountId::from(hex!("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac")), - AccountId::from(hex!("3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0")), - ], - // Collator Candidates - vec![ - // Alice -> Alith - ( - AccountId::from(hex!("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac")), - get_from_seed::("Alice"), - 100_000 * MOVR, - ), - // Bob -> Baltathar - ( - AccountId::from(hex!("3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0")), - get_from_seed::("Bob"), - 100_000 * MOVR, - ), - ], - // Delegations - vec![], - // Endowed: Alith, Baltathar, Charleth and Dorothy - vec![ - AccountId::from(hex!("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac")), - AccountId::from(hex!("3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0")), - AccountId::from(hex!("798d4Ba9baf0064Ec19eB4F0a1a45785ae9D6DFc")), - AccountId::from(hex!("773539d4Ac0e786233D90A233654ccEE26a613D9")), - ], - 3_000_000 * MOVR, - para_id, - 1280, //ChainId - )) + .with_genesis_config_preset_name(sp_genesis_builder::DEV_RUNTIME_PRESET) .build() } From 6ef78e33b5f89ecdb53d07da071a3f7de6f1091a Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Thu, 23 Jan 2025 13:28:21 +0100 Subject: [PATCH 18/33] refactor: :recycle: use with_genesis_config_preset_name in test_spec --- node/cli/src/command.rs | 3 +- node/service/src/chain_spec/test_spec.rs | 102 ++--------------------- node/service/src/lazy_loading/backend.rs | 2 +- 3 files changed, 7 insertions(+), 100 deletions(-) diff --git a/node/cli/src/command.rs b/node/cli/src/command.rs index d3a5f4141b..1961516a7d 100644 --- a/node/cli/src/command.rs +++ b/node/cli/src/command.rs @@ -866,8 +866,7 @@ pub fn run() -> Result<()> { max_retries_per_request: cli.run.lazy_loading_max_retries_per_request, }; - let spec_builder = - chain_spec::test_spec::lazy_loading_spec_builder(Default::default()); + let spec_builder = chain_spec::test_spec::lazy_loading_spec_builder(); config.chain_spec = Box::new(spec_builder.build()); // TODO: create a tokio runtime inside offchain_worker thread (otherwise it will panic) diff --git a/node/service/src/chain_spec/test_spec.rs b/node/service/src/chain_spec/test_spec.rs index 2bba38cefd..1a1ebf305f 100644 --- a/node/service/src/chain_spec/test_spec.rs +++ b/node/service/src/chain_spec/test_spec.rs @@ -16,18 +16,15 @@ //! Embedded specs for testing purposes, must be compiled with --features=test-spec use crate::chain_spec::moonbase::ChainSpec; -use crate::chain_spec::{get_from_seed, Extensions}; +use crate::chain_spec::Extensions; use cumulus_primitives_core::ParaId; -use hex_literal::hex; -use moonbase_runtime::{currency::UNIT, AccountId, WASM_BINARY}; -use nimbus_primitives::NimbusId; use sc_service::ChainType; /// Generate testing chain_spec for staking integration tests with accounts initialized for /// collating and nominating. pub fn staking_spec(para_id: ParaId) -> ChainSpec { ChainSpec::builder( - WASM_BINARY.expect("WASM binary was not build, please build it!"), + moonbase_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), Extensions { relay_chain: "westend_local".into(), para_id: para_id.into(), @@ -39,58 +36,12 @@ pub fn staking_spec(para_id: ParaId) -> ChainSpec { .with_properties( serde_json::from_str("{\"tokenDecimals\": 18}").expect("Provided valid json map"), ) - .with_genesis_config(moonbase_runtime::genesis_config_preset::testnet_genesis( - // Root - AccountId::from(hex!("6Be02d1d3665660d22FF9624b7BE0551ee1Ac91b")), - // Treasury Council members: Baltathar, Charleth and Dorothy - vec![ - AccountId::from(hex!("3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0")), - AccountId::from(hex!("798d4Ba9baf0064Ec19eB4F0a1a45785ae9D6DFc")), - AccountId::from(hex!("773539d4Ac0e786233D90A233654ccEE26a613D9")), - ], - // Open Tech Committee members: Alith and Baltathar - vec![ - AccountId::from(hex!("6Be02d1d3665660d22FF9624b7BE0551ee1Ac91b")), - AccountId::from(hex!("3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0")), - ], - // Collators - vec![ - ( - AccountId::from(hex!("6Be02d1d3665660d22FF9624b7BE0551ee1Ac91b")), - get_from_seed::("Alice"), - 1_000 * UNIT, - ), - ( - AccountId::from(hex!("C0F0f4ab324C46e55D02D0033343B4Be8A55532d")), - get_from_seed::("Faith"), - 1_000 * UNIT, - ), - ], - // Delegations - vec![], - // Endowed accounts (each minted 1 << 80 balance) - vec![ - // Alith, Baltathar, Charleth, Dorothy and Faith - AccountId::from(hex!("6Be02d1d3665660d22FF9624b7BE0551ee1Ac91b")), - AccountId::from(hex!("3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0")), - AccountId::from(hex!("798d4Ba9baf0064Ec19eB4F0a1a45785ae9D6DFc")), - AccountId::from(hex!("773539d4Ac0e786233D90A233654ccEE26a613D9")), - AccountId::from(hex!("C0F0f4ab324C46e55D02D0033343B4Be8A55532d")), - // Additional accounts - AccountId::from(hex!("Ff64d3F6efE2317EE2807d223a0Bdc4c0c49dfDB")), - AccountId::from(hex!("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac")), - ], - 3_000_000 * UNIT, - para_id, - // Chain ID - 1280, - )) + .with_genesis_config_preset_name(sp_genesis_builder::DEV_RUNTIME_PRESET) .build() } #[cfg(feature = "lazy-loading")] -pub fn lazy_loading_spec_builder(para_id: ParaId) -> sc_chain_spec::ChainSpecBuilder { - use moonbeam_runtime::currency::{GLMR, SUPPLY_FACTOR}; +pub fn lazy_loading_spec_builder() -> sc_chain_spec::ChainSpecBuilder { crate::chain_spec::moonbeam::ChainSpec::builder( moonbeam_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), Default::default(), @@ -104,48 +55,5 @@ pub fn lazy_loading_spec_builder(para_id: ParaId) -> sc_chain_spec::ChainSpecBui ) .expect("Provided valid json map"), ) - .with_genesis_config(moonbeam_runtime::genesis_config_preset::testnet_genesis( - // Treasury Council members: Baltathar, Charleth and Dorothy - vec![ - AccountId::from(hex!("3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0")), - AccountId::from(hex!("798d4Ba9baf0064Ec19eB4F0a1a45785ae9D6DFc")), - AccountId::from(hex!("773539d4Ac0e786233D90A233654ccEE26a613D9")), - ], - // Open Tech Committee members: Alith and Baltathar - vec![ - AccountId::from(hex!("6Be02d1d3665660d22FF9624b7BE0551ee1Ac91b")), - AccountId::from(hex!("3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0")), - ], - // Collators - vec![ - ( - AccountId::from(hex!("6Be02d1d3665660d22FF9624b7BE0551ee1Ac91b")), - get_from_seed::("Alice"), - 20_000 * GLMR * SUPPLY_FACTOR, - ), - ( - AccountId::from(hex!("C0F0f4ab324C46e55D02D0033343B4Be8A55532d")), - get_from_seed::("Faith"), - 20_000 * GLMR * SUPPLY_FACTOR, - ), - ], - // Delegations - vec![], - // Endowed accounts (each minted 1 << 80 balance) - vec![ - // Alith, Baltathar, Charleth, Dorothy and Faith - AccountId::from(hex!("6Be02d1d3665660d22FF9624b7BE0551ee1Ac91b")), - AccountId::from(hex!("3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0")), - AccountId::from(hex!("798d4Ba9baf0064Ec19eB4F0a1a45785ae9D6DFc")), - AccountId::from(hex!("773539d4Ac0e786233D90A233654ccEE26a613D9")), - AccountId::from(hex!("C0F0f4ab324C46e55D02D0033343B4Be8A55532d")), - // Additional accounts - AccountId::from(hex!("Ff64d3F6efE2317EE2807d223a0Bdc4c0c49dfDB")), - AccountId::from(hex!("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac")), - ], - 1_500_000 * GLMR * SUPPLY_FACTOR, - para_id, - // Chain ID - 1280, - )) + .with_genesis_config_preset_name(sp_genesis_builder::DEV_RUNTIME_PRESET) } diff --git a/node/service/src/lazy_loading/backend.rs b/node/service/src/lazy_loading/backend.rs index 623498aec6..06c21755c7 100644 --- a/node/service/src/lazy_loading/backend.rs +++ b/node/service/src/lazy_loading/backend.rs @@ -1737,7 +1737,7 @@ where .system_properties() .expect("Should fetch chain properties"); - let spec_builder = chain_spec::test_spec::lazy_loading_spec_builder(Default::default()) + let spec_builder = chain_spec::test_spec::lazy_loading_spec_builder() .with_name(chain_name.as_str()) .with_properties(chain_properties); config.chain_spec = Box::new(spec_builder.build()); From 570c6af3c576046ea1706d41c47f649028575780 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Thu, 23 Jan 2025 16:58:07 +0100 Subject: [PATCH 19/33] refactor: :fire: remove serde_json feature --- runtime/moonbase/Cargo.toml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/runtime/moonbase/Cargo.toml b/runtime/moonbase/Cargo.toml index 82f8f90546..a7997be140 100644 --- a/runtime/moonbase/Cargo.toml +++ b/runtime/moonbase/Cargo.toml @@ -14,9 +14,7 @@ log = { workspace = true } num_enum = { workspace = true } rlp = { workspace = true, optional = true } serde = { workspace = true, features = ["derive"] } -serde_json = { version = "1.0.114", default-features = false, features = [ - "alloc", -] } +serde_json = { version = "1.0.114", default-features = false } sha3 = { workspace = true, optional = true } smallvec = { workspace = true } strum = { workspace = true } From 34c3c153a47ab64341d804f219d54e411eac9293 Mon Sep 17 00:00:00 2001 From: Rodrigo Quelhas Date: Thu, 23 Jan 2025 22:33:23 +0000 Subject: [PATCH 20/33] fix json serialization of GenesisConfig in xcm-transactor --- pallets/xcm-transactor/src/lib.rs | 1 + runtime/moonbase/Cargo.toml | 2 +- runtime/moonbeam/Cargo.toml | 2 +- runtime/moonriver/Cargo.toml | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pallets/xcm-transactor/src/lib.rs b/pallets/xcm-transactor/src/lib.rs index 48e219a43e..ddedd43908 100644 --- a/pallets/xcm-transactor/src/lib.rs +++ b/pallets/xcm-transactor/src/lib.rs @@ -420,6 +420,7 @@ pub mod pallet { #[pallet::genesis_config] pub struct GenesisConfig { pub relay_indices: RelayChainIndices, + #[serde(skip)] pub _phantom: PhantomData, } diff --git a/runtime/moonbase/Cargo.toml b/runtime/moonbase/Cargo.toml index a7997be140..c8cdc3e971 100644 --- a/runtime/moonbase/Cargo.toml +++ b/runtime/moonbase/Cargo.toml @@ -14,7 +14,7 @@ log = { workspace = true } num_enum = { workspace = true } rlp = { workspace = true, optional = true } serde = { workspace = true, features = ["derive"] } -serde_json = { version = "1.0.114", default-features = false } +serde_json = { workspace = true, default-features = false, features = ["alloc"] } sha3 = { workspace = true, optional = true } smallvec = { workspace = true } strum = { workspace = true } diff --git a/runtime/moonbeam/Cargo.toml b/runtime/moonbeam/Cargo.toml index f73baa811a..10789a3b00 100644 --- a/runtime/moonbeam/Cargo.toml +++ b/runtime/moonbeam/Cargo.toml @@ -14,7 +14,7 @@ log = { workspace = true } num_enum = { workspace = true } rlp = { workspace = true, optional = true } serde = { workspace = true, features = ["derive"] } -serde_json = { version = "1.0.114", default-features = false } +serde_json = { workspace = true, default-features = false, features = ["alloc"] } sha3 = { workspace = true, optional = true } smallvec = { workspace = true } strum = { workspace = true } diff --git a/runtime/moonriver/Cargo.toml b/runtime/moonriver/Cargo.toml index cf7484efd0..4eff5e62a8 100644 --- a/runtime/moonriver/Cargo.toml +++ b/runtime/moonriver/Cargo.toml @@ -14,7 +14,7 @@ log = { workspace = true } num_enum = { workspace = true } rlp = { workspace = true, optional = true } serde = { workspace = true, features = ["derive"] } -serde_json = { version = "1.0.114", default-features = false } +serde_json = { workspace = true, default-features = false, features = ["alloc"] } sha3 = { workspace = true, optional = true } smallvec = { workspace = true } strum = { workspace = true } From f310990a0ecc6414319e2a19857300aa0d09f2c5 Mon Sep 17 00:00:00 2001 From: Rodrigo Quelhas Date: Thu, 23 Jan 2025 22:53:34 +0000 Subject: [PATCH 21/33] fix serde_json dependendency in no_std environemnt --- Cargo.toml | 2 +- client/evm-tracing/Cargo.toml | 2 +- client/rpc-core/debug/Cargo.toml | 2 +- client/rpc-core/trace/Cargo.toml | 2 +- client/rpc-core/txpool/Cargo.toml | 2 +- client/rpc-core/types/Cargo.toml | 2 +- node/Cargo.toml | 2 +- node/service/Cargo.toml | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0f99718cf7..68bb576870 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -397,7 +397,7 @@ parking_lot = "0.12.1" primitive-types = "0.12.1" prometheus = { version = "0.13.0", default-features = false } rand = "0.8.5" -serde_json = { version = "1.0.114" } +serde_json = { version = "1.0.114", default-features = false } similar-asserts = "1.1.0" tempfile = "3.8.1" tiny-bip39 = { version = "0.8", default-features = false } diff --git a/client/evm-tracing/Cargo.toml b/client/evm-tracing/Cargo.toml index 6aef0ead5b..a6e3b7ca5e 100644 --- a/client/evm-tracing/Cargo.toml +++ b/client/evm-tracing/Cargo.toml @@ -11,7 +11,7 @@ version = "0.1.0" ethereum-types = { workspace = true, features = [ "std" ] } hex = { workspace = true, features = [ "serde" ] } serde = { workspace = true, features = [ "derive", "std" ] } -serde_json = { workspace = true } +serde_json = { workspace = true, default-features = true } # Moonbeam evm-tracing-events = { workspace = true, features = [ "std" ] } diff --git a/client/rpc-core/debug/Cargo.toml b/client/rpc-core/debug/Cargo.toml index 99836a0232..a4eb9f15a5 100644 --- a/client/rpc-core/debug/Cargo.toml +++ b/client/rpc-core/debug/Cargo.toml @@ -15,7 +15,7 @@ jsonrpsee = { workspace = true, features = [ "macros", "server" ] } moonbeam-client-evm-tracing = { workspace = true } moonbeam-rpc-core-types = { workspace = true } serde = { workspace = true, features = [ "derive" ] } -serde_json = { workspace = true } +serde_json = { workspace = true, default-features = true } sp-core = { workspace = true, features = [ "std" ] } fc-rpc-core = { workspace = true } diff --git a/client/rpc-core/trace/Cargo.toml b/client/rpc-core/trace/Cargo.toml index 048e15b5cb..4c6c942138 100644 --- a/client/rpc-core/trace/Cargo.toml +++ b/client/rpc-core/trace/Cargo.toml @@ -14,4 +14,4 @@ jsonrpsee = { workspace = true, features = [ "macros", "server" ] } moonbeam-client-evm-tracing = { workspace = true } moonbeam-rpc-core-types = { workspace = true } serde = { workspace = true, features = [ "derive" ] } -serde_json = { workspace = true } +serde_json = { workspace = true, default-features = true } diff --git a/client/rpc-core/txpool/Cargo.toml b/client/rpc-core/txpool/Cargo.toml index 9467c94070..0dc4ae56d4 100644 --- a/client/rpc-core/txpool/Cargo.toml +++ b/client/rpc-core/txpool/Cargo.toml @@ -12,6 +12,6 @@ ethereum = { workspace = true, features = [ "std", "with-codec" ] } ethereum-types = { workspace = true, features = [ "std" ] } jsonrpsee = { workspace = true, features = [ "macros", "server" ] } serde = { workspace = true, features = [ "derive" ] } -serde_json = { workspace = true } +serde_json = { workspace = true, default-features = true } fc-rpc-core = { workspace = true } diff --git a/client/rpc-core/types/Cargo.toml b/client/rpc-core/types/Cargo.toml index 5ab9086522..8c3c32bd8d 100644 --- a/client/rpc-core/types/Cargo.toml +++ b/client/rpc-core/types/Cargo.toml @@ -10,4 +10,4 @@ version = "0.1.0" [dependencies] ethereum-types = { workspace = true, features = [ "std" ] } serde = { workspace = true, features = [ "derive" ] } -serde_json = { workspace = true } +serde_json = { workspace = true, default-features = true } diff --git a/node/Cargo.toml b/node/Cargo.toml index fd855cf91c..120a9318e0 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -22,7 +22,7 @@ assert_cmd = { workspace = true } hex = { workspace = true, features = [ "std" ] } nix = { workspace = true } serde = { workspace = true, features = [ "derive" ] } -serde_json = { workspace = true } +serde_json = { workspace = true, default-features = true } tempfile = { workspace = true } tracing-core = { workspace = true } diff --git a/node/service/Cargo.toml b/node/service/Cargo.toml index 068340ac79..59b898d57e 100644 --- a/node/service/Cargo.toml +++ b/node/service/Cargo.toml @@ -21,7 +21,7 @@ log = { workspace = true } maplit = { workspace = true } parking_lot = { workspace = true } serde = { workspace = true, features = ["derive"] } -serde_json = { workspace = true } +serde_json = { workspace = true, default-features = true } sha3 = { workspace = true } tiny-bip39 = { workspace = true } tokio = { workspace = true, features = ["sync", "rt-multi-thread"] } From bc92fbdc1361372eada2c9b8550540f1ae38bee0 Mon Sep 17 00:00:00 2001 From: Rodrigo Quelhas Date: Thu, 23 Jan 2025 22:54:43 +0000 Subject: [PATCH 22/33] simplify code --- runtime/common/src/apis.rs | 14 ++++++++++++++ runtime/moonbase/src/lib.rs | 14 -------------- runtime/moonbeam/src/lib.rs | 14 -------------- runtime/moonriver/src/lib.rs | 14 -------------- 4 files changed, 14 insertions(+), 42 deletions(-) diff --git a/runtime/common/src/apis.rs b/runtime/common/src/apis.rs index 0ea4d99df3..f71be61b66 100644 --- a/runtime/common/src/apis.rs +++ b/runtime/common/src/apis.rs @@ -115,6 +115,20 @@ macro_rules! impl_runtime_apis_plus_common { } } + impl sp_genesis_builder::GenesisBuilder for Runtime { + fn build_state(config: Vec) -> sp_genesis_builder::Result { + frame_support::genesis_builder_helper::build_state::(config) + } + + fn get_preset(id: &Option) -> Option> { + frame_support::genesis_builder_helper::get_preset::(id, genesis_config_preset::get_preset) + } + + fn preset_names() -> Vec { + genesis_config_preset::preset_names() + } + } + impl frame_system_rpc_runtime_api::AccountNonceApi for Runtime { fn account_nonce(account: AccountId) -> Index { System::account_nonce(account) diff --git a/runtime/moonbase/src/lib.rs b/runtime/moonbase/src/lib.rs index da7cbbfa6a..2d4a264906 100644 --- a/runtime/moonbase/src/lib.rs +++ b/runtime/moonbase/src/lib.rs @@ -1584,20 +1584,6 @@ moonbeam_runtime_common::impl_runtime_apis_plus_common! { ConsensusHook::can_build_upon(included_hash, slot) } } - - impl sp_genesis_builder::GenesisBuilder for Runtime { - fn build_state(config: Vec) -> sp_genesis_builder::Result { - frame_support::genesis_builder_helper::build_state::(config) - } - - fn get_preset(id: &Option) -> Option> { - frame_support::genesis_builder_helper::get_preset::(id, crate::genesis_config_preset::get_preset) - } - - fn preset_names() -> Vec { - crate::genesis_config_preset::preset_names() - } - } } struct CheckInherents; diff --git a/runtime/moonbeam/src/lib.rs b/runtime/moonbeam/src/lib.rs index 20d6a9f713..97930546ad 100644 --- a/runtime/moonbeam/src/lib.rs +++ b/runtime/moonbeam/src/lib.rs @@ -1624,20 +1624,6 @@ moonbeam_runtime_common::impl_runtime_apis_plus_common! { ConsensusHook::can_build_upon(included_hash, slot) } } - - impl sp_genesis_builder::GenesisBuilder for Runtime { - fn build_state(config: Vec) -> sp_genesis_builder::Result { - frame_support::genesis_builder_helper::build_state::(config) - } - - fn get_preset(id: &Option) -> Option> { - frame_support::genesis_builder_helper::get_preset::(id, crate::genesis_config_preset::get_preset) - } - - fn preset_names() -> Vec { - crate::genesis_config_preset::preset_names() - } - } } struct CheckInherents; diff --git a/runtime/moonriver/src/lib.rs b/runtime/moonriver/src/lib.rs index 091d7d1b67..e7bb7519c1 100644 --- a/runtime/moonriver/src/lib.rs +++ b/runtime/moonriver/src/lib.rs @@ -1625,20 +1625,6 @@ moonbeam_runtime_common::impl_runtime_apis_plus_common! { ConsensusHook::can_build_upon(included_hash, slot) } } - - impl sp_genesis_builder::GenesisBuilder for Runtime { - fn build_state(config: Vec) -> sp_genesis_builder::Result { - frame_support::genesis_builder_helper::build_state::(config) - } - - fn get_preset(id: &Option) -> Option> { - frame_support::genesis_builder_helper::get_preset::(id, crate::genesis_config_preset::get_preset) - } - - fn preset_names() -> Vec { - crate::genesis_config_preset::preset_names() - } - } } struct CheckInherents; From 305d7cbf6a86f94e2e0ed4928ae56e8b6273e525 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Thu, 23 Jan 2025 18:23:58 +0100 Subject: [PATCH 23/33] style: :art: format comment/tuple --- runtime/moonbase/src/genesis_config_preset.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/runtime/moonbase/src/genesis_config_preset.rs b/runtime/moonbase/src/genesis_config_preset.rs index 7fef14d472..108eb2f66f 100644 --- a/runtime/moonbase/src/genesis_config_preset.rs +++ b/runtime/moonbase/src/genesis_config_preset.rs @@ -212,16 +212,14 @@ pub fn development() -> serde_json::Value { )), ], // Collator Candidates - vec![ + vec![( // Alice -> Alith - ( - AccountId::from(sp_core::hex2array!( - "f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac" - )), - get_from_seed::("Alice"), - 1_000 * UNIT, - ), - ], + AccountId::from(sp_core::hex2array!( + "f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac" + )), + get_from_seed::("Alice"), + 1_000 * UNIT, + )], // Delegations vec![], // Endowed: Alith, Baltathar, Charleth and Dorothy From 22951b75b962812768188b28f8ccd9aecd512fca Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Fri, 24 Jan 2025 12:15:44 +0100 Subject: [PATCH 24/33] feat: :sparkles: add cargo feature to disable genesis builder --- runtime/common/src/apis.rs | 1 + runtime/moonbase/Cargo.toml | 14 ++++++++++++-- runtime/moonbase/src/lib.rs | 1 + runtime/moonbeam/src/lib.rs | 1 + runtime/moonriver/src/lib.rs | 1 + 5 files changed, 16 insertions(+), 2 deletions(-) diff --git a/runtime/common/src/apis.rs b/runtime/common/src/apis.rs index f71be61b66..06518f61b5 100644 --- a/runtime/common/src/apis.rs +++ b/runtime/common/src/apis.rs @@ -115,6 +115,7 @@ macro_rules! impl_runtime_apis_plus_common { } } + #[cfg(not(feature = "disable-genesis-builder"))] impl sp_genesis_builder::GenesisBuilder for Runtime { fn build_state(config: Vec) -> sp_genesis_builder::Result { frame_support::genesis_builder_helper::build_state::(config) diff --git a/runtime/moonbase/Cargo.toml b/runtime/moonbase/Cargo.toml index c8cdc3e971..b9c966cf56 100644 --- a/runtime/moonbase/Cargo.toml +++ b/runtime/moonbase/Cargo.toml @@ -14,7 +14,9 @@ log = { workspace = true } num_enum = { workspace = true } rlp = { workspace = true, optional = true } serde = { workspace = true, features = ["derive"] } -serde_json = { workspace = true, default-features = false, features = ["alloc"] } +serde_json = { workspace = true, default-features = false, features = [ + "alloc", +] } sha3 = { workspace = true, optional = true } smallvec = { workspace = true } strum = { workspace = true } @@ -339,7 +341,15 @@ metadata-hash = ["substrate-wasm-builder/metadata-hash"] # A feature that should be enabled when the runtime should be build for on-chain # deployment. This will disable stuff that shouldn't be part of the on-chain wasm # to make it smaller like logging for example. -on-chain-release-build = ["metadata-hash", "sp-api/disable-logging"] +on-chain-release-build = [ + "metadata-hash", + "sp-api/disable-logging", + "disable-genesis-builder", +] + +# When enabled, the GenesisBuilder API will not be supported, GenesisConfig shall be +# stripped from the final binary +disable-genesis-builder = [] runtime-benchmarks = [ "cumulus-pallet-parachain-system/runtime-benchmarks", diff --git a/runtime/moonbase/src/lib.rs b/runtime/moonbase/src/lib.rs index 2d4a264906..a395ef52c1 100644 --- a/runtime/moonbase/src/lib.rs +++ b/runtime/moonbase/src/lib.rs @@ -29,6 +29,7 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); pub mod asset_config; +#[cfg(not(feature = "disable-genesis-builder"))] pub mod genesis_config_preset; pub mod governance; pub mod runtime_params; diff --git a/runtime/moonbeam/src/lib.rs b/runtime/moonbeam/src/lib.rs index 97930546ad..f95e3a8283 100644 --- a/runtime/moonbeam/src/lib.rs +++ b/runtime/moonbeam/src/lib.rs @@ -119,6 +119,7 @@ pub use sp_runtime::BuildStorage; pub type Precompiles = MoonbeamPrecompiles; pub mod asset_config; +#[cfg(not(feature = "disable-genesis-builder"))] pub mod genesis_config_preset; pub mod governance; pub mod runtime_params; diff --git a/runtime/moonriver/src/lib.rs b/runtime/moonriver/src/lib.rs index e7bb7519c1..730d192224 100644 --- a/runtime/moonriver/src/lib.rs +++ b/runtime/moonriver/src/lib.rs @@ -121,6 +121,7 @@ pub use sp_runtime::BuildStorage; pub type Precompiles = MoonriverPrecompiles; pub mod asset_config; +#[cfg(not(feature = "disable-genesis-builder"))] pub mod genesis_config_preset; pub mod governance; pub mod runtime_params; From f323670916918b6ffbbea48ff7b8e3efc83acbdf Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Fri, 24 Jan 2025 12:34:52 +0100 Subject: [PATCH 25/33] refactor: :zap: change cargo feature disable-genesis-builder to enable-genesis-builder --- runtime/common/src/apis.rs | 2 +- runtime/moonbase/Cargo.toml | 13 +++++-------- runtime/moonbase/src/lib.rs | 2 +- runtime/moonbeam/src/lib.rs | 2 +- runtime/moonriver/src/lib.rs | 2 +- 5 files changed, 9 insertions(+), 12 deletions(-) diff --git a/runtime/common/src/apis.rs b/runtime/common/src/apis.rs index 06518f61b5..b9cda9a86f 100644 --- a/runtime/common/src/apis.rs +++ b/runtime/common/src/apis.rs @@ -115,7 +115,7 @@ macro_rules! impl_runtime_apis_plus_common { } } - #[cfg(not(feature = "disable-genesis-builder"))] + #[cfg(feature = "enable-genesis-builder")] impl sp_genesis_builder::GenesisBuilder for Runtime { fn build_state(config: Vec) -> sp_genesis_builder::Result { frame_support::genesis_builder_helper::build_state::(config) diff --git a/runtime/moonbase/Cargo.toml b/runtime/moonbase/Cargo.toml index b9c966cf56..72dc86b76c 100644 --- a/runtime/moonbase/Cargo.toml +++ b/runtime/moonbase/Cargo.toml @@ -16,7 +16,7 @@ rlp = { workspace = true, optional = true } serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true, default-features = false, features = [ "alloc", -] } +], optional = true } sha3 = { workspace = true, optional = true } smallvec = { workspace = true } strum = { workspace = true } @@ -204,7 +204,7 @@ precompile-utils = { workspace = true, features = ["std", "testing"] } substrate-wasm-builder = { workspace = true } [features] -default = ["std"] +default = ["std", "serde_json"] std = [ "account/std", "async-backing-primitives/std", @@ -341,19 +341,16 @@ metadata-hash = ["substrate-wasm-builder/metadata-hash"] # A feature that should be enabled when the runtime should be build for on-chain # deployment. This will disable stuff that shouldn't be part of the on-chain wasm # to make it smaller like logging for example. -on-chain-release-build = [ - "metadata-hash", - "sp-api/disable-logging", - "disable-genesis-builder", -] +on-chain-release-build = ["metadata-hash", "sp-api/disable-logging"] # When enabled, the GenesisBuilder API will not be supported, GenesisConfig shall be # stripped from the final binary -disable-genesis-builder = [] +enable-genesis-builder = ["serde_json"] runtime-benchmarks = [ "cumulus-pallet-parachain-system/runtime-benchmarks", "cumulus-primitives-core/runtime-benchmarks", + "enable-genesis-builder", "frame-benchmarking/runtime-benchmarks", "frame-support/runtime-benchmarks", "frame-system-benchmarking/runtime-benchmarks", diff --git a/runtime/moonbase/src/lib.rs b/runtime/moonbase/src/lib.rs index a395ef52c1..9782f7e674 100644 --- a/runtime/moonbase/src/lib.rs +++ b/runtime/moonbase/src/lib.rs @@ -29,7 +29,7 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); pub mod asset_config; -#[cfg(not(feature = "disable-genesis-builder"))] +#[cfg(feature = "enable-genesis-builder")] pub mod genesis_config_preset; pub mod governance; pub mod runtime_params; diff --git a/runtime/moonbeam/src/lib.rs b/runtime/moonbeam/src/lib.rs index f95e3a8283..679a77b990 100644 --- a/runtime/moonbeam/src/lib.rs +++ b/runtime/moonbeam/src/lib.rs @@ -119,7 +119,7 @@ pub use sp_runtime::BuildStorage; pub type Precompiles = MoonbeamPrecompiles; pub mod asset_config; -#[cfg(not(feature = "disable-genesis-builder"))] +#[cfg(feature = "enable-genesis-builder")] pub mod genesis_config_preset; pub mod governance; pub mod runtime_params; diff --git a/runtime/moonriver/src/lib.rs b/runtime/moonriver/src/lib.rs index 730d192224..9e0570d3da 100644 --- a/runtime/moonriver/src/lib.rs +++ b/runtime/moonriver/src/lib.rs @@ -121,7 +121,7 @@ pub use sp_runtime::BuildStorage; pub type Precompiles = MoonriverPrecompiles; pub mod asset_config; -#[cfg(not(feature = "disable-genesis-builder"))] +#[cfg(feature = "enable-genesis-builder")] pub mod genesis_config_preset; pub mod governance; pub mod runtime_params; From 1ba1ba3656c59afdf74c41c2e41f4a4e6c9bdabe Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Fri, 24 Jan 2025 12:49:15 +0100 Subject: [PATCH 26/33] fix: :bug: correct enable-genesis-builder cargo feature logic and add it to all runtimes --- node/service/Cargo.toml | 12 +++++++++--- runtime/moonbase/Cargo.toml | 4 ++-- runtime/moonbeam/Cargo.toml | 8 +++++++- runtime/moonriver/Cargo.toml | 10 ++++++++-- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/node/service/Cargo.toml b/node/service/Cargo.toml index 59b898d57e..5531223595 100644 --- a/node/service/Cargo.toml +++ b/node/service/Cargo.toml @@ -52,9 +52,15 @@ pallet-xcm-transactor = { workspace = true } session-keys-primitives = { workspace = true } # Moonbeam runtimes -moonbase-runtime = { workspace = true, optional = true } -moonbeam-runtime = { workspace = true, optional = true } -moonriver-runtime = { workspace = true, optional = true } +moonbase-runtime = { workspace = true, features = [ + "enable-genesis-builder", +], optional = true } +moonbeam-runtime = { workspace = true, features = [ + "enable-genesis-builder", +], optional = true } +moonriver-runtime = { workspace = true, features = [ + "enable-genesis-builder", +], optional = true } # Substrate frame-system-rpc-runtime-api = { workspace = true, features = ["std"] } diff --git a/runtime/moonbase/Cargo.toml b/runtime/moonbase/Cargo.toml index 72dc86b76c..665e72afd2 100644 --- a/runtime/moonbase/Cargo.toml +++ b/runtime/moonbase/Cargo.toml @@ -204,7 +204,7 @@ precompile-utils = { workspace = true, features = ["std", "testing"] } substrate-wasm-builder = { workspace = true } [features] -default = ["std", "serde_json"] +default = ["std", "enable-genesis-builder"] std = [ "account/std", "async-backing-primitives/std", @@ -343,7 +343,7 @@ metadata-hash = ["substrate-wasm-builder/metadata-hash"] # to make it smaller like logging for example. on-chain-release-build = ["metadata-hash", "sp-api/disable-logging"] -# When enabled, the GenesisBuilder API will not be supported, GenesisConfig shall be +# When enabled, the GenesisBuilder API will be supported, GenesisConfig shall be # stripped from the final binary enable-genesis-builder = ["serde_json"] diff --git a/runtime/moonbeam/Cargo.toml b/runtime/moonbeam/Cargo.toml index 10789a3b00..b9a7feb855 100644 --- a/runtime/moonbeam/Cargo.toml +++ b/runtime/moonbeam/Cargo.toml @@ -14,7 +14,9 @@ log = { workspace = true } num_enum = { workspace = true } rlp = { workspace = true, optional = true } serde = { workspace = true, features = ["derive"] } -serde_json = { workspace = true, default-features = false, features = ["alloc"] } +serde_json = { workspace = true, default-features = false, features = [ + "alloc", +], optional = true } sha3 = { workspace = true, optional = true } smallvec = { workspace = true } strum = { workspace = true } @@ -330,6 +332,10 @@ metadata-hash = ["substrate-wasm-builder/metadata-hash"] # to make it smaller like logging for example. on-chain-release-build = ["metadata-hash", "sp-api/disable-logging"] +# When enabled, the GenesisBuilder API will be supported, GenesisConfig shall be +# stripped from the final binary +enable-genesis-builder = ["serde_json"] + runtime-benchmarks = [ "cumulus-pallet-parachain-system/runtime-benchmarks", "cumulus-primitives-core/runtime-benchmarks", diff --git a/runtime/moonriver/Cargo.toml b/runtime/moonriver/Cargo.toml index 4eff5e62a8..e62293ea75 100644 --- a/runtime/moonriver/Cargo.toml +++ b/runtime/moonriver/Cargo.toml @@ -14,7 +14,9 @@ log = { workspace = true } num_enum = { workspace = true } rlp = { workspace = true, optional = true } serde = { workspace = true, features = ["derive"] } -serde_json = { workspace = true, default-features = false, features = ["alloc"] } +serde_json = { workspace = true, default-features = false, features = [ + "alloc", +], optional = true } sha3 = { workspace = true, optional = true } smallvec = { workspace = true } strum = { workspace = true } @@ -198,7 +200,7 @@ precompile-utils = { workspace = true, features = ["std", "testing"] } substrate-wasm-builder = { workspace = true } [features] -default = ["std"] +default = ["std", "enable-genesis-builder"] std = [ "account/std", "async-backing-primitives/std", @@ -335,6 +337,10 @@ metadata-hash = ["substrate-wasm-builder/metadata-hash"] # to make it smaller like logging for example. on-chain-release-build = ["metadata-hash", "sp-api/disable-logging"] +# When enabled, the GenesisBuilder API will be supported, GenesisConfig shall be +# stripped from the final binary +enable-genesis-builder = ["serde_json"] + runtime-benchmarks = [ "cumulus-pallet-parachain-system/runtime-benchmarks", "cumulus-primitives-core/runtime-benchmarks", From 0e7a2273c646d2cffdd5632a5bbada24a5cd80e4 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Fri, 24 Jan 2025 13:08:45 +0100 Subject: [PATCH 27/33] style: :art: rename enable-genesis-config cargo feature to genesis-config --- node/service/Cargo.toml | 6 +++--- runtime/common/src/apis.rs | 2 +- runtime/moonbase/Cargo.toml | 6 +++--- runtime/moonbase/src/lib.rs | 2 +- runtime/moonbeam/Cargo.toml | 2 +- runtime/moonbeam/src/lib.rs | 2 +- runtime/moonriver/Cargo.toml | 4 ++-- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/node/service/Cargo.toml b/node/service/Cargo.toml index 5531223595..a5766e5cd2 100644 --- a/node/service/Cargo.toml +++ b/node/service/Cargo.toml @@ -53,13 +53,13 @@ session-keys-primitives = { workspace = true } # Moonbeam runtimes moonbase-runtime = { workspace = true, features = [ - "enable-genesis-builder", + "genesis-builder", ], optional = true } moonbeam-runtime = { workspace = true, features = [ - "enable-genesis-builder", + "genesis-builder", ], optional = true } moonriver-runtime = { workspace = true, features = [ - "enable-genesis-builder", + "genesis-builder", ], optional = true } # Substrate diff --git a/runtime/common/src/apis.rs b/runtime/common/src/apis.rs index b9cda9a86f..d865911f48 100644 --- a/runtime/common/src/apis.rs +++ b/runtime/common/src/apis.rs @@ -115,7 +115,7 @@ macro_rules! impl_runtime_apis_plus_common { } } - #[cfg(feature = "enable-genesis-builder")] + #[cfg(feature = "genesis-builder")] impl sp_genesis_builder::GenesisBuilder for Runtime { fn build_state(config: Vec) -> sp_genesis_builder::Result { frame_support::genesis_builder_helper::build_state::(config) diff --git a/runtime/moonbase/Cargo.toml b/runtime/moonbase/Cargo.toml index 665e72afd2..9e2c88fb06 100644 --- a/runtime/moonbase/Cargo.toml +++ b/runtime/moonbase/Cargo.toml @@ -204,7 +204,7 @@ precompile-utils = { workspace = true, features = ["std", "testing"] } substrate-wasm-builder = { workspace = true } [features] -default = ["std", "enable-genesis-builder"] +default = ["std", "genesis-builder"] std = [ "account/std", "async-backing-primitives/std", @@ -345,12 +345,12 @@ on-chain-release-build = ["metadata-hash", "sp-api/disable-logging"] # When enabled, the GenesisBuilder API will be supported, GenesisConfig shall be # stripped from the final binary -enable-genesis-builder = ["serde_json"] +genesis-builder = ["serde_json"] runtime-benchmarks = [ "cumulus-pallet-parachain-system/runtime-benchmarks", "cumulus-primitives-core/runtime-benchmarks", - "enable-genesis-builder", + "genesis-builder", "frame-benchmarking/runtime-benchmarks", "frame-support/runtime-benchmarks", "frame-system-benchmarking/runtime-benchmarks", diff --git a/runtime/moonbase/src/lib.rs b/runtime/moonbase/src/lib.rs index 9782f7e674..7baae90b2b 100644 --- a/runtime/moonbase/src/lib.rs +++ b/runtime/moonbase/src/lib.rs @@ -29,7 +29,7 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); pub mod asset_config; -#[cfg(feature = "enable-genesis-builder")] +#[cfg(feature = "genesis-builder")] pub mod genesis_config_preset; pub mod governance; pub mod runtime_params; diff --git a/runtime/moonbeam/Cargo.toml b/runtime/moonbeam/Cargo.toml index b9a7feb855..c0e00db627 100644 --- a/runtime/moonbeam/Cargo.toml +++ b/runtime/moonbeam/Cargo.toml @@ -334,7 +334,7 @@ on-chain-release-build = ["metadata-hash", "sp-api/disable-logging"] # When enabled, the GenesisBuilder API will be supported, GenesisConfig shall be # stripped from the final binary -enable-genesis-builder = ["serde_json"] +genesis-builder = ["serde_json"] runtime-benchmarks = [ "cumulus-pallet-parachain-system/runtime-benchmarks", diff --git a/runtime/moonbeam/src/lib.rs b/runtime/moonbeam/src/lib.rs index 679a77b990..dd85f13cd0 100644 --- a/runtime/moonbeam/src/lib.rs +++ b/runtime/moonbeam/src/lib.rs @@ -119,7 +119,7 @@ pub use sp_runtime::BuildStorage; pub type Precompiles = MoonbeamPrecompiles; pub mod asset_config; -#[cfg(feature = "enable-genesis-builder")] +#[cfg(feature = "genesis-builder")] pub mod genesis_config_preset; pub mod governance; pub mod runtime_params; diff --git a/runtime/moonriver/Cargo.toml b/runtime/moonriver/Cargo.toml index e62293ea75..cea4066251 100644 --- a/runtime/moonriver/Cargo.toml +++ b/runtime/moonriver/Cargo.toml @@ -200,7 +200,7 @@ precompile-utils = { workspace = true, features = ["std", "testing"] } substrate-wasm-builder = { workspace = true } [features] -default = ["std", "enable-genesis-builder"] +default = ["std", "genesis-builder"] std = [ "account/std", "async-backing-primitives/std", @@ -339,7 +339,7 @@ on-chain-release-build = ["metadata-hash", "sp-api/disable-logging"] # When enabled, the GenesisBuilder API will be supported, GenesisConfig shall be # stripped from the final binary -enable-genesis-builder = ["serde_json"] +genesis-builder = ["serde_json"] runtime-benchmarks = [ "cumulus-pallet-parachain-system/runtime-benchmarks", From 590829446062c1745b47aa6129b2520d503db34e Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Fri, 24 Jan 2025 14:10:17 +0100 Subject: [PATCH 28/33] fix: :bug: apply renaming of cargo feature enable-genesis-builder --- runtime/moonriver/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/moonriver/src/lib.rs b/runtime/moonriver/src/lib.rs index 9e0570d3da..9c878d8904 100644 --- a/runtime/moonriver/src/lib.rs +++ b/runtime/moonriver/src/lib.rs @@ -121,7 +121,7 @@ pub use sp_runtime::BuildStorage; pub type Precompiles = MoonriverPrecompiles; pub mod asset_config; -#[cfg(feature = "enable-genesis-builder")] +#[cfg(feature = "genesis-builder")] pub mod genesis_config_preset; pub mod governance; pub mod runtime_params; From 061254dd5b47a57a030a07c2983a4757d280958f Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Fri, 24 Jan 2025 14:12:19 +0100 Subject: [PATCH 29/33] feat: :fire: remove genesis-builder from default features --- runtime/moonbase/Cargo.toml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/runtime/moonbase/Cargo.toml b/runtime/moonbase/Cargo.toml index 9e2c88fb06..720912eef1 100644 --- a/runtime/moonbase/Cargo.toml +++ b/runtime/moonbase/Cargo.toml @@ -204,7 +204,7 @@ precompile-utils = { workspace = true, features = ["std", "testing"] } substrate-wasm-builder = { workspace = true } [features] -default = ["std", "genesis-builder"] +default = ["std"] std = [ "account/std", "async-backing-primitives/std", @@ -303,7 +303,6 @@ std = [ "parity-scale-codec/std", "precompile-utils/std", "scale-info/std", - "serde_json/std", "session-keys-primitives/std", "sp-api/std", "sp-block-builder/std", From 261029dfd0a0d6b74948cda18d657429ea437bab Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Fri, 24 Jan 2025 14:49:25 +0100 Subject: [PATCH 30/33] feat: :zap: remove genesis-builder and serde_json from default features --- runtime/moonbeam/Cargo.toml | 1 - runtime/moonriver/Cargo.toml | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/runtime/moonbeam/Cargo.toml b/runtime/moonbeam/Cargo.toml index c0e00db627..e94e512cde 100644 --- a/runtime/moonbeam/Cargo.toml +++ b/runtime/moonbeam/Cargo.toml @@ -297,7 +297,6 @@ std = [ "parity-scale-codec/std", "precompile-utils/std", "scale-info/std", - "serde_json/std", "session-keys-primitives/std", "sp-api/std", "sp-block-builder/std", diff --git a/runtime/moonriver/Cargo.toml b/runtime/moonriver/Cargo.toml index cea4066251..24bf304bb8 100644 --- a/runtime/moonriver/Cargo.toml +++ b/runtime/moonriver/Cargo.toml @@ -200,7 +200,7 @@ precompile-utils = { workspace = true, features = ["std", "testing"] } substrate-wasm-builder = { workspace = true } [features] -default = ["std", "genesis-builder"] +default = ["std"] std = [ "account/std", "async-backing-primitives/std", @@ -297,7 +297,6 @@ std = [ "parity-scale-codec/std", "precompile-utils/std", "scale-info/std", - "serde_json/std", "session-keys-primitives/std", "sp-api/std", "sp-block-builder/std", From c4b071e9381877f419668ce3ebf67fa9002534f8 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Fri, 24 Jan 2025 17:14:47 +0100 Subject: [PATCH 31/33] refactor: :recycle: switch back to disable-genesis-builder --- runtime/common/src/apis.rs | 2 +- runtime/moonbase/Cargo.toml | 11 ++++++++--- runtime/moonbase/src/lib.rs | 2 +- runtime/moonbeam/Cargo.toml | 11 ++++++++--- runtime/moonbeam/src/lib.rs | 2 +- runtime/moonriver/Cargo.toml | 11 ++++++++--- runtime/moonriver/src/lib.rs | 2 +- 7 files changed, 28 insertions(+), 13 deletions(-) diff --git a/runtime/common/src/apis.rs b/runtime/common/src/apis.rs index d865911f48..06518f61b5 100644 --- a/runtime/common/src/apis.rs +++ b/runtime/common/src/apis.rs @@ -115,7 +115,7 @@ macro_rules! impl_runtime_apis_plus_common { } } - #[cfg(feature = "genesis-builder")] + #[cfg(not(feature = "disable-genesis-builder"))] impl sp_genesis_builder::GenesisBuilder for Runtime { fn build_state(config: Vec) -> sp_genesis_builder::Result { frame_support::genesis_builder_helper::build_state::(config) diff --git a/runtime/moonbase/Cargo.toml b/runtime/moonbase/Cargo.toml index 720912eef1..4fe95e49e5 100644 --- a/runtime/moonbase/Cargo.toml +++ b/runtime/moonbase/Cargo.toml @@ -16,7 +16,7 @@ rlp = { workspace = true, optional = true } serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true, default-features = false, features = [ "alloc", -], optional = true } +] } sha3 = { workspace = true, optional = true } smallvec = { workspace = true } strum = { workspace = true } @@ -303,6 +303,7 @@ std = [ "parity-scale-codec/std", "precompile-utils/std", "scale-info/std", + "serde_json/std", "session-keys-primitives/std", "sp-api/std", "sp-block-builder/std", @@ -340,11 +341,15 @@ metadata-hash = ["substrate-wasm-builder/metadata-hash"] # A feature that should be enabled when the runtime should be build for on-chain # deployment. This will disable stuff that shouldn't be part of the on-chain wasm # to make it smaller like logging for example. -on-chain-release-build = ["metadata-hash", "sp-api/disable-logging"] +on-chain-release-build = [ + "metadata-hash", + "sp-api/disable-logging", + "disable-genesis-builder", +] # When enabled, the GenesisBuilder API will be supported, GenesisConfig shall be # stripped from the final binary -genesis-builder = ["serde_json"] +disable-genesis-builder = [] runtime-benchmarks = [ "cumulus-pallet-parachain-system/runtime-benchmarks", diff --git a/runtime/moonbase/src/lib.rs b/runtime/moonbase/src/lib.rs index 7baae90b2b..a395ef52c1 100644 --- a/runtime/moonbase/src/lib.rs +++ b/runtime/moonbase/src/lib.rs @@ -29,7 +29,7 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); pub mod asset_config; -#[cfg(feature = "genesis-builder")] +#[cfg(not(feature = "disable-genesis-builder"))] pub mod genesis_config_preset; pub mod governance; pub mod runtime_params; diff --git a/runtime/moonbeam/Cargo.toml b/runtime/moonbeam/Cargo.toml index e94e512cde..709388650d 100644 --- a/runtime/moonbeam/Cargo.toml +++ b/runtime/moonbeam/Cargo.toml @@ -16,7 +16,7 @@ rlp = { workspace = true, optional = true } serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true, default-features = false, features = [ "alloc", -], optional = true } +] } sha3 = { workspace = true, optional = true } smallvec = { workspace = true } strum = { workspace = true } @@ -297,6 +297,7 @@ std = [ "parity-scale-codec/std", "precompile-utils/std", "scale-info/std", + "serde_json/std", "session-keys-primitives/std", "sp-api/std", "sp-block-builder/std", @@ -329,11 +330,15 @@ metadata-hash = ["substrate-wasm-builder/metadata-hash"] # A feature that should be enabled when the runtime should be build for on-chain # deployment. This will disable stuff that shouldn't be part of the on-chain wasm # to make it smaller like logging for example. -on-chain-release-build = ["metadata-hash", "sp-api/disable-logging"] +on-chain-release-build = [ + "metadata-hash", + "sp-api/disable-logging", + "disable-genesis-builder", +] # When enabled, the GenesisBuilder API will be supported, GenesisConfig shall be # stripped from the final binary -genesis-builder = ["serde_json"] +disable-genesis-builder = [] runtime-benchmarks = [ "cumulus-pallet-parachain-system/runtime-benchmarks", diff --git a/runtime/moonbeam/src/lib.rs b/runtime/moonbeam/src/lib.rs index dd85f13cd0..f95e3a8283 100644 --- a/runtime/moonbeam/src/lib.rs +++ b/runtime/moonbeam/src/lib.rs @@ -119,7 +119,7 @@ pub use sp_runtime::BuildStorage; pub type Precompiles = MoonbeamPrecompiles; pub mod asset_config; -#[cfg(feature = "genesis-builder")] +#[cfg(not(feature = "disable-genesis-builder"))] pub mod genesis_config_preset; pub mod governance; pub mod runtime_params; diff --git a/runtime/moonriver/Cargo.toml b/runtime/moonriver/Cargo.toml index 24bf304bb8..f25297583c 100644 --- a/runtime/moonriver/Cargo.toml +++ b/runtime/moonriver/Cargo.toml @@ -16,7 +16,7 @@ rlp = { workspace = true, optional = true } serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true, default-features = false, features = [ "alloc", -], optional = true } +] } sha3 = { workspace = true, optional = true } smallvec = { workspace = true } strum = { workspace = true } @@ -297,6 +297,7 @@ std = [ "parity-scale-codec/std", "precompile-utils/std", "scale-info/std", + "serde_json/std", "session-keys-primitives/std", "sp-api/std", "sp-block-builder/std", @@ -334,11 +335,15 @@ metadata-hash = ["substrate-wasm-builder/metadata-hash"] # A feature that should be enabled when the runtime should be build for on-chain # deployment. This will disable stuff that shouldn't be part of the on-chain wasm # to make it smaller like logging for example. -on-chain-release-build = ["metadata-hash", "sp-api/disable-logging"] +on-chain-release-build = [ + "metadata-hash", + "sp-api/disable-logging", + "disable-genesis-builder", +] # When enabled, the GenesisBuilder API will be supported, GenesisConfig shall be # stripped from the final binary -genesis-builder = ["serde_json"] +disable-genesis-builder = [] runtime-benchmarks = [ "cumulus-pallet-parachain-system/runtime-benchmarks", diff --git a/runtime/moonriver/src/lib.rs b/runtime/moonriver/src/lib.rs index 9c878d8904..730d192224 100644 --- a/runtime/moonriver/src/lib.rs +++ b/runtime/moonriver/src/lib.rs @@ -121,7 +121,7 @@ pub use sp_runtime::BuildStorage; pub type Precompiles = MoonriverPrecompiles; pub mod asset_config; -#[cfg(feature = "genesis-builder")] +#[cfg(not(feature = "disable-genesis-builder"))] pub mod genesis_config_preset; pub mod governance; pub mod runtime_params; From 6794d92cd4bc2049bcb50f3d32bcd48ec7778235 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Fri, 24 Jan 2025 17:17:37 +0100 Subject: [PATCH 32/33] fix: :bug: remove genesis-builder feature references --- node/service/Cargo.toml | 12 +++--------- runtime/moonbase/Cargo.toml | 1 - 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/node/service/Cargo.toml b/node/service/Cargo.toml index a5766e5cd2..59b898d57e 100644 --- a/node/service/Cargo.toml +++ b/node/service/Cargo.toml @@ -52,15 +52,9 @@ pallet-xcm-transactor = { workspace = true } session-keys-primitives = { workspace = true } # Moonbeam runtimes -moonbase-runtime = { workspace = true, features = [ - "genesis-builder", -], optional = true } -moonbeam-runtime = { workspace = true, features = [ - "genesis-builder", -], optional = true } -moonriver-runtime = { workspace = true, features = [ - "genesis-builder", -], optional = true } +moonbase-runtime = { workspace = true, optional = true } +moonbeam-runtime = { workspace = true, optional = true } +moonriver-runtime = { workspace = true, optional = true } # Substrate frame-system-rpc-runtime-api = { workspace = true, features = ["std"] } diff --git a/runtime/moonbase/Cargo.toml b/runtime/moonbase/Cargo.toml index 4fe95e49e5..e8aad4feca 100644 --- a/runtime/moonbase/Cargo.toml +++ b/runtime/moonbase/Cargo.toml @@ -354,7 +354,6 @@ disable-genesis-builder = [] runtime-benchmarks = [ "cumulus-pallet-parachain-system/runtime-benchmarks", "cumulus-primitives-core/runtime-benchmarks", - "genesis-builder", "frame-benchmarking/runtime-benchmarks", "frame-support/runtime-benchmarks", "frame-system-benchmarking/runtime-benchmarks", From b0d81d085d6711ef2c6a37676b6977cfe6d8e39d Mon Sep 17 00:00:00 2001 From: Rodrigo Quelhas Date: Fri, 24 Jan 2025 18:20:52 +0000 Subject: [PATCH 33/33] chore(ci): fix wasm-size-check --- .github/workflows/build.yml | 38 ++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b7de9c3ade..bd41936b8c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -297,6 +297,7 @@ jobs: name: "Check WASM runtimes with Twiggy" runs-on: ubuntu-latest permissions: + actions: read contents: read pull-requests: write if: ${{ github.event_name == 'pull_request' && !github.event.pull_request.head.repo.fork }} @@ -317,24 +318,47 @@ jobs: - name: Download Twiggy run: cargo install twiggy - name: Lookup for latest target branch build + id: latest-target-build run: | TARGET_BRANCH=${{ github.event.pull_request.base.ref }} LATEST_TARGET_BRANCH_BUILD=$(gh run -R moonbeam-foundation/moonbeam list -w Build --limit=100 --json databaseId,url,headBranch,event,status,conclusion,createdAt --jq ".[] | select(.headBranch == \"$TARGET_BRANCH\" and .event == \"push\" and .status == \"completed\" and .conclusion == \"success\") | .databaseId" | head -n 1) echo "LATEST_TARGET_BRANCH_BUILD=$LATEST_TARGET_BRANCH_BUILD" >> $GITHUB_OUTPUT - - name: Download latest target branch build artifacts + - name: "Download runtimes from target branch" + uses: actions/download-artifact@v4 + with: + name: runtimes + path: runtimes-target-branch + merge-multiple: true + github-token: ${{ github.token }} + run-id: ${{ steps.latest-target-build.outputs.LATEST_TARGET_BRANCH_BUILD }} + - name: "Download uncompressed-runtimes from target branch" + uses: actions/download-artifact@v4 + with: + name: uncompressed-runtimes + path: uncompressed-runtimes-target-branch + merge-multiple: true + github-token: ${{ github.token }} + run-id: ${{ steps.latest-target-build.outputs.LATEST_TARGET_BRANCH_BUILD }} + - name: Check Runtimes size for target branch run: | - gh run -R moonbeam-foundation/moonbeam download $LATEST_TARGET_BRANCH_BUILD -n uncompressed-runtimes --dir uncompressed-runtimes-target-branch - gh run -R moonbeam-foundation/moonbeam download $LATEST_TARGET_BRANCH_BUILD -n runtimes --dir runtimes-target-branch + PREVIOUS_MOONBASE=$(du -k runtimes-target-branch/* | awk '/moonbase_runtime/ {print $1}') + PREVIOUS_MOONBEAM=$(du -k runtimes-target-branch/* | awk '/moonbeam_runtime/ {print $1}') + PREVIOUS_MOONRIVER=$(du -k runtimes-target-branch/* | awk '/moonriver_runtime/ {print $1}') + echo "PREVIOUS_MOONBASE=$PREVIOUS_MOONBASE" >> $GITHUB_ENV + echo "PREVIOUS_MOONBEAM=$PREVIOUS_MOONBEAM" >> $GITHUB_ENV + echo "PREVIOUS_MOONRIVER=$PREVIOUS_MOONRIVER" >> $GITHUB_ENV - name: "Download branch built runtime" uses: actions/download-artifact@v4 with: name: runtimes path: runtimes-current-branch + merge-multiple: true - name: "Download branch built uncompressed-runtimes" uses: actions/download-artifact@v4 with: name: uncompressed-runtimes path: uncompressed-runtimes-current-branch + merge-multiple: true - name: Check Runtimes size for current branch run: | CURRENT_MOONBASE=$(du -k runtimes-current-branch/* | awk '/moonbase_runtime/ {print $1}') @@ -360,14 +384,6 @@ jobs: echo "LATEST_MOONBASE=$LATEST_MOONBASE" >> $GITHUB_ENV echo "LATEST_MOONBEAM=$LATEST_MOONBEAM" >> $GITHUB_ENV echo "LATEST_MOONRIVER=$LATEST_MOONRIVER" >> $GITHUB_ENV - - name: Check Runtimes size for target branch - run: | - PREVIOUS_MOONBASE=$(du -k runtimes-target-branch/* | awk '/moonbase_runtime/ {print $1}') - PREVIOUS_MOONBEAM=$(du -k runtimes-target-branch/* | awk '/moonbeam_runtime/ {print $1}') - PREVIOUS_MOONRIVER=$(du -k runtimes-target-branch/* | awk '/moonriver_runtime/ {print $1}') - echo "PREVIOUS_MOONBASE=$PREVIOUS_MOONBASE" >> $GITHUB_ENV - echo "PREVIOUS_MOONBEAM=$PREVIOUS_MOONBEAM" >> $GITHUB_ENV - echo "PREVIOUS_MOONRIVER=$PREVIOUS_MOONRIVER" >> $GITHUB_ENV - name: Create Twiggy diff reports run: | # Install Twiggy if not already installed