From d27513a21ea223d144479d8a0611fe3ee7daa38f Mon Sep 17 00:00:00 2001 From: Guantong <04637@163.com> Date: Thu, 8 Dec 2022 20:18:16 +0800 Subject: [PATCH] Add staking & deposit to Crab & Pangolin (#112) --- Cargo.lock | 30 ++--- node/src/chain_spec/crab.rs | 27 +++-- node/src/chain_spec/pangolin.rs | 27 +++-- runtime/crab/Cargo.toml | 15 ++- runtime/crab/src/lib.rs | 7 +- runtime/crab/src/pallets/assets.rs | 5 + runtime/crab/src/pallets/authorship.rs | 2 +- .../crab/src/pallets/collator_selection.rs | 43 ------- runtime/crab/src/pallets/deposit.rs | 38 ++++++ runtime/crab/src/pallets/evm.rs | 8 +- runtime/crab/src/pallets/mod.rs | 5 +- runtime/crab/src/pallets/session.rs | 14 ++- runtime/crab/src/pallets/staking.rs | 85 ++++++++++++++ runtime/crab/src/weights/mod.rs | 1 - .../src/weights/pallet_collator_selection.rs | 111 ------------------ runtime/darwinia/src/pallets/mod.rs | 1 + runtime/pangolin/Cargo.toml | 15 ++- runtime/pangolin/src/lib.rs | 10 +- runtime/pangolin/src/pallets/assets.rs | 5 + runtime/pangolin/src/pallets/authorship.rs | 2 +- .../src/pallets/collator_selection.rs | 43 ------- runtime/pangolin/src/pallets/deposit.rs | 38 ++++++ runtime/pangolin/src/pallets/evm.rs | 8 +- runtime/pangolin/src/pallets/mod.rs | 9 +- runtime/pangolin/src/pallets/session.rs | 14 ++- runtime/pangolin/src/pallets/staking.rs | 85 ++++++++++++++ runtime/pangolin/src/weights/mod.rs | 1 - .../src/weights/pallet_collator_selection.rs | 111 ------------------ 28 files changed, 373 insertions(+), 387 deletions(-) delete mode 100644 runtime/crab/src/pallets/collator_selection.rs create mode 100644 runtime/crab/src/pallets/deposit.rs create mode 100644 runtime/crab/src/pallets/staking.rs delete mode 100644 runtime/crab/src/weights/pallet_collator_selection.rs delete mode 100644 runtime/pangolin/src/pallets/collator_selection.rs create mode 100644 runtime/pangolin/src/pallets/deposit.rs create mode 100644 runtime/pangolin/src/pallets/staking.rs delete mode 100644 runtime/pangolin/src/weights/pallet_collator_selection.rs diff --git a/Cargo.lock b/Cargo.lock index 2c24a41c3..ea18262d1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1356,10 +1356,14 @@ dependencies = [ "cumulus-primitives-utility", "darwinia-account-migration", "darwinia-common-runtime", + "darwinia-deposit", "darwinia-message-transact", "darwinia-precompile-assets", "darwinia-precompile-bls12-381", + "darwinia-precompile-deposit", + "darwinia-precompile-staking", "darwinia-precompile-state-storage", + "darwinia-staking", "dc-primitives", "fp-rpc", "fp-self-contained", @@ -1378,7 +1382,6 @@ dependencies = [ "pallet-bridge-dispatch", "pallet-bridge-grandpa", "pallet-bridge-messages", - "pallet-collator-selection", "pallet-collective", "pallet-democracy", "pallet-elections-phragmen", @@ -6552,26 +6555,6 @@ dependencies = [ "sp-std", ] -[[package]] -name = "pallet-collator-selection" -version = "3.0.0" -source = "git+https://github.com/paritytech/cumulus.git?branch=polkadot-v0.9.30#7b1fc0ed107fe42bb7e6a5dfefb586f4c3ae4328" -dependencies = [ - "frame-benchmarking", - "frame-support", - "frame-system", - "log", - "pallet-authorship", - "pallet-session", - "parity-scale-codec", - "rand 0.8.5", - "scale-info", - "serde", - "sp-runtime", - "sp-staking", - "sp-std", -] - [[package]] name = "pallet-collective" version = "4.0.0-dev" @@ -7395,10 +7378,14 @@ dependencies = [ "cumulus-primitives-utility", "darwinia-account-migration", "darwinia-common-runtime", + "darwinia-deposit", "darwinia-message-transact", "darwinia-precompile-assets", "darwinia-precompile-bls12-381", + "darwinia-precompile-deposit", + "darwinia-precompile-staking", "darwinia-precompile-state-storage", + "darwinia-staking", "dc-primitives", "fp-rpc", "fp-self-contained", @@ -7417,7 +7404,6 @@ dependencies = [ "pallet-bridge-dispatch", "pallet-bridge-grandpa", "pallet-bridge-messages", - "pallet-collator-selection", "pallet-collective", "pallet-democracy", "pallet-elections-phragmen", diff --git a/node/src/chain_spec/crab.rs b/node/src/chain_spec/crab.rs index 141cdb634..71165a9ca 100644 --- a/node/src/chain_spec/crab.rs +++ b/node/src/chain_spec/crab.rs @@ -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 @@ -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![( @@ -209,7 +215,7 @@ pub fn config() -> ChainSpec { } fn testnet_genesis( - invulnerables: Vec<(AccountId, AuraId)>, + collators: Vec<(AccountId, AuraId)>, endowed_accounts: Vec, id: ParaId, ) -> GenesisConfig { @@ -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)| { ( diff --git a/node/src/chain_spec/pangolin.rs b/node/src/chain_spec/pangolin.rs index fb43c347e..685500e62 100644 --- a/node/src/chain_spec/pangolin.rs +++ b/node/src/chain_spec/pangolin.rs @@ -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 @@ -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![( @@ -204,7 +210,7 @@ pub fn config() -> ChainSpec { } fn testnet_genesis( - invulnerables: Vec<(AccountId, AuraId)>, + collators: Vec<(AccountId, AuraId)>, endowed_accounts: Vec, id: ParaId, ) -> GenesisConfig { @@ -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)| { ( diff --git a/runtime/crab/Cargo.toml b/runtime/crab/Cargo.toml index a7e214e98..83a6af4b5 100644 --- a/runtime/crab/Cargo.toml +++ b/runtime/crab/Cargo.toml @@ -30,7 +30,6 @@ 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" } @@ -38,10 +37,14 @@ cumulus-pallet-session-benchmarking = { optional = true, default-features = fals # 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 @@ -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 @@ -125,6 +128,7 @@ frame-try-runtime = { optional = true, default-features = false, git = " [features] default = ["std"] +production = [] std = [ # crates.io "codec/std", @@ -139,7 +143,6 @@ 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", @@ -147,10 +150,14 @@ 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 @@ -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 @@ -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 diff --git a/runtime/crab/src/lib.rs b/runtime/crab/src/lib.rs index 9789a29b5..d379aa5b2 100644 --- a/runtime/crab/src/lib.rs +++ b/runtime/crab/src/lib.rs @@ -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::{ @@ -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}; @@ -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, diff --git a/runtime/crab/src/pallets/assets.rs b/runtime/crab/src/pallets/assets.rs index d649ffa49..a456fa09e 100644 --- a/runtime/crab/src/pallets/assets.rs +++ b/runtime/crab/src/pallets/assets.rs @@ -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>; diff --git a/runtime/crab/src/pallets/authorship.rs b/runtime/crab/src/pallets/authorship.rs index eb48e3bdb..d2a61afc7 100644 --- a/runtime/crab/src/pallets/authorship.rs +++ b/runtime/crab/src/pallets/authorship.rs @@ -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; type UncleGenerations = ConstU32<0>; diff --git a/runtime/crab/src/pallets/collator_selection.rs b/runtime/crab/src/pallets/collator_selection.rs deleted file mode 100644 index 511377862..000000000 --- a/runtime/crab/src/pallets/collator_selection.rs +++ /dev/null @@ -1,43 +0,0 @@ -// This file is part of Darwinia. -// -// Copyright (C) 2018-2022 Darwinia Network -// SPDX-License-Identifier: GPL-3.0 -// -// Darwinia 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. -// -// Darwinia 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 Darwinia. If not, see . - -// darwinia -use crate::*; - -// We allow root only to execute privileged collator selection operations. -pub type CollatorSelectionUpdateOrigin = EnsureRoot; -frame_support::parameter_types! { - pub const PotId: PalletId = PalletId(*b"PotStake"); - pub const ExecutiveBody: BodyId = BodyId::Executive; -} - -impl pallet_collator_selection::Config for Runtime { - type Currency = Balances; - // should be a multiple of session or things will get inconsistent - type KickThreshold = Period; - type MaxCandidates = ConstU32<1000>; - type MaxInvulnerables = ConstU32<100>; - type MinCandidates = ConstU32<5>; - type PotId = PotId; - type RuntimeEvent = RuntimeEvent; - type UpdateOrigin = CollatorSelectionUpdateOrigin; - type ValidatorId = ::AccountId; - type ValidatorIdOf = pallet_collator_selection::IdentityCollator; - type ValidatorRegistration = Session; - type WeightInfo = weights::pallet_collator_selection::WeightInfo; -} diff --git a/runtime/crab/src/pallets/deposit.rs b/runtime/crab/src/pallets/deposit.rs new file mode 100644 index 000000000..0ed9b9bfb --- /dev/null +++ b/runtime/crab/src/pallets/deposit.rs @@ -0,0 +1,38 @@ +// This file is part of Darwinia. +// +// Copyright (C) 2018-2022 Darwinia Network +// SPDX-License-Identifier: GPL-3.0 +// +// Darwinia 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. +// +// Darwinia 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 Darwinia. If not, see . + +// darwinia +use crate::*; + +pub enum CKtonMinting {} +impl darwinia_deposit::Minting for CKtonMinting { + type AccountId = AccountId; + + fn mint(beneficiary: &Self::AccountId, amount: Balance) -> sp_runtime::DispatchResult { + Assets::mint(RuntimeOrigin::root(), AssetIds::CKton as AssetId, *beneficiary, amount) + } +} + +impl darwinia_deposit::Config for Runtime { + type Kton = CKtonMinting; + type MaxDeposits = frame_support::traits::ConstU32<16>; + type MinLockingAmount = frame_support::traits::ConstU128; + type Ring = Balances; + type RuntimeEvent = RuntimeEvent; + type UnixTime = Timestamp; +} diff --git a/runtime/crab/src/pallets/evm.rs b/runtime/crab/src/pallets/evm.rs index 278cdca06..06766c029 100644 --- a/runtime/crab/src/pallets/evm.rs +++ b/runtime/crab/src/pallets/evm.rs @@ -90,7 +90,7 @@ where Self(Default::default()) } - pub fn used_addresses() -> [H160; 13] { + pub fn used_addresses() -> [H160; 15] { [ addr(1), addr(2), @@ -104,6 +104,8 @@ where addr(1024), addr(1025), addr(1026), // For KTON asset + addr(1536), + addr(1537), addr(2048), ] } @@ -151,6 +153,10 @@ where handle, )), // [1536, 2048) reserved for other stable precompiles. + a if a == addr(1536) => + Some(>::execute(handle)), + a if a == addr(1537) => + Some(>::execute(handle)), // [2048..) reserved for the experimental precompiles. a if a == addr(2048) => Some(>::execute(handle)), diff --git a/runtime/crab/src/pallets/mod.rs b/runtime/crab/src/pallets/mod.rs index 169c4eff8..a64ad0db0 100644 --- a/runtime/crab/src/pallets/mod.rs +++ b/runtime/crab/src/pallets/mod.rs @@ -40,13 +40,16 @@ mod balances; mod transaction_payment; mod assets; +pub use assets::*; + +mod deposit; mod migrate; // Consensus stuff. mod authorship; -mod collator_selection; +mod staking; mod session; pub use session::*; diff --git a/runtime/crab/src/pallets/session.rs b/runtime/crab/src/pallets/session.rs index 7725500ed..bb36bdc36 100644 --- a/runtime/crab/src/pallets/session.rs +++ b/runtime/crab/src/pallets/session.rs @@ -25,21 +25,27 @@ 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; +} impl pallet_session::Config for Runtime { type Keys = SessionKeys; type NextSessionRotation = pallet_session::PeriodicSessions; type RuntimeEvent = RuntimeEvent; - // Essentially just Aura, but lets be pedantic. + // Essentially just AURA, but lets be pedantic. type SessionHandler = ::KeyTypeIdProviders; - type SessionManager = CollatorSelection; + type SessionManager = Staking; type ShouldEndSession = pallet_session::PeriodicSessions; type ValidatorId = ::AccountId; - // we don't have stash and controller, thus we don't need the convert as well. - type ValidatorIdOf = pallet_collator_selection::IdentityCollator; + // We don't have stash and controller, thus we don't need the convert as well. + type ValidatorIdOf = darwinia_staking::IdentityCollator; type WeightInfo = weights::pallet_session::WeightInfo; } diff --git a/runtime/crab/src/pallets/staking.rs b/runtime/crab/src/pallets/staking.rs new file mode 100644 index 000000000..b705f2502 --- /dev/null +++ b/runtime/crab/src/pallets/staking.rs @@ -0,0 +1,85 @@ +// This file is part of Darwinia. +// +// Copyright (C) 2018-2022 Darwinia Network +// SPDX-License-Identifier: GPL-3.0 +// +// Darwinia 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. +// +// Darwinia 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 Darwinia. If not, see . + +// darwinia +use crate::*; + +pub enum CrabStaking {} +impl darwinia_staking::Stake for CrabStaking { + type AccountId = AccountId; + type Item = Balance; + + fn stake(who: &Self::AccountId, item: Self::Item) -> sp_runtime::DispatchResult { + >::transfer( + who, + &darwinia_staking::account_id(), + item, + frame_support::traits::ExistenceRequirement::KeepAlive, + ) + } + + fn unstake(who: &Self::AccountId, item: Self::Item) -> sp_runtime::DispatchResult { + >::transfer( + &darwinia_staking::account_id(), + who, + item, + frame_support::traits::ExistenceRequirement::AllowDeath, + ) + } +} +pub enum CKtonStaking {} +impl darwinia_staking::Stake for CKtonStaking { + type AccountId = AccountId; + type Item = Balance; + + fn stake(who: &Self::AccountId, item: Self::Item) -> sp_runtime::DispatchResult { + Assets::transfer( + RuntimeOrigin::signed(*who), + AssetIds::CKton as AssetId, + darwinia_staking::account_id(), + item, + ) + } + + fn unstake(who: &Self::AccountId, item: Self::Item) -> sp_runtime::DispatchResult { + Assets::transfer( + RuntimeOrigin::signed(darwinia_staking::account_id()), + AssetIds::CKton as AssetId, + *who, + item, + ) + } +} + +frame_support::parameter_types! { + pub const PayoutFraction: sp_runtime::Perbill = sp_runtime::Perbill::from_percent(20); +} + +impl darwinia_staking::Config for Runtime { + type Deposit = Deposit; + type Kton = CKtonStaking; + type MaxDeposits = ConstU32<16>; + type MaxUnstakings = ConstU32<16>; + type MinStakingDuration = ConstU32<{ 14 * DAYS }>; + type PayoutFraction = PayoutFraction; + type RewardRemainder = Treasury; + type Ring = CrabStaking; + type RingCurrency = Balances; + type RuntimeEvent = RuntimeEvent; + type UnixTime = Timestamp; +} diff --git a/runtime/crab/src/weights/mod.rs b/runtime/crab/src/weights/mod.rs index 74dbfcbbd..5856c3a7f 100644 --- a/runtime/crab/src/weights/mod.rs +++ b/runtime/crab/src/weights/mod.rs @@ -35,6 +35,5 @@ pub use rocksdb_weights::constants::RocksDbWeight; pub mod cumulus_pallet_xcmp_queue; pub mod frame_system; pub mod pallet_balances; -pub mod pallet_collator_selection; pub mod pallet_session; pub mod pallet_timestamp; diff --git a/runtime/crab/src/weights/pallet_collator_selection.rs b/runtime/crab/src/weights/pallet_collator_selection.rs deleted file mode 100644 index affdfcef8..000000000 --- a/runtime/crab/src/weights/pallet_collator_selection.rs +++ /dev/null @@ -1,111 +0,0 @@ -// This file is part of Darwinia. -// -// Copyright (C) 2018-2022 Darwinia Network -// SPDX-License-Identifier: GPL-3.0 -// -// Darwinia 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. -// -// Darwinia 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 Darwinia. If not, see . - -//! Autogenerated weights for `pallet_collator_selection` -//! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-11-09, STEPS: `2`, REPEAT: 1, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! HOSTNAME: `inv.cafe`, CPU: `AMD Ryzen 9 5950X 16-Core Processor` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("local"), DB CACHE: 1024 - -// Executed Command: -// target/release/darwinia -// benchmark -// pallet -// --header -// .maintain/license-header -// --execution -// wasm -// --heap-pages -// 4096 -// --chain -// local -// --output -// runtime/src/weights -// --extrinsic -// set_invulnerables,set_desired_candidates,set_candidacy_bond,leave_intent,new_session,note_author -// --pallet -// pallet-collator-selection - -#![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] -#![allow(unused_imports)] - -use frame_support::{traits::Get, weights::Weight}; -use sp_std::marker::PhantomData; - -/// Weight functions for `pallet_collator_selection`. -pub struct WeightInfo(PhantomData); -impl pallet_collator_selection::WeightInfo for WeightInfo { - // Storage: Session NextKeys (r:1 w:0) - // Storage: CollatorSelection Invulnerables (r:0 w:1) - /// The range of component `b` is `[1, 100]`. - fn set_invulnerables(_b: u32, ) -> Weight { - Weight::from_ref_time(317_565_000 as u64) - .saturating_add(T::DbWeight::get().reads(100 as u64)) - .saturating_add(T::DbWeight::get().writes(1 as u64)) - } - // Storage: CollatorSelection DesiredCandidates (r:0 w:1) - fn set_desired_candidates() -> Weight { - Weight::from_ref_time(19_951_000 as u64) - .saturating_add(T::DbWeight::get().writes(1 as u64)) - } - // Storage: CollatorSelection CandidacyBond (r:0 w:1) - fn set_candidacy_bond() -> Weight { - Weight::from_ref_time(19_730_000 as u64) - .saturating_add(T::DbWeight::get().writes(1 as u64)) - } - fn register_as_candidate(c: u32) -> Weight { - Weight::from_ref_time(71_196_000 as u64) - // Standard Error: 0 - .saturating_add(Weight::from_ref_time(198_000 as u64).saturating_mul(c as u64)) - .saturating_add(T::DbWeight::get().reads(4 as u64)) - .saturating_add(T::DbWeight::get().writes(2 as u64)) - } - // Storage: CollatorSelection Candidates (r:1 w:1) - // Storage: CollatorSelection LastAuthoredBlock (r:0 w:1) - /// The range of component `c` is `[6, 1000]`. - fn leave_intent(_c: u32, ) -> Weight { - Weight::from_ref_time(181_302_000 as u64) - .saturating_add(T::DbWeight::get().reads(1 as u64)) - .saturating_add(T::DbWeight::get().writes(2 as u64)) - } - // Storage: System Account (r:2 w:2) - // Storage: System BlockWeight (r:1 w:1) - // Storage: CollatorSelection LastAuthoredBlock (r:0 w:1) - fn note_author() -> Weight { - Weight::from_ref_time(43_091_000 as u64) - .saturating_add(T::DbWeight::get().reads(3 as u64)) - .saturating_add(T::DbWeight::get().writes(4 as u64)) - } - // Storage: CollatorSelection Candidates (r:1 w:1) - // Storage: CollatorSelection LastAuthoredBlock (r:1000 w:1) - // Storage: System Account (r:1 w:1) - // Storage: CollatorSelection Invulnerables (r:1 w:0) - // Storage: System BlockWeight (r:1 w:1) - /// The range of component `r` is `[1, 1000]`. - /// The range of component `c` is `[1, 1000]`. - fn new_session(_r: u32, c: u32, ) -> Weight { - Weight::from_ref_time(28_111_000 as u64) - // Standard Error: 39_309 - .saturating_add(Weight::from_ref_time(3_055_761 as u64).saturating_mul(c as u64)) - .saturating_add(T::DbWeight::get().reads(4 as u64)) - .saturating_add(T::DbWeight::get().reads((1 as u64).saturating_mul(c as u64))) - .saturating_add(T::DbWeight::get().writes(1 as u64)) - } -} diff --git a/runtime/darwinia/src/pallets/mod.rs b/runtime/darwinia/src/pallets/mod.rs index d6cdba9f7..a64ad0db0 100644 --- a/runtime/darwinia/src/pallets/mod.rs +++ b/runtime/darwinia/src/pallets/mod.rs @@ -45,6 +45,7 @@ pub use assets::*; mod deposit; mod migrate; + // Consensus stuff. mod authorship; diff --git a/runtime/pangolin/Cargo.toml b/runtime/pangolin/Cargo.toml index 106613408..87a56f151 100644 --- a/runtime/pangolin/Cargo.toml +++ b/runtime/pangolin/Cargo.toml @@ -30,7 +30,6 @@ 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" } @@ -38,10 +37,14 @@ cumulus-pallet-session-benchmarking = { optional = true, default-features = fals # 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 @@ -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 @@ -125,6 +128,7 @@ frame-try-runtime = { optional = true, default-features = false, git = " [features] default = ["std"] +production = [] std = [ # crates.io "codec/std", @@ -139,7 +143,6 @@ 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", @@ -147,10 +150,14 @@ 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 @@ -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 @@ -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 diff --git a/runtime/pangolin/src/lib.rs b/runtime/pangolin/src/lib.rs index 73bb9d614..74406598d 100644 --- a/runtime/pangolin/src/lib.rs +++ b/runtime/pangolin/src/lib.rs @@ -29,6 +29,7 @@ pub use pallets::*; mod weights; +pub use darwinia_common_runtime::*; pub use sp_consensus_aura::sr25519::AuthorityId as AuraId; // cumulus @@ -36,7 +37,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::{ @@ -46,7 +46,6 @@ use frame_support::{ ConstantMultiplier, Weight, WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial, }, - PalletId, }; use frame_system::EnsureRoot; use sp_core::{crypto::KeyTypeId, OpaqueMetadata, H160, H256, U256}; @@ -272,11 +271,12 @@ frame_support::construct_runtime! { Balances: pallet_balances = 5, TransactionPayment: pallet_transaction_payment = 6, Assets: pallet_assets = 34, - AccountMigration: darwinia_account_migration = 36, + 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, @@ -310,7 +310,7 @@ frame_support::construct_runtime! { Ethereum: pallet_ethereum = 31, Evm: pallet_evm = 32, BaseFee: pallet_base_fee = 33, - MessageTransact: darwinia_message_transact = 35, + MessageTransact: darwinia_message_transact = 39, } } diff --git a/runtime/pangolin/src/pallets/assets.rs b/runtime/pangolin/src/pallets/assets.rs index d649ffa49..dde186c4a 100644 --- a/runtime/pangolin/src/pallets/assets.rs +++ b/runtime/pangolin/src/pallets/assets.rs @@ -19,6 +19,11 @@ // darwinia use crate::*; +/// List of the assets existed in this runtime. +pub enum AssetIds { + PKton = 1026, +} + impl pallet_assets::Config for Runtime { type ApprovalDeposit = ConstU128<0>; type AssetAccountDeposit = ConstU128<0>; diff --git a/runtime/pangolin/src/pallets/authorship.rs b/runtime/pangolin/src/pallets/authorship.rs index eb48e3bdb..d2a61afc7 100644 --- a/runtime/pangolin/src/pallets/authorship.rs +++ b/runtime/pangolin/src/pallets/authorship.rs @@ -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; type UncleGenerations = ConstU32<0>; diff --git a/runtime/pangolin/src/pallets/collator_selection.rs b/runtime/pangolin/src/pallets/collator_selection.rs deleted file mode 100644 index 511377862..000000000 --- a/runtime/pangolin/src/pallets/collator_selection.rs +++ /dev/null @@ -1,43 +0,0 @@ -// This file is part of Darwinia. -// -// Copyright (C) 2018-2022 Darwinia Network -// SPDX-License-Identifier: GPL-3.0 -// -// Darwinia 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. -// -// Darwinia 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 Darwinia. If not, see . - -// darwinia -use crate::*; - -// We allow root only to execute privileged collator selection operations. -pub type CollatorSelectionUpdateOrigin = EnsureRoot; -frame_support::parameter_types! { - pub const PotId: PalletId = PalletId(*b"PotStake"); - pub const ExecutiveBody: BodyId = BodyId::Executive; -} - -impl pallet_collator_selection::Config for Runtime { - type Currency = Balances; - // should be a multiple of session or things will get inconsistent - type KickThreshold = Period; - type MaxCandidates = ConstU32<1000>; - type MaxInvulnerables = ConstU32<100>; - type MinCandidates = ConstU32<5>; - type PotId = PotId; - type RuntimeEvent = RuntimeEvent; - type UpdateOrigin = CollatorSelectionUpdateOrigin; - type ValidatorId = ::AccountId; - type ValidatorIdOf = pallet_collator_selection::IdentityCollator; - type ValidatorRegistration = Session; - type WeightInfo = weights::pallet_collator_selection::WeightInfo; -} diff --git a/runtime/pangolin/src/pallets/deposit.rs b/runtime/pangolin/src/pallets/deposit.rs new file mode 100644 index 000000000..023819bc4 --- /dev/null +++ b/runtime/pangolin/src/pallets/deposit.rs @@ -0,0 +1,38 @@ +// This file is part of Darwinia. +// +// Copyright (C) 2018-2022 Darwinia Network +// SPDX-License-Identifier: GPL-3.0 +// +// Darwinia 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. +// +// Darwinia 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 Darwinia. If not, see . + +// darwinia +use crate::*; + +pub enum PKtonMinting {} +impl darwinia_deposit::Minting for PKtonMinting { + type AccountId = AccountId; + + fn mint(beneficiary: &Self::AccountId, amount: Balance) -> sp_runtime::DispatchResult { + Assets::mint(RuntimeOrigin::root(), AssetIds::PKton as AssetId, *beneficiary, amount) + } +} + +impl darwinia_deposit::Config for Runtime { + type Kton = PKtonMinting; + type MaxDeposits = frame_support::traits::ConstU32<16>; + type MinLockingAmount = frame_support::traits::ConstU128; + type Ring = Balances; + type RuntimeEvent = RuntimeEvent; + type UnixTime = Timestamp; +} diff --git a/runtime/pangolin/src/pallets/evm.rs b/runtime/pangolin/src/pallets/evm.rs index 8d7e764e4..051329ca2 100644 --- a/runtime/pangolin/src/pallets/evm.rs +++ b/runtime/pangolin/src/pallets/evm.rs @@ -90,7 +90,7 @@ where Self(Default::default()) } - pub fn used_addresses() -> [H160; 13] { + pub fn used_addresses() -> [H160; 15] { [ addr(1), addr(2), @@ -104,6 +104,8 @@ where addr(1024), addr(1025), addr(1026), // For KTON asset + addr(1536), + addr(1537), addr(2048), ] } @@ -151,6 +153,10 @@ where handle, )), // [1536, 2048) reserved for other stable precompiles. + a if a == addr(1536) => + Some(>::execute(handle)), + a if a == addr(1537) => + Some(>::execute(handle)), // [2048..) reserved for the experimental precompiles. a if a == addr(2048) => Some(>::execute(handle)), diff --git a/runtime/pangolin/src/pallets/mod.rs b/runtime/pangolin/src/pallets/mod.rs index 4ec80c833..8ffa23449 100644 --- a/runtime/pangolin/src/pallets/mod.rs +++ b/runtime/pangolin/src/pallets/mod.rs @@ -25,8 +25,6 @@ mod shared_imports { pub use shared_imports::*; // System stuffs. -mod assets; - mod system; pub use system::*; @@ -41,12 +39,17 @@ mod balances; mod transaction_payment; +mod assets; +pub use assets::*; + +mod deposit; + mod migrate; // Consensus stuff. mod authorship; -mod collator_selection; +mod staking; mod session; pub use session::*; diff --git a/runtime/pangolin/src/pallets/session.rs b/runtime/pangolin/src/pallets/session.rs index 7725500ed..bb36bdc36 100644 --- a/runtime/pangolin/src/pallets/session.rs +++ b/runtime/pangolin/src/pallets/session.rs @@ -25,21 +25,27 @@ 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; +} impl pallet_session::Config for Runtime { type Keys = SessionKeys; type NextSessionRotation = pallet_session::PeriodicSessions; type RuntimeEvent = RuntimeEvent; - // Essentially just Aura, but lets be pedantic. + // Essentially just AURA, but lets be pedantic. type SessionHandler = ::KeyTypeIdProviders; - type SessionManager = CollatorSelection; + type SessionManager = Staking; type ShouldEndSession = pallet_session::PeriodicSessions; type ValidatorId = ::AccountId; - // we don't have stash and controller, thus we don't need the convert as well. - type ValidatorIdOf = pallet_collator_selection::IdentityCollator; + // We don't have stash and controller, thus we don't need the convert as well. + type ValidatorIdOf = darwinia_staking::IdentityCollator; type WeightInfo = weights::pallet_session::WeightInfo; } diff --git a/runtime/pangolin/src/pallets/staking.rs b/runtime/pangolin/src/pallets/staking.rs new file mode 100644 index 000000000..81c9a2f4c --- /dev/null +++ b/runtime/pangolin/src/pallets/staking.rs @@ -0,0 +1,85 @@ +// This file is part of Darwinia. +// +// Copyright (C) 2018-2022 Darwinia Network +// SPDX-License-Identifier: GPL-3.0 +// +// Darwinia 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. +// +// Darwinia 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 Darwinia. If not, see . + +// darwinia +use crate::*; + +pub enum PRingStaking {} +impl darwinia_staking::Stake for PRingStaking { + type AccountId = AccountId; + type Item = Balance; + + fn stake(who: &Self::AccountId, item: Self::Item) -> sp_runtime::DispatchResult { + >::transfer( + who, + &darwinia_staking::account_id(), + item, + frame_support::traits::ExistenceRequirement::KeepAlive, + ) + } + + fn unstake(who: &Self::AccountId, item: Self::Item) -> sp_runtime::DispatchResult { + >::transfer( + &darwinia_staking::account_id(), + who, + item, + frame_support::traits::ExistenceRequirement::AllowDeath, + ) + } +} +pub enum PKtonStaking {} +impl darwinia_staking::Stake for PKtonStaking { + type AccountId = AccountId; + type Item = Balance; + + fn stake(who: &Self::AccountId, item: Self::Item) -> sp_runtime::DispatchResult { + Assets::transfer( + RuntimeOrigin::signed(*who), + AssetIds::PKton as AssetId, + darwinia_staking::account_id(), + item, + ) + } + + fn unstake(who: &Self::AccountId, item: Self::Item) -> sp_runtime::DispatchResult { + Assets::transfer( + RuntimeOrigin::signed(darwinia_staking::account_id()), + AssetIds::PKton as AssetId, + *who, + item, + ) + } +} + +frame_support::parameter_types! { + pub const PayoutFraction: sp_runtime::Perbill = sp_runtime::Perbill::from_percent(20); +} + +impl darwinia_staking::Config for Runtime { + type Deposit = Deposit; + type Kton = PKtonStaking; + type MaxDeposits = ConstU32<16>; + type MaxUnstakings = ConstU32<16>; + type MinStakingDuration = ConstU32<{ 14 * DAYS }>; + type PayoutFraction = PayoutFraction; + type RewardRemainder = Treasury; + type Ring = PRingStaking; + type RingCurrency = Balances; + type RuntimeEvent = RuntimeEvent; + type UnixTime = Timestamp; +} diff --git a/runtime/pangolin/src/weights/mod.rs b/runtime/pangolin/src/weights/mod.rs index 74dbfcbbd..5856c3a7f 100644 --- a/runtime/pangolin/src/weights/mod.rs +++ b/runtime/pangolin/src/weights/mod.rs @@ -35,6 +35,5 @@ pub use rocksdb_weights::constants::RocksDbWeight; pub mod cumulus_pallet_xcmp_queue; pub mod frame_system; pub mod pallet_balances; -pub mod pallet_collator_selection; pub mod pallet_session; pub mod pallet_timestamp; diff --git a/runtime/pangolin/src/weights/pallet_collator_selection.rs b/runtime/pangolin/src/weights/pallet_collator_selection.rs deleted file mode 100644 index affdfcef8..000000000 --- a/runtime/pangolin/src/weights/pallet_collator_selection.rs +++ /dev/null @@ -1,111 +0,0 @@ -// This file is part of Darwinia. -// -// Copyright (C) 2018-2022 Darwinia Network -// SPDX-License-Identifier: GPL-3.0 -// -// Darwinia 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. -// -// Darwinia 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 Darwinia. If not, see . - -//! Autogenerated weights for `pallet_collator_selection` -//! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-11-09, STEPS: `2`, REPEAT: 1, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! HOSTNAME: `inv.cafe`, CPU: `AMD Ryzen 9 5950X 16-Core Processor` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("local"), DB CACHE: 1024 - -// Executed Command: -// target/release/darwinia -// benchmark -// pallet -// --header -// .maintain/license-header -// --execution -// wasm -// --heap-pages -// 4096 -// --chain -// local -// --output -// runtime/src/weights -// --extrinsic -// set_invulnerables,set_desired_candidates,set_candidacy_bond,leave_intent,new_session,note_author -// --pallet -// pallet-collator-selection - -#![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] -#![allow(unused_imports)] - -use frame_support::{traits::Get, weights::Weight}; -use sp_std::marker::PhantomData; - -/// Weight functions for `pallet_collator_selection`. -pub struct WeightInfo(PhantomData); -impl pallet_collator_selection::WeightInfo for WeightInfo { - // Storage: Session NextKeys (r:1 w:0) - // Storage: CollatorSelection Invulnerables (r:0 w:1) - /// The range of component `b` is `[1, 100]`. - fn set_invulnerables(_b: u32, ) -> Weight { - Weight::from_ref_time(317_565_000 as u64) - .saturating_add(T::DbWeight::get().reads(100 as u64)) - .saturating_add(T::DbWeight::get().writes(1 as u64)) - } - // Storage: CollatorSelection DesiredCandidates (r:0 w:1) - fn set_desired_candidates() -> Weight { - Weight::from_ref_time(19_951_000 as u64) - .saturating_add(T::DbWeight::get().writes(1 as u64)) - } - // Storage: CollatorSelection CandidacyBond (r:0 w:1) - fn set_candidacy_bond() -> Weight { - Weight::from_ref_time(19_730_000 as u64) - .saturating_add(T::DbWeight::get().writes(1 as u64)) - } - fn register_as_candidate(c: u32) -> Weight { - Weight::from_ref_time(71_196_000 as u64) - // Standard Error: 0 - .saturating_add(Weight::from_ref_time(198_000 as u64).saturating_mul(c as u64)) - .saturating_add(T::DbWeight::get().reads(4 as u64)) - .saturating_add(T::DbWeight::get().writes(2 as u64)) - } - // Storage: CollatorSelection Candidates (r:1 w:1) - // Storage: CollatorSelection LastAuthoredBlock (r:0 w:1) - /// The range of component `c` is `[6, 1000]`. - fn leave_intent(_c: u32, ) -> Weight { - Weight::from_ref_time(181_302_000 as u64) - .saturating_add(T::DbWeight::get().reads(1 as u64)) - .saturating_add(T::DbWeight::get().writes(2 as u64)) - } - // Storage: System Account (r:2 w:2) - // Storage: System BlockWeight (r:1 w:1) - // Storage: CollatorSelection LastAuthoredBlock (r:0 w:1) - fn note_author() -> Weight { - Weight::from_ref_time(43_091_000 as u64) - .saturating_add(T::DbWeight::get().reads(3 as u64)) - .saturating_add(T::DbWeight::get().writes(4 as u64)) - } - // Storage: CollatorSelection Candidates (r:1 w:1) - // Storage: CollatorSelection LastAuthoredBlock (r:1000 w:1) - // Storage: System Account (r:1 w:1) - // Storage: CollatorSelection Invulnerables (r:1 w:0) - // Storage: System BlockWeight (r:1 w:1) - /// The range of component `r` is `[1, 1000]`. - /// The range of component `c` is `[1, 1000]`. - fn new_session(_r: u32, c: u32, ) -> Weight { - Weight::from_ref_time(28_111_000 as u64) - // Standard Error: 39_309 - .saturating_add(Weight::from_ref_time(3_055_761 as u64).saturating_mul(c as u64)) - .saturating_add(T::DbWeight::get().reads(4 as u64)) - .saturating_add(T::DbWeight::get().reads((1 as u64).saturating_mul(c as u64))) - .saturating_add(T::DbWeight::get().writes(1 as u64)) - } -}