Skip to content

Commit

Permalink
Add staking & deposit to Crab & Pangolin (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
jiguantong authored Dec 8, 2022
1 parent 222d968 commit d27513a
Show file tree
Hide file tree
Showing 28 changed files with 373 additions and 387 deletions.
30 changes: 8 additions & 22 deletions Cargo.lock

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

27 changes: 17 additions & 10 deletions node/src/chain_spec/crab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
#![allow(clippy::derive_partial_eq_without_eq)]

// std
use std::{collections::BTreeMap, str::FromStr};
use std::{
collections::BTreeMap,
str::FromStr,
time::{SystemTime, UNIX_EPOCH},
};
// cumulus
use cumulus_primitives_core::ParaId;
// darwinia
Expand Down Expand Up @@ -152,9 +156,11 @@ pub fn genesis_config() -> ChainSpec {
assets: Default::default(),

// Consensus stuff.
collator_selection: CollatorSelectionConfig {
invulnerables: vec![array_bytes::hex_n_into_unchecked(ALITH)],
..Default::default()
staking: StakingConfig {
now: SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_millis(),
elapsed_time: 0,
collator_count: 3,
collators: Vec::new(),
},
session: SessionConfig {
keys: vec![(
Expand Down Expand Up @@ -209,7 +215,7 @@ pub fn config() -> ChainSpec {
}

fn testnet_genesis(
invulnerables: Vec<(AccountId, AuraId)>,
collators: Vec<(AccountId, AuraId)>,
endowed_accounts: Vec<AccountId>,
id: ParaId,
) -> GenesisConfig {
Expand All @@ -227,13 +233,14 @@ fn testnet_genesis(
assets: Default::default(),

// Consensus stuff.
collator_selection: CollatorSelectionConfig {
invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(),
candidacy_bond: UNIT,
..Default::default()
staking: StakingConfig {
now: SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_millis(),
elapsed_time: 0,
collator_count: collators.len() as _,
collators: collators.iter().map(|(a, _)| (a.to_owned(), UNIT)).collect(),
},
session: SessionConfig {
keys: invulnerables
keys: collators
.into_iter()
.map(|(acc, aura)| {
(
Expand Down
27 changes: 17 additions & 10 deletions node/src/chain_spec/pangolin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
#![allow(clippy::derive_partial_eq_without_eq)]

// std
use std::{collections::BTreeMap, str::FromStr};
use std::{
collections::BTreeMap,
str::FromStr,
time::{SystemTime, UNIX_EPOCH},
};
// cumulus
use cumulus_primitives_core::ParaId;
// darwinia
Expand Down Expand Up @@ -152,9 +156,11 @@ pub fn genesis_config() -> ChainSpec {
assets: Default::default(),

// Consensus stuff.
collator_selection: CollatorSelectionConfig {
invulnerables: vec![array_bytes::hex_n_into_unchecked(ALITH)],
..Default::default()
staking: StakingConfig {
now: SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_millis(),
elapsed_time: 0,
collator_count: 3,
collators: Vec::new(),
},
session: SessionConfig {
keys: vec![(
Expand Down Expand Up @@ -204,7 +210,7 @@ pub fn config() -> ChainSpec {
}

fn testnet_genesis(
invulnerables: Vec<(AccountId, AuraId)>,
collators: Vec<(AccountId, AuraId)>,
endowed_accounts: Vec<AccountId>,
id: ParaId,
) -> GenesisConfig {
Expand All @@ -222,13 +228,14 @@ fn testnet_genesis(
assets: Default::default(),

// Consensus stuff.
collator_selection: CollatorSelectionConfig {
invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(),
candidacy_bond: UNIT,
..Default::default()
staking: StakingConfig {
now: SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_millis(),
elapsed_time: 0,
collator_count: collators.len() as _,
collators: collators.iter().map(|(a, _)| (a.to_owned(), UNIT)).collect(),
},
session: SessionConfig {
keys: invulnerables
keys: collators
.into_iter()
.map(|(acc, aura)| {
(
Expand Down
15 changes: 10 additions & 5 deletions runtime/crab/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,21 @@ cumulus-pallet-xcmp-queue = { default-features = false, git = "https://git
cumulus-primitives-core = { default-features = false, git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30" }
cumulus-primitives-timestamp = { default-features = false, git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30" }
cumulus-primitives-utility = { default-features = false, git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30" }
pallet-collator-selection = { default-features = false, git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30" }
parachain-info = { default-features = false, git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30" }
# cumulus optional
cumulus-pallet-session-benchmarking = { optional = true, default-features = false, git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30" }

# darwinia
darwinia-account-migration = { default-features = false, path = "../../pallet/account-migration" }
darwinia-common-runtime = { default-features = false, path = "../common" }
darwinia-deposit = { default-features = false, path = "../../pallet/deposit" }
darwinia-message-transact = { default-features = false, path = "../../pallet/message-transact" }
darwinia-precompile-assets = { default-features = false, path = "../../precompile/assets" }
darwinia-precompile-bls12-381 = { default-features = false, path = "../../precompile/bls12-381" }
darwinia-precompile-deposit = { default-features = false, path = "../../precompile/deposit" }
darwinia-precompile-staking = { default-features = false, path = "../../precompile/staking" }
darwinia-precompile-state-storage = { default-features = false, path = "../../precompile/state-storage" }
darwinia-staking = { default-features = false, path = "../../pallet/staking" }
dc-primitives = { default-features = false, path = "../../core/primitives" }

# darwinia-messages-substrate
Expand All @@ -68,7 +71,7 @@ pallet-evm-precompile-modexp = { default-features = false, git = "https://gith
pallet-evm-precompile-simple = { default-features = false, git = "https://github.com/paritytech/frontier", branch = "polkadot-v0.9.30" }

# moonbeam
precompile-utils = { default-features = false, git = "https://github.com/darwinia-network/moonbeam", branch = "polkadot-v0.9.30"}
precompile-utils = { default-features = false, git = "https://github.com/darwinia-network/moonbeam", branch = "polkadot-v0.9.30" }
xcm-primitives = { default-features = false, git = "https://github.com/darwinia-network/moonbeam", branch = "polkadot-v0.9.30" }

# polkadot
Expand Down Expand Up @@ -125,6 +128,7 @@ frame-try-runtime = { optional = true, default-features = false, git = "

[features]
default = ["std"]
production = []
std = [
# crates.io
"codec/std",
Expand All @@ -139,18 +143,21 @@ std = [
"cumulus-primitives-core/std",
"cumulus-primitives-timestamp/std",
"cumulus-primitives-utility/std",
"pallet-collator-selection/std",
"parachain-info/std",
# cumulus optional
"cumulus-pallet-session-benchmarking?/std",

# darwinia
"darwinia-account-migration/std",
"darwinia-common-runtime/std",
"darwinia-deposit/std",
"darwinia-message-transact/std",
"darwinia-precompile-assets/std",
"darwinia-precompile-bls12-381/std",
"darwinia-precompile-staking/std",
"darwinia-precompile-deposit/std",
"darwinia-precompile-state-storage/std",
"darwinia-staking/std",
"dc-primitives/std",

# darwinia-messages-substrate
Expand Down Expand Up @@ -239,7 +246,6 @@ runtime-benchmarks = [
"array-bytes",

# cumulus
"pallet-collator-selection/runtime-benchmarks",
"cumulus-pallet-parachain-system/runtime-benchmarks",
"cumulus-pallet-xcmp-queue/runtime-benchmarks",
# cumulus optional
Expand Down Expand Up @@ -297,7 +303,6 @@ try-runtime = [
"cumulus-pallet-parachain-system/try-runtime",
"cumulus-pallet-xcm/try-runtime",
"cumulus-pallet-xcmp-queue/try-runtime",
"pallet-collator-selection/try-runtime",
"parachain-info/try-runtime",

# frontier
Expand Down
7 changes: 3 additions & 4 deletions runtime/crab/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases;
// darwinia
use dc_primitives::*;
// polkadot
use xcm::latest::prelude::BodyId;
use xcm_executor::XcmExecutor;
// substrate
use frame_support::{
Expand All @@ -50,7 +49,6 @@ use frame_support::{
ConstantMultiplier, Weight, WeightToFeeCoefficient, WeightToFeeCoefficients,
WeightToFeePolynomial,
},
PalletId,
};
use frame_system::EnsureRoot;
use sp_core::{crypto::KeyTypeId, OpaqueMetadata, H160, H256, U256};
Expand Down Expand Up @@ -276,11 +274,12 @@ frame_support::construct_runtime! {
Balances: pallet_balances = 5,
TransactionPayment: pallet_transaction_payment = 6,
Assets: pallet_assets = 34,
AccountMigration: darwinia_account_migration = 40,
Deposit: darwinia_deposit = 40,
AccountMigration: darwinia_account_migration = 41,

// Consensus stuff.
Authorship: pallet_authorship = 7,
CollatorSelection: pallet_collator_selection = 8,
Staking: darwinia_staking = 8,
Session: pallet_session = 9,
Aura: pallet_aura = 10,
AuraExt: cumulus_pallet_aura_ext = 11,
Expand Down
5 changes: 5 additions & 0 deletions runtime/crab/src/pallets/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
// darwinia
use crate::*;

/// List of the assets existed in this runtime.
pub enum AssetIds {
CKton = 1026,
}

impl pallet_assets::Config for Runtime {
type ApprovalDeposit = ConstU128<0>;
type AssetAccountDeposit = ConstU128<0>;
Expand Down
2 changes: 1 addition & 1 deletion runtime/crab/src/pallets/authorship.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use crate::*;

impl pallet_authorship::Config for Runtime {
type EventHandler = (CollatorSelection,);
type EventHandler = (Staking,);
type FilterUncle = ();
type FindAuthor = pallet_session::FindAccountFromAuthorIndex<Self, Aura>;
type UncleGenerations = ConstU32<0>;
Expand Down
43 changes: 0 additions & 43 deletions runtime/crab/src/pallets/collator_selection.rs

This file was deleted.

Loading

0 comments on commit d27513a

Please sign in to comment.