diff --git a/Cargo.lock b/Cargo.lock index a1645e4030..6a8ca31c0b 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", @@ -7044,6 +7046,7 @@ dependencies = [ "sp-consensus", "sp-core", "sp-externalities", + "sp-genesis-builder", "sp-inherents", "sp-io", "sp-keystore", @@ -7251,6 +7254,7 @@ dependencies = [ "rlp", "scale-info", "serde", + "serde_json", "session-keys-primitives", "sha3", "smallvec", 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/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/Cargo.toml b/node/service/Cargo.toml index a749ab2307..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"] } @@ -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 3d2d34af2a..b2a90873f2 100644 --- a/node/service/src/chain_spec/moonbase.rs +++ b/node/service/src/chain_spec/moonbase.rs @@ -25,20 +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, 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, 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}; /// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type. pub type ChainSpec = sc_service::GenericChainSpec; @@ -122,201 +114,10 @@ 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() } -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.") -} - #[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..7a2ee3dc67 100644 --- a/node/service/src/chain_spec/moonbeam.rs +++ b/node/service/src/chain_spec/moonbeam.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 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, 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}; /// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type. pub type ChainSpec = sc_service::GenericChainSpec; @@ -113,188 +108,10 @@ 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() } -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.") -} - #[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..e35b3b0c00 100644 --- a/node/service/src/chain_spec/moonriver.rs +++ b/node/service/src/chain_spec/moonriver.rs @@ -25,19 +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, 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, 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}; /// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type. pub type ChainSpec = sc_service::GenericChainSpec; @@ -113,188 +106,10 @@ 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() } -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.") -} - #[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..1a1ebf305f 100644 --- a/node/service/src/chain_spec/test_spec.rs +++ b/node/service/src/chain_spec/test_spec.rs @@ -15,19 +15,16 @@ // 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::{get_from_seed, Extensions}; +use crate::chain_spec::moonbase::ChainSpec; +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(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(crate::chain_spec::moonbeam::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()); 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/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/common/src/apis.rs b/runtime/common/src/apis.rs index 144a82f966..f71be61b66 100644 --- a/runtime/common/src/apis.rs +++ b/runtime/common/src/apis.rs @@ -121,11 +121,11 @@ 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, genesis_config_preset::get_preset) } fn preset_names() -> Vec { - vec![] + genesis_config_preset::preset_names() } } diff --git a/runtime/moonbase/Cargo.toml b/runtime/moonbase/Cargo.toml index 8d334d43ad..c8cdc3e971 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 = { workspace = true, default-features = false, features = ["alloc"] } sha3 = { workspace = true, optional = true } smallvec = { workspace = true } strum = { workspace = true } @@ -300,6 +301,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/moonbase/src/genesis_config_preset.rs b/runtime/moonbase/src/genesis_config_preset.rs new file mode 100644 index 0000000000..7fef14d472 --- /dev/null +++ b/runtime/moonbase/src/genesis_config_preset.rs @@ -0,0 +1,264 @@ +// 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::{ + 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; +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); +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.") +} + +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 + ) +} + +/// 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 5cd1c82cc1..2d4a264906 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; +pub mod genesis_config_preset; pub mod governance; pub mod runtime_params; pub mod xcm_config; diff --git a/runtime/moonbeam/Cargo.toml b/runtime/moonbeam/Cargo.toml index 1f87feabe2..10789a3b00 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 = { workspace = true, default-features = false, features = ["alloc"] } sha3 = { workspace = true, optional = true } smallvec = { workspace = true } strum = { workspace = true } @@ -294,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/moonbeam/src/genesis_config_preset.rs b/runtime/moonbeam/src/genesis_config_preset.rs new file mode 100644 index 0000000000..a478f9a932 --- /dev/null +++ b/runtime/moonbeam/src/genesis_config_preset.rs @@ -0,0 +1,246 @@ +// 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::{ + 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_genesis_builder::PresetId; +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 + ) +} + +/// 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 9190d2804a..97930546ad 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; diff --git a/runtime/moonriver/Cargo.toml b/runtime/moonriver/Cargo.toml index 7ac5e41d7d..4eff5e62a8 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 = { workspace = true, default-features = false, features = ["alloc"] } sha3 = { workspace = true, optional = true } smallvec = { workspace = true } strum = { workspace = true } @@ -294,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/src/genesis_config_preset.rs b/runtime/moonriver/src/genesis_config_preset.rs new file mode 100644 index 0000000000..59ba3f10e8 --- /dev/null +++ b/runtime/moonriver/src/genesis_config_preset.rs @@ -0,0 +1,249 @@ +// 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_genesis_builder::PresetId; +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 + ) +} + +/// 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 e8c82f3377..e7bb7519c1 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; diff --git a/scripts/run-benches-for-runtime.sh b/scripts/run-benches-for-runtime.sh index e94a2d31f6..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,15 +43,17 @@ for PALLET in "${PALLETS[@]}"; do OUTPUT=$( ./target/${profile}/moonbeam benchmark pallet \ - --chain="${runtime}-dev" \ - --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"