Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add genesis config presets to runtime #3138

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b3b4509
refactor: :recycle: update deprecated options in command `moonbeam be…
manuelmauro Jan 17, 2025
aeecd0d
refactor: :recycle: update deprecated options in both invocations of …
manuelmauro Jan 17, 2025
52436cb
feat: :sparkles: add default preset for RuntimeGenesisConfig
manuelmauro Jan 21, 2025
1c4e1d0
Revert "feat: :sparkles: add default preset for RuntimeGenesisConfig"
manuelmauro Jan 21, 2025
31d8740
feat: :sparkles: add genesis builder dummy development preset
manuelmauro Jan 21, 2025
94bc298
refactor: :recycle: implement GenesisBuilder within each runtime
manuelmauro Jan 21, 2025
8a9da17
Merge branch 'master' into manuel/update-deprecation-in-benchmarks-sc…
manuelmauro Jan 22, 2025
dc562fa
refactor: :recycle: move moonbase runtime test config to runtime
manuelmauro Jan 22, 2025
1b73386
refactor: :art: improve structure
manuelmauro Jan 22, 2025
c5170a3
refactor: :recycle: move moonbeam runtime test config to runtime
manuelmauro Jan 22, 2025
ba403b4
refactor: :recycle: move moonriver runtime test config to runtime
manuelmauro Jan 22, 2025
0236acf
fix: :fire: remove unused dep
manuelmauro Jan 22, 2025
57cea86
chore: :page_facing_up: add copyright
manuelmauro Jan 23, 2025
a12ff6e
refactor: :fire: complete move of testnet_genesis functions to runtime
manuelmauro Jan 23, 2025
3e42e86
refactor: :coffin: remove dead functions *_inflation_config
manuelmauro Jan 23, 2025
3d0900c
refactor: :recycle: add get_preset and preset_names functions
manuelmauro Jan 23, 2025
b23c7e0
build: :sparkles:
manuelmauro Jan 23, 2025
e61473f
refactor: :recycle: correctly use with_genesis_config_preset_name in …
manuelmauro Jan 23, 2025
6ef78e3
refactor: :recycle: use with_genesis_config_preset_name in test_spec
manuelmauro Jan 23, 2025
570c6af
refactor: :fire: remove serde_json feature
manuelmauro Jan 23, 2025
34c3c15
fix json serialization of GenesisConfig in xcm-transactor
RomarQ Jan 23, 2025
f310990
fix serde_json dependendency in no_std environemnt
RomarQ Jan 23, 2025
bc92fbd
simplify code
RomarQ Jan 23, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

160 changes: 1 addition & 159 deletions node/service/src/chain_spec/moonbase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Extensions>;
Expand Down Expand Up @@ -167,156 +159,6 @@ pub fn get_chain_spec(para_id: ParaId) -> ChainSpec {
.build()
RomarQ marked this conversation as resolved.
Show resolved Hide resolved
}

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<Balance> {
fn to_round_inflation(annual: Range<Perbill>) -> Range<Perbill> {
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<AccountId>,
open_tech_committee_members: Vec<AccountId>,
candidates: Vec<(AccountId, NimbusId, Balance)>,
delegations: Vec<(AccountId, AccountId, Balance, Percent)>,
endowed_accounts: Vec<AccountId>,
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::*;
Expand Down
150 changes: 3 additions & 147 deletions node/service/src/chain_spec/moonbeam.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Extensions>;
Expand Down Expand Up @@ -156,145 +151,6 @@ 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<Balance> {
fn to_round_inflation(annual: Range<Perbill>) -> Range<Perbill> {
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<AccountId>,
open_tech_committee_members: Vec<AccountId>,
candidates: Vec<(AccountId, NimbusId, Balance)>,
delegations: Vec<(AccountId, AccountId, Balance, Percent)>,
endowed_accounts: Vec<AccountId>,
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::*;
Expand Down
Loading
Loading