Skip to content

Commit

Permalink
✨ Paseo config (#317)
Browse files Browse the repository at this point in the history
## What?
- Add paseo chain spec
- Refactor all chain specs

## Why?
- To start our paseo testnet
- To avoid duplicating code and improve readability

## How?
- Split chain specs into files depending on their relay chain
- Remove unused live chain specs, keep the json files at ./chain-specs

## Testing?
- Run with zombienet each chain spec and check if we produce blocks
  • Loading branch information
JuaniRios committed Jun 21, 2024
1 parent 86996b7 commit 36378a0
Show file tree
Hide file tree
Showing 35 changed files with 1,035 additions and 824 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions chain-specs/paseo/polimec-paseo.genesis.state
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0x0000000000000000000000000000000000000000000000000000000000000000003e577f4d515d83e76679dee1ef5f4bb909dfdf89a2c706996ff1bedcfa3d405903170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c11131400
1 change: 1 addition & 0 deletions chain-specs/paseo/polimec-paseo.genesis.wasm

Large diffs are not rendered by default.

248 changes: 248 additions & 0 deletions chain-specs/paseo/polimec-paseo.spec.plain.json

Large diffs are not rendered by default.

132 changes: 132 additions & 0 deletions chain-specs/paseo/polimec-paseo.spec.raw.json

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions nodes/parachain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ cumulus-client-consensus-proposer.workspace = true
cumulus-client-service.workspace = true
cumulus-primitives-core.workspace = true
cumulus-relay-chain-interface.workspace = true
itertools.workspace = true

[build-dependencies]
substrate-build-script-utils.workspace = true
Expand Down
5 changes: 3 additions & 2 deletions nodes/parachain/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ use serde::{Deserialize, Serialize};
use sp_core::{Pair, Public};
use sp_runtime::traits::{IdentifyAccount, Verify};

pub mod polimec;
pub mod politest;
pub mod common;
pub mod polimec_paseo;
pub mod polimec_rococo;

const DEFAULT_PARA_ID: ParaId = LOWEST_PUBLIC_ID;

Expand Down
183 changes: 183 additions & 0 deletions nodes/parachain/src/chain_spec/common.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
use crate::chain_spec::{get_account_id_from_seed, Extensions};
use cumulus_primitives_core::ParaId;
use frame_support::traits::fungible::Inspect;
#[cfg(not(feature = "runtime-benchmarks"))]
use itertools::Itertools;
#[cfg(not(feature = "runtime-benchmarks"))]
use polimec_runtime::MinCandidateStk;
use polimec_runtime::{
pallet_parachain_staking,
pallet_parachain_staking::{
inflation::{perbill_annual_to_perbill_round, BLOCKS_PER_YEAR},
InflationInfo, Range,
},
AccountId, AuraId as AuthorityId, Balance, OracleProvidersMembershipConfig, Runtime, RuntimeGenesisConfig, PLMC,
};
use sp_core::{crypto::UncheckedInto, sr25519};
use sp_runtime::{traits::AccountIdConversion, Perbill, Percent};
pub type ChainSpec = sc_service::GenericChainSpec<RuntimeGenesisConfig, Extensions>;

/// The default XCM version to set in genesis config.
pub const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION;
pub const COLLATOR_COMMISSION: Perbill = Perbill::from_percent(10);
pub const PARACHAIN_BOND_RESERVE_PERCENT: Percent = Percent::from_percent(0);
pub const BLOCKS_PER_ROUND: u32 = 2 * 10;
pub const NUM_SELECTED_CANDIDATES: u32 = 5;

pub fn polimec_inflation_config() -> InflationInfo<Balance> {
fn to_round_inflation(annual: Range<Perbill>) -> Range<Perbill> {
perbill_annual_to_perbill_round(
annual,
// rounds per year
BLOCKS_PER_YEAR / BLOCKS_PER_ROUND,
)
}

let annual =
Range { min: Perbill::from_percent(2), ideal: Perbill::from_percent(3), max: Perbill::from_percent(3) };

InflationInfo {
// staking expectations
expect: Range { min: 100_000 * PLMC, ideal: 200_000 * PLMC, max: 500_000 * PLMC },
// annual inflation
annual,
round: to_round_inflation(annual),
}
}

pub fn get_polimec_session_keys(keys: AuthorityId) -> polimec_runtime::SessionKeys {
polimec_runtime::SessionKeys { aura: keys }
}

pub fn alice() -> polimec_runtime::AccountId {
get_account_id_from_seed::<sr25519::Public>("Alice")
}
pub fn bob() -> polimec_runtime::AccountId {
get_account_id_from_seed::<sr25519::Public>("Bob")
}
pub fn charlie() -> polimec_runtime::AccountId {
get_account_id_from_seed::<sr25519::Public>("Charlie")
}
pub fn dave() -> polimec_runtime::AccountId {
get_account_id_from_seed::<sr25519::Public>("Dave")
}
pub fn eve() -> polimec_runtime::AccountId {
get_account_id_from_seed::<sr25519::Public>("Eve")
}

pub struct GenesisConfigParams {
pub stakers: Vec<AccountId>,
pub council_members: Vec<AccountId>,
pub technical_committee_members: Vec<AccountId>,
pub oracle_members: Vec<AccountId>,
// Do not include system accounts or the funding asset owner.
pub endowed_accounts: Vec<(AccountId, Balance)>,
pub funding_assets_owner: AccountId,
pub id: ParaId,
}
pub fn genesis_config(genesis_config_params: GenesisConfigParams) -> serde_json::Value {
let GenesisConfigParams {
stakers,
council_members,
technical_committee_members,
oracle_members,
mut endowed_accounts,
funding_assets_owner,
id,
} = genesis_config_params;

let system_accounts = vec![
(
<Runtime as pallet_funding::Config>::ProtocolGrowthTreasury::get(),
<Runtime as pallet_funding::Config>::NativeCurrency::minimum_balance(),
),
(
<Runtime as pallet_funding::Config>::ContributionTreasury::get(),
<Runtime as pallet_funding::Config>::NativeCurrency::minimum_balance(),
),
// Need this to have enough for staking rewards
(<Runtime as pallet_parachain_staking::Config>::PayMaster::get(), 10_000_000 * PLMC),
];
endowed_accounts.append(&mut system_accounts.clone());

#[cfg(not(feature = "runtime-benchmarks"))]
let staking_candidates = stakers.clone().into_iter().map(|account| (account, MinCandidateStk::get())).collect_vec();
#[cfg(feature = "runtime-benchmarks")]
let staking_candidates: Vec<(AccountId, Balance)> = vec![];

let usdt_id = pallet_funding::types::AcceptedFundingAsset::USDT.to_assethub_id();
let usdc_id = pallet_funding::types::AcceptedFundingAsset::USDC.to_assethub_id();
let dot_id = pallet_funding::types::AcceptedFundingAsset::DOT.to_assethub_id();

serde_json::json!({
"balances": {
"balances": endowed_accounts.clone()
},
"parachainInfo": {
"parachainId": id
},
"foreignAssets": {
"assets": vec![(
pallet_funding::types::AcceptedFundingAsset::USDT.to_assethub_id(),
&AccountIdConversion::<AccountId>::into_account_truncating(&<Runtime as pallet_funding::Config>::PalletId::get()),
true,
70000,
),
(
pallet_funding::types::AcceptedFundingAsset::USDC.to_assethub_id(),
&AccountIdConversion::<AccountId>::into_account_truncating(&<Runtime as pallet_funding::Config>::PalletId::get()),
true,
70000,
),
(
pallet_funding::types::AcceptedFundingAsset::DOT.to_assethub_id(),
&AccountIdConversion::<AccountId>::into_account_truncating(&<Runtime as pallet_funding::Config>::PalletId::get()),
true,
70000,
)],
// (id, name, symbol, decimals)
"metadata": vec![
(usdt_id, b"Local USDT", b"USDT", 6),
(usdc_id, b"Local USDC", b"USDC", 6),
(dot_id, b"Local DOT ", b"DOT ", 10)
],
// (id, account_id, amount)
"accounts": vec![
(usdt_id, funding_assets_owner.clone(), 1000000000000u64),
(usdc_id, funding_assets_owner.clone(), 1000000000000u64),
(dot_id, funding_assets_owner.clone(), 1000000000000u64)
],
},
"parachainStaking": {
"candidates": staking_candidates,
"inflationConfig": polimec_inflation_config(),
"delegations": [],
"collatorCommission": COLLATOR_COMMISSION,
"parachainBondReservePercent": PARACHAIN_BOND_RESERVE_PERCENT,
"blocksPerRound": BLOCKS_PER_ROUND,
"numSelectedCandidates": NUM_SELECTED_CANDIDATES
},
"session": {
"keys": stakers.iter().map(|account| {
(
account.clone(),
account.clone(),
get_polimec_session_keys(Into::<[u8; 32]>::into(account.clone()).unchecked_into())
)
}).collect::<Vec<_>>()
},
"polkadotXcm": {
"safeXcmVersion": SAFE_XCM_VERSION
},
"oracleProvidersMembership": OracleProvidersMembershipConfig {
members: oracle_members.try_into().unwrap(),
phantom: Default::default(),
},
"council": {
"members": council_members
},
"technicalCommittee": {
"members": technical_committee_members
},
})
}
Loading

0 comments on commit 36378a0

Please sign in to comment.