Skip to content

Commit

Permalink
Some adjustment (#120)
Browse files Browse the repository at this point in the history
* Fast runtime

* Valid genesis exposure

* Assets genesis
  • Loading branch information
AurevoirXavier committed Dec 9, 2022
1 parent d27513a commit f2ce40c
Show file tree
Hide file tree
Showing 15 changed files with 59 additions and 44 deletions.
4 changes: 3 additions & 1 deletion node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ substrate-prometheus-endpoint = { git = "https://github.com/paritytech/substrat
try-runtime-cli = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" }

[features]
default = ["darwinia-runtime/production"]
default = []

fast-runtime = []

runtime-benchmarks = [
# darwinia
Expand Down
6 changes: 5 additions & 1 deletion node/src/chain_spec/crab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,11 @@ fn testnet_genesis(
balances: endowed_accounts.iter().cloned().map(|k| (k, 100_000_000 * UNIT)).collect(),
},
transaction_payment: Default::default(),
assets: Default::default(),
assets: AssetsConfig {
assets: vec![(AssetIds::CKton as _, array_bytes::hex_n_into_unchecked(ALITH), true, 1)],
metadata: vec![(AssetIds::CKton as _, b"Crab Commitment Token".to_vec(), b"CKTON".to_vec(), 18)],
..Default::default()
},

// Consensus stuff.
staking: StakingConfig {
Expand Down
6 changes: 5 additions & 1 deletion node/src/chain_spec/darwinia.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,11 @@ fn testnet_genesis(
balances: endowed_accounts.iter().cloned().map(|k| (k, 100_000_000 * UNIT)).collect(),
},
transaction_payment: Default::default(),
assets: Default::default(),
assets: AssetsConfig {
assets: vec![(AssetIds::Kton as _, array_bytes::hex_n_into_unchecked(ALITH), true, 1)],
metadata: vec![(AssetIds::Kton as _, b"Darwinia Commitment Token".to_vec(), b"KTON".to_vec(), 18)],
..Default::default()
},

// Consensus stuff.
staking: StakingConfig {
Expand Down
6 changes: 5 additions & 1 deletion node/src/chain_spec/pangolin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,11 @@ pub fn genesis_config() -> ChainSpec {
// Monetary stuff.
balances: Default::default(),
transaction_payment: Default::default(),
assets: Default::default(),
assets: AssetsConfig {
assets: vec![(AssetIds::PKton as _, array_bytes::hex_n_into_unchecked(ALITH), true, 1)],
metadata: vec![(AssetIds::PKton as _, b"Pangolin Commitment Token".to_vec(), b"PKTON".to_vec(), 18)],
..Default::default()
},

// Consensus stuff.
staking: StakingConfig {
Expand Down
11 changes: 7 additions & 4 deletions pallet/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,13 @@ pub mod pallet {
<ElapsedTime<T>>::put(self.elapsed_time);
<CollatorCount<T>>::put(self.collator_count);

self.collators.iter().cloned().for_each(|(who, stake)| {
<Pallet<T>>::stake(RawOrigin::Signed(who.clone()).into(), stake, 0, Vec::new())
.unwrap();
<Pallet<T>>::collect(RawOrigin::Signed(who).into(), Default::default()).unwrap();
self.collators.iter().for_each(|(who, stake)| {
<Pallet<T>>::stake(RawOrigin::Signed(who.to_owned()).into(), *stake, 0, Vec::new())
.expect("[pallet::staking] 0, genesis must be built; qed");
<Pallet<T>>::collect(RawOrigin::Signed(who.to_owned()).into(), Default::default())
.expect("[pallet::staking] 1, genesis must be built; qed");
<Pallet<T>>::nominate(RawOrigin::Signed(who.to_owned()).into(), who.to_owned())
.expect("[pallet::staking] 2, genesis must be built; qed");
});
}
}
Expand Down
10 changes: 10 additions & 0 deletions runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,13 @@ pub mod xcm_configs;
pub use bp_darwinia_core as bp_crab;
pub use bp_darwinia_core as bp_darwinia;
pub use bp_darwinia_core as bp_pangolin;

#[macro_export]
macro_rules! fast_runtime_or_not {
($name:ident, $development_type:ty, $production_type:ty) => {
#[cfg(feature = "fast-runtime")]
type $name = $development_type;
#[cfg(not(feature = "fast-runtime"))]
type $name = $production_type;
};
}
3 changes: 2 additions & 1 deletion runtime/crab/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ frame-try-runtime = { optional = true, default-features = false, git = "

[features]
default = ["std"]
production = []
std = [
# crates.io
"codec/std",
Expand Down Expand Up @@ -241,6 +240,8 @@ std = [

]

fast-runtime = []

runtime-benchmarks = [
# crates.io
"array-bytes",
Expand Down
13 changes: 3 additions & 10 deletions runtime/crab/src/pallets/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,9 @@ sp_runtime::impl_opaque_keys! {
}
}

#[cfg(feature = "production")]
frame_support::parameter_types! {
pub const Period: u32 = 6 * HOURS;
pub const Offset: u32 = 0;
}
#[cfg(not(feature = "production"))]
frame_support::parameter_types! {
pub const Period: u32 = 2 * MINUTES;
pub const Offset: u32 = 0;
}
fast_runtime_or_not!(Period, ConstU32<{ 2 * MINUTES }>, ConstU32<{ 6 * HOURS }>);

type Offset = ConstU32<0>;

impl pallet_session::Config for Runtime {
type Keys = SessionKeys;
Expand Down
4 changes: 3 additions & 1 deletion runtime/crab/src/pallets/staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
// darwinia
use crate::*;

fast_runtime_or_not!(MinStakingDuration, ConstU32<MINUTES>, ConstU32<{ 14 * DAYS }>);

pub enum CrabStaking {}
impl darwinia_staking::Stake for CrabStaking {
type AccountId = AccountId;
Expand Down Expand Up @@ -75,7 +77,7 @@ impl darwinia_staking::Config for Runtime {
type Kton = CKtonStaking;
type MaxDeposits = ConstU32<16>;
type MaxUnstakings = ConstU32<16>;
type MinStakingDuration = ConstU32<{ 14 * DAYS }>;
type MinStakingDuration = MinStakingDuration;
type PayoutFraction = PayoutFraction;
type RewardRemainder = Treasury;
type Ring = CrabStaking;
Expand Down
3 changes: 2 additions & 1 deletion runtime/darwinia/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ frame-try-runtime = { optional = true, default-features = false, git = "

[features]
default = ["std"]
production = []
std = [
# crates.io
"codec/std",
Expand Down Expand Up @@ -241,6 +240,8 @@ std = [

]

fast-runtime = []

runtime-benchmarks = [
# crates.io
"array-bytes",
Expand Down
13 changes: 3 additions & 10 deletions runtime/darwinia/src/pallets/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,9 @@ sp_runtime::impl_opaque_keys! {
}
}

#[cfg(feature = "production")]
frame_support::parameter_types! {
pub const Period: u32 = 6 * HOURS;
pub const Offset: u32 = 0;
}
#[cfg(not(feature = "production"))]
frame_support::parameter_types! {
pub const Period: u32 = 2 * MINUTES;
pub const Offset: u32 = 0;
}
fast_runtime_or_not!(Period, ConstU32<{ 2 * MINUTES }>, ConstU32<{ 6 * HOURS }>);

type Offset = ConstU32<0>;

impl pallet_session::Config for Runtime {
type Keys = SessionKeys;
Expand Down
4 changes: 3 additions & 1 deletion runtime/darwinia/src/pallets/staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
// darwinia
use crate::*;

fast_runtime_or_not!(MinStakingDuration, ConstU32<MINUTES>, ConstU32<{ 14 * DAYS }>);

pub enum RingStaking {}
impl darwinia_staking::Stake for RingStaking {
type AccountId = AccountId;
Expand Down Expand Up @@ -75,7 +77,7 @@ impl darwinia_staking::Config for Runtime {
type Kton = KtonStaking;
type MaxDeposits = ConstU32<16>;
type MaxUnstakings = ConstU32<16>;
type MinStakingDuration = ConstU32<{ 14 * DAYS }>;
type MinStakingDuration = MinStakingDuration;
type PayoutFraction = PayoutFraction;
type RewardRemainder = Treasury;
type Ring = RingStaking;
Expand Down
3 changes: 2 additions & 1 deletion runtime/pangolin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ frame-try-runtime = { optional = true, default-features = false, git = "

[features]
default = ["std"]
production = []
std = [
# crates.io
"codec/std",
Expand Down Expand Up @@ -296,6 +295,8 @@ runtime-benchmarks = [
"frame-system-benchmarking/runtime-benchmarks",
]

fast-runtime = []

try-runtime = [
# cumulus
"cumulus-pallet-aura-ext/try-runtime",
Expand Down
13 changes: 3 additions & 10 deletions runtime/pangolin/src/pallets/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,9 @@ sp_runtime::impl_opaque_keys! {
}
}

#[cfg(feature = "production")]
frame_support::parameter_types! {
pub const Period: u32 = 6 * HOURS;
pub const Offset: u32 = 0;
}
#[cfg(not(feature = "production"))]
frame_support::parameter_types! {
pub const Period: u32 = 2 * MINUTES;
pub const Offset: u32 = 0;
}
fast_runtime_or_not!(Period, ConstU32<{ 2 * MINUTES }>, ConstU32<{ 6 * HOURS }>);

type Offset = ConstU32<0>;

impl pallet_session::Config for Runtime {
type Keys = SessionKeys;
Expand Down
4 changes: 3 additions & 1 deletion runtime/pangolin/src/pallets/staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
// darwinia
use crate::*;

fast_runtime_or_not!(MinStakingDuration, ConstU32<MINUTES>, ConstU32<{ 14 * DAYS }>);

pub enum PRingStaking {}
impl darwinia_staking::Stake for PRingStaking {
type AccountId = AccountId;
Expand Down Expand Up @@ -75,7 +77,7 @@ impl darwinia_staking::Config for Runtime {
type Kton = PKtonStaking;
type MaxDeposits = ConstU32<16>;
type MaxUnstakings = ConstU32<16>;
type MinStakingDuration = ConstU32<{ 14 * DAYS }>;
type MinStakingDuration = MinStakingDuration;
type PayoutFraction = PayoutFraction;
type RewardRemainder = Treasury;
type Ring = PRingStaking;
Expand Down

0 comments on commit f2ce40c

Please sign in to comment.