diff --git a/Cargo.lock b/Cargo.lock index 5fd5e33923..12692dad4c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -999,6 +999,25 @@ dependencies = [ "sp-runtime", ] +[[package]] +name = "common-runtime" +version = "2.7.0" +dependencies = [ + "common-primitives", + "darwinia-balances", + "darwinia-support", + "frame-support", + "frame-system", + "max-encoded-len", + "pallet-authorship", + "pallet-transaction-payment", + "pallet-treasury", + "parity-scale-codec", + "sp-runtime", + "sp-std", + "static_assertions", +] + [[package]] name = "concurrent-queue" version = "1.2.2" @@ -6124,14 +6143,6 @@ dependencies = [ "sp-std", ] -[[package]] -name = "pangolin-constants" -version = "2.7.0" -dependencies = [ - "common-primitives", - "sp-staking", -] - [[package]] name = "pangolin-runtime" version = "2.7.0" @@ -6143,6 +6154,7 @@ dependencies = [ "bridge-primitives", "bridge-runtime-common", "common-primitives", + "common-runtime", "darwinia-balances", "darwinia-balances-rpc-runtime-api", "darwinia-bridge-bsc", @@ -6216,10 +6228,6 @@ dependencies = [ "pallet-transaction-payment-rpc-runtime-api", "pallet-treasury", "pallet-utility", - "pangolin-constants", - "pangolin-runtime-system-params", - "pangoro-constants", - "pangoro-runtime-system-params", "parity-scale-codec", "serde", "smallvec 1.7.0", @@ -6245,24 +6253,6 @@ dependencies = [ "to-tron-backing", ] -[[package]] -name = "pangolin-runtime-system-params" -version = "2.7.0" -dependencies = [ - "frame-support", - "frame-system", - "sp-runtime", - "static_assertions", -] - -[[package]] -name = "pangoro-constants" -version = "2.7.0" -dependencies = [ - "common-primitives", - "sp-staking", -] - [[package]] name = "pangoro-runtime" version = "2.7.0" @@ -6275,6 +6265,7 @@ dependencies = [ "bridge-primitives", "bridge-runtime-common", "common-primitives", + "common-runtime", "darwinia-balances", "darwinia-balances-rpc-runtime-api", "darwinia-evm", @@ -6312,12 +6303,10 @@ dependencies = [ "pallet-timestamp", "pallet-transaction-payment", "pallet-transaction-payment-rpc-runtime-api", - "pangolin-constants", - "pangolin-runtime-system-params", - "pangoro-constants", - "pangoro-runtime-system-params", + "pallet-treasury", "parity-scale-codec", "serde", + "smallvec 1.7.0", "sp-api", "sp-authority-discovery", "sp-block-builder", @@ -6338,16 +6327,6 @@ dependencies = [ "to-substrate-backing", ] -[[package]] -name = "pangoro-runtime-system-params" -version = "2.7.0" -dependencies = [ - "frame-support", - "frame-system", - "sp-runtime", - "static_assertions", -] - [[package]] name = "parity-db" version = "0.2.4" diff --git a/Cargo.toml b/Cargo.toml index 2add0a4ffa..8529f2ddbd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,12 +4,9 @@ members = [ "node/primitives/common", "node/primitives/bridge", "node/rpc", + "node/runtime/common", "node/runtime/pangolin", - "node/runtime/pangolin/src/constants", - "node/runtime/pangolin/src/pallets/system/params", "node/runtime/pangoro", - "node/runtime/pangoro/src/constants", - "node/runtime/pangoro/src/pallets/system/params", "node/service", "client/dvm/db", "client/dvm/mapping-sync", diff --git a/node/primitives/common/src/lib.rs b/node/primitives/common/src/lib.rs index e472bee13f..2376d3ac57 100644 --- a/node/primitives/common/src/lib.rs +++ b/node/primitives/common/src/lib.rs @@ -83,3 +83,53 @@ pub type Header = generic::Header; /// Block type. pub type OpaqueBlock = generic::Block; + +/// 1 in u128. +pub const NANO: Balance = 1; +/// 1_000 in u128. +pub const MICRO: Balance = 1_000 * NANO; +/// 1_000_000 in u128. +pub const MILLI: Balance = 1_000 * MICRO; +/// 1_000_000_000 in u128. +pub const COIN: Balance = 1_000 * MILLI; + +/// GWEI for DVM. +pub const GWEI: Balance = 1_000_000_000; + +/// The hard cap of RING. +pub const RING_HARD_CAP: Balance = 10_000_000_000 * COIN; +/// The amount of total power. +pub const TOTAL_POWER: Power = 1_000_000_000; + +/// Deposit calculator for Pangoro. +pub const fn pangoro_deposit(items: u32, bytes: u32) -> Balance { + items as Balance * 20 * MILLI + (bytes as Balance) * 100 * NANO +} +/// Deposit calculator for Pangolin. +pub const fn pangolin_deposit(items: u32, bytes: u32) -> Balance { + items as Balance * 20 * COIN + (bytes as Balance) * 100 * MICRO +} + +/// Block time of Pangoro/Pangolin. +pub const MILLISECS_PER_BLOCK: Moment = 6000; + +/// Minute in Pangoro/Pangolin. +pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber); +/// Hour in Pangoro/Pangolin. +pub const HOURS: BlockNumber = 60 * MINUTES; +/// Day in Pangoro/Pangolin. +pub const DAYS: BlockNumber = 24 * HOURS; +/// Slot duration in Pangoro/Pangolin. +pub const SLOT_DURATION: Moment = MILLISECS_PER_BLOCK; + +/// Session length of Pangolin. +pub const PANGOLIN_BLOCKS_PER_SESSION: BlockNumber = 30 * MINUTES; +/// Era length of Pangolin. +pub const PANGOLIN_SESSIONS_PER_ERA: BlockNumber = 3; +/// Session length of Pangoro. +pub const PANGORO_BLOCKS_PER_SESSION: BlockNumber = 2 * HOURS; +/// Era length of Pangoro. +pub const PANGORO_SESSIONS_PER_ERA: BlockNumber = 3; + +/// 1 in 4 blocks (on average, not counting collisions) will be primary BABE blocks. +pub const PRIMARY_PROBABILITY: (u64, u64) = (1, 4); diff --git a/node/runtime/common/Cargo.toml b/node/runtime/common/Cargo.toml new file mode 100644 index 0000000000..357272bffe --- /dev/null +++ b/node/runtime/common/Cargo.toml @@ -0,0 +1,51 @@ +[package] +authors = ["Darwinia Network "] +description = "DRML node common runtime" +edition = "2021" +homepage = "https://darwinia.network" +license = "GPL-3.0" +name = "common-runtime" +repository = "https://github.com/darwinia-network/darwinia-common" +version = "2.7.0" + +[dependencies] +# crates.io +codec = { package = "parity-scale-codec", version = "2.1", default-features = false } +static_assertions = { version = "1.1" } +# darwinia-network +common-primitives = { default-features = false, path = "../../primitives/common" } +darwinia-balances = { default-features = false, path = "../../../frame/balances" } +darwinia-support = { default-features = false, path = "../../../frame/support" } +# paritytech +frame-support = { default-features = false, git = "https://github.com/darwinia-network/substrate", tag = "darwinia-v0.11.6-1" } +frame-system = { default-features = false, git = "https://github.com/darwinia-network/substrate", tag = "darwinia-v0.11.6-1" } +pallet-authorship = { default-features = false, git = "https://github.com/darwinia-network/substrate", tag = "darwinia-v0.11.6-1" } +pallet-transaction-payment = { default-features = false, git = "https://github.com/darwinia-network/substrate", tag = "darwinia-v0.11.6-1" } +pallet-treasury = { default-features = false, git = "https://github.com/darwinia-network/substrate", tag = "darwinia-v0.11.6-1" } +sp-runtime = { default-features = false, git = "https://github.com/darwinia-network/substrate", tag = "darwinia-v0.11.6-1" } +sp-std = { default-features = false, git = "https://github.com/darwinia-network/substrate", tag = "darwinia-v0.11.6-1" } + +# will be removed in later substrate version +max-encoded-len = { default-features = false, git = "https://github.com/darwinia-network/substrate", tag = "darwinia-v0.11.6-1" } + +[features] +default = ["std"] + +no_std = [] +std = [ + # crates.io + "codec/std", + # darwinia-network + "common-primitives/std", + "darwinia-balances/std", + "darwinia-support/std", + # paritytech + "frame-support/std", + "frame-system/std", + "pallet-authorship/std", + "pallet-transaction-payment/std", + "pallet-treasury/std", + "sp-runtime/std", + "sp-std/std", + "max-encoded-len/std", +] diff --git a/node/runtime/common/src/impls.rs b/node/runtime/common/src/impls.rs new file mode 100644 index 0000000000..13a32a42b8 --- /dev/null +++ b/node/runtime/common/src/impls.rs @@ -0,0 +1,88 @@ +// This file is part of Darwinia. +// +// Copyright (C) 2018-2021 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 . + +//! Auxillary struct/enums for Darwinia runtime. + +// --- crates.io --- +use codec::{Decode, Encode}; +// --- paritytech --- +use frame_support::traits::{Currency, Imbalance, MaxEncodedLen, OnUnbalanced}; +use sp_runtime::RuntimeDebug; +// --- darwinia-network --- +use crate::*; + +darwinia_support::impl_account_data! { + struct AccountData + for + RingInstance, + KtonInstance + where + Balance = common_primitives::Balance + { + // other data + } +} + +/// Logic for the author to get a portion of fees. +pub struct ToAuthor(sp_std::marker::PhantomData); +impl OnUnbalanced> for ToAuthor +where + R: darwinia_balances::Config + pallet_authorship::Config, + ::AccountId: From, + ::AccountId: Into, + ::Event: From>, +{ + fn on_nonzero_unbalanced(amount: NegativeImbalance) { + let numeric_amount = amount.peek(); + let author = >::author(); + >::resolve_creating( + &>::author(), + amount, + ); + >::deposit_event(darwinia_balances::Event::Deposit( + author, + numeric_amount, + )); + } +} + +pub struct DealWithFees(sp_std::marker::PhantomData); +impl OnUnbalanced> for DealWithFees +where + R: darwinia_balances::Config + + pallet_treasury::Config + + pallet_authorship::Config, + pallet_treasury::Pallet: OnUnbalanced>, + ::AccountId: From, + ::AccountId: Into, + ::Event: From>, +{ + fn on_unbalanceds(mut fees_then_tips: impl Iterator>) { + if let Some(fees) = fees_then_tips.next() { + // for fees, 80% to treasury, 20% to author + let mut split = fees.ration(80, 20); + if let Some(tips) = fees_then_tips.next() { + // for tips, if any, 100% to author + tips.merge_into(&mut split.1); + } + use pallet_treasury::Pallet as Treasury; + as OnUnbalanced<_>>::on_unbalanced(split.0); + as OnUnbalanced<_>>::on_unbalanced(split.1); + } + } +} diff --git a/node/runtime/common/src/lib.rs b/node/runtime/common/src/lib.rs new file mode 100644 index 0000000000..6567199b11 --- /dev/null +++ b/node/runtime/common/src/lib.rs @@ -0,0 +1,133 @@ +// This file is part of Darwinia. +// +// Copyright (C) 2018-2021 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 . + +//! Common runtime code for Darwinia and Crab. + +#![cfg_attr(not(feature = "std"), no_std)] + +/// Implementations of some helper traits passed into runtime modules as associated types. +pub mod impls; +pub use impls::*; + +pub use frame_support::weights::constants::{ExtrinsicBaseWeight, RocksDbWeight}; + +pub use darwinia_balances::Instance1 as RingInstance; +pub use darwinia_balances::Instance2 as KtonInstance; + +// --- crates.io --- +use static_assertions::const_assert; +// --- paritytech --- +use frame_support::{ + traits::Currency, + weights::{ + constants::{BlockExecutionWeight, WEIGHT_PER_SECOND}, + DispatchClass, Weight, + }, +}; +use frame_system::limits::{BlockLength, BlockWeights}; +use pallet_transaction_payment::{Multiplier, TargetedFeeAdjustment}; +use sp_runtime::{FixedPointNumber, Perbill, Perquintill}; +// --- darwinia-network --- +use common_primitives::BlockNumber; + +pub type NegativeImbalance = as Currency< + ::AccountId, +>>::NegativeImbalance; + +/// We assume that an on-initialize consumes 2.5% of the weight on average, hence a single extrinsic +/// will not be allowed to consume more than `AvailableBlockRatio - 2.5%`. +pub const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_perthousand(25); +/// We allow `Normal` extrinsics to fill up the block up to 75%, the rest can be used +/// by Operational extrinsics. +const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75); +/// We allow for 2 seconds of compute with a 6 second average block time. +pub const MAXIMUM_BLOCK_WEIGHT: Weight = 2 * WEIGHT_PER_SECOND; +const_assert!(NORMAL_DISPATCH_RATIO.deconstruct() >= AVERAGE_ON_INITIALIZE_RATIO.deconstruct()); + +frame_support::parameter_types! { + pub const BlockHashCountForPangolin: BlockNumber = 256; + pub const BlockHashCountForPangoro: BlockNumber = 2400; + /// The portion of the `NORMAL_DISPATCH_RATIO` that we adjust the fees with. Blocks filled less + /// than this will decrease the weight and more will increase. + pub const TargetBlockFullness: Perquintill = Perquintill::from_percent(25); + /// The adjustment variable of the runtime. Higher values will cause `TargetBlockFullness` to + /// change the fees more rapidly. + pub AdjustmentVariable: Multiplier = Multiplier::saturating_from_rational(3, 100_000); + /// Minimum amount of the multiplier. This value cannot be too low. A test case should ensure + /// that combined with `AdjustmentVariable`, we can recover from the minimum. + /// See `multiplier_can_grow_from_zero`. + pub MinimumMultiplier: Multiplier = Multiplier::saturating_from_rational(1, 1_000_000_000u128); + /// Maximum length of block. Up to 5MB. + pub RuntimeBlockLength: BlockLength = + BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO); + /// Block weights base values and limits. + pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder() + .base_block(BlockExecutionWeight::get()) + .for_class(DispatchClass::all(), |weights| { + weights.base_extrinsic = ExtrinsicBaseWeight::get(); + }) + .for_class(DispatchClass::Normal, |weights| { + weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT); + }) + .for_class(DispatchClass::Operational, |weights| { + weights.max_total = Some(MAXIMUM_BLOCK_WEIGHT); + // Operational transactions have some extra reserved space, so that they + // are included even if block reached `MAXIMUM_BLOCK_WEIGHT`. + weights.reserved = Some( + MAXIMUM_BLOCK_WEIGHT - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT + ); + }) + .avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO) + .build_or_panic(); +} + +frame_support::parameter_types! { + /// A limit for off-chain phragmen unsigned solution submission. + /// + /// We want to keep it as high as possible, but can't risk having it reject, + /// so we always subtract the base block execution weight. + pub OffchainSolutionWeightLimit: Weight = RuntimeBlockWeights::get() + .get(DispatchClass::Normal) + .max_extrinsic + .expect("Normal extrinsics have weight limit configured by default; qed") + .saturating_sub(BlockExecutionWeight::get()); + + /// A limit for off-chain phragmen unsigned solution length. + /// + /// We allow up to 90% of the block's size to be consumed by the solution. + pub OffchainSolutionLengthLimit: u32 = Perbill::from_rational(90_u32, 100) * + *RuntimeBlockLength::get() + .max + .get(DispatchClass::Normal); +} + +/// Parameterized slow adjusting fee updated based on +/// https://w3f-research.readthedocs.io/en/latest/polkadot/Token%20Economics.html#-2.-slow-adjusting-mechanism +pub type SlowAdjustingFeeUpdate = + TargetedFeeAdjustment; + +pub fn max_extrinsic_weight() -> Weight { + RuntimeBlockWeights::get() + .get(DispatchClass::Normal) + .max_extrinsic + .unwrap_or(Weight::MAX) +} + +pub fn max_extrinsic_size() -> u32 { + *RuntimeBlockLength::get().max.get(DispatchClass::Normal) +} diff --git a/node/runtime/pangolin/Cargo.toml b/node/runtime/pangolin/Cargo.toml index 95b883a57b..108312663e 100644 --- a/node/runtime/pangolin/Cargo.toml +++ b/node/runtime/pangolin/Cargo.toml @@ -20,6 +20,7 @@ static_assertions = { version = "1.1" } # darwinia-network bridge-primitives = { default-features = false, path = "../../primitives/bridge" } common-primitives = { default-features = false, path = "../../primitives/common" } +common-runtime = { default-features = false, path = "../common" } darwinia-balances = { default-features = false, path = "../../../frame/balances" } darwinia-balances-rpc-runtime-api = { default-features = false, path = "../../../frame/balances/rpc/runtime-api" } darwinia-bridge-bsc = { default-features = false, path = "../../../frame/bridge/bsc" } @@ -55,10 +56,6 @@ ethereum-primitives = { default-features = false, path = ".. from-ethereum-issuing = { default-features = false, path = "../../../frame/wormhole/issuing/ethereum" } from-substrate-issuing = { default-features = false, path = "../../../frame/wormhole/issuing/s2s" } module-transaction-pause = { default-features = false, path = "../../../frame/transaction-pause" } -pangolin-constants = { default-features = false, path = "src/constants" } -pangolin-runtime-system-params = { default-features = false, path = "src/pallets/system/params" } -pangoro-constants = { default-features = false, path = "../pangoro/src/constants" } -pangoro-runtime-system-params = { default-features = false, path = "../pangoro/src/pallets/system/params" } to-ethereum-backing = { default-features = false, path = "../../../frame/wormhole/backing/ethereum" } to-tron-backing = { default-features = false, path = "../../../frame/wormhole/backing/tron" } # paritytech @@ -135,6 +132,7 @@ std = [ # darwinia-network "bridge-primitives/std", "common-primitives/std", + "common-runtime/std", "darwinia-balances/std", "darwinia-balances-rpc-runtime-api/std", "darwinia-bridge-bsc/std", @@ -170,10 +168,6 @@ std = [ "from-ethereum-issuing/std", "from-substrate-issuing/std", "module-transaction-pause/std", - "pangolin-constants/std", - "pangolin-runtime-system-params/std", - "pangoro-constants/std", - "pangoro-runtime-system-params/std", "to-ethereum-backing/std", "to-tron-backing/std", # paritytech diff --git a/node/runtime/pangolin/src/constants/Cargo.toml b/node/runtime/pangolin/src/constants/Cargo.toml deleted file mode 100644 index f9ec400cb1..0000000000 --- a/node/runtime/pangolin/src/constants/Cargo.toml +++ /dev/null @@ -1,25 +0,0 @@ -[package] -authors = ["Darwinia Network "] -edition = "2021" -homepage = "https://darwinia.network/" -license = "GPL-3.0" -name = "pangolin-constants" -readme = "README.md" -repository = "https://github.com/darwinia-network/darwinia-common/" -version = "2.7.0" - -[dependencies] -# darwinia-network -common-primitives = { default-features = false, path = "../../../../primitives/common" } -# paritytech -sp-staking = { default-features = false, git = "https://github.com/darwinia-network/substrate", tag = "darwinia-v0.11.6-1" } - -[features] -default = ["std"] - -std = [ - # darwinia-network - "common-primitives/std", - # paritytech - "sp-staking/std", -] diff --git a/node/runtime/pangolin/src/constants/src/lib.rs b/node/runtime/pangolin/src/constants/src/lib.rs deleted file mode 100644 index 4764d36a5c..0000000000 --- a/node/runtime/pangolin/src/constants/src/lib.rs +++ /dev/null @@ -1,35 +0,0 @@ -#![cfg_attr(not(feature = "std"), no_std)] - -// --- paritytech --- -use sp_staking::SessionIndex; -// --- darwinia-network --- -use common_primitives::*; - -pub const NANO: Balance = 1; -pub const MICRO: Balance = 1_000 * NANO; -pub const MILLI: Balance = 1_000 * MICRO; -pub const COIN: Balance = 1_000 * MILLI; - -pub const CAP: Balance = 10_000_000_000 * COIN; -pub const TOTAL_POWER: Power = 1_000_000_000; - -// Time is measured by number of blocks. -pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber); -pub const HOURS: BlockNumber = 60 * MINUTES; -pub const DAYS: BlockNumber = 24 * HOURS; - -pub const MILLISECS_PER_BLOCK: Moment = 6000; -// NOTE: Currently it is not possible to change the slot duration after the chain has started. -// Attempting to do so will brick block production. -pub const SLOT_DURATION: Moment = MILLISECS_PER_BLOCK; -// NOTE: Currently it is not possible to change the epoch duration after the chain has started. -// Attempting to do so will brick block production. -pub const BLOCKS_PER_SESSION: BlockNumber = 10 * MINUTES; -pub const SESSIONS_PER_ERA: SessionIndex = 3; - -// 1 in 4 blocks (on average, not counting collisions) will be primary babe blocks. -pub const PRIMARY_PROBABILITY: (u64, u64) = (1, 4); - -pub const fn deposit(items: u32, bytes: u32) -> Balance { - items as Balance * 20 * COIN + (bytes as Balance) * 100 * MICRO -} diff --git a/node/runtime/pangolin/src/impls.rs b/node/runtime/pangolin/src/impls.rs deleted file mode 100644 index 9bd21ec20c..0000000000 --- a/node/runtime/pangolin/src/impls.rs +++ /dev/null @@ -1,132 +0,0 @@ -//! Some configurable implementations as associated type for the substrate runtime. - -pub mod relay { - // --- darwinia-network --- - use crate::*; - use darwinia_relay_primitives::relayer_game::*; - use ethereum_primitives::EthereumBlockNumber; - - pub struct EthereumRelayerGameAdjustor; - impl AdjustableRelayerGame for EthereumRelayerGameAdjustor { - type Moment = BlockNumber; - type Balance = Balance; - type RelayHeaderId = EthereumBlockNumber; - - fn max_active_games() -> u8 { - 32 - } - - fn affirm_time(round: u32) -> Self::Moment { - match round { - // 1.5 mins - 0 => 15, - // 0.5 mins - _ => 5, - } - } - - fn complete_proofs_time(round: u32) -> Self::Moment { - match round { - // 1.5 mins - 0 => 15, - // 0.5 mins - _ => 5, - } - } - - fn update_sample_points(sample_points: &mut Vec>) { - sample_points.push(vec![sample_points.last().unwrap().last().unwrap() - 1]); - } - - fn estimate_stake(round: u32, affirmations_count: u32) -> Self::Balance { - match round { - 0 => match affirmations_count { - 0 => 1000 * COIN, - _ => 1500 * COIN, - }, - _ => 100 * COIN, - } - } - } -} - -// --- crates.io --- -use smallvec::smallvec; -// --- paritytech --- -use frame_support::{ - traits::{Currency, Imbalance, MaxEncodedLen, OnUnbalanced}, - weights::{ - constants::ExtrinsicBaseWeight, WeightToFeeCoefficient, WeightToFeeCoefficients, - WeightToFeePolynomial, - }, -}; -use sp_runtime::{Perbill, RuntimeDebug}; -// --- darwinia-network --- -use crate::*; - -darwinia_support::impl_account_data! { - struct AccountData - for - RingInstance, - KtonInstance - where - Balance = Balance - { - // other data - } -} - -pub struct ToAuthor; -impl OnUnbalanced for ToAuthor { - fn on_nonzero_unbalanced(amount: RingNegativeImbalance) { - let numeric_amount = amount.peek(); - let author = Authorship::author(); - Ring::resolve_creating(&Authorship::author(), amount); - System::deposit_event(>::Deposit( - author, - numeric_amount, - )); - } -} - -pub struct DealWithFees; -impl OnUnbalanced for DealWithFees { - fn on_unbalanceds(mut fees_then_tips: impl Iterator) { - if let Some(fees) = fees_then_tips.next() { - // for fees, 80% to treasury, 20% to author - let mut split = fees.ration(80, 20); - if let Some(tips) = fees_then_tips.next() { - // for tips, if any, 100% to author - tips.merge_into(&mut split.1); - } - Treasury::on_unbalanced(split.0); - ToAuthor::on_unbalanced(split.1); - } - } -} - -/// Handles converting a weight scalar to a fee value, based on the scale and granularity of the -/// node's balance type. -/// -/// This should typically create a mapping between the following ranges: -/// - [0, MAXIMUM_BLOCK_WEIGHT] -/// - [Balance::min, Balance::max] -/// -/// Yet, it can be used for any other sort of change to weight-fee. Some examples being: -/// - Setting it to `0` will essentially disable the weight fee. -/// - Setting it to `1` will cause the literal `#[weight = x]` values to be charged. -pub struct WeightToFee; -impl WeightToFeePolynomial for WeightToFee { - type Balance = Balance; - fn polynomial() -> WeightToFeeCoefficients { - // in Crab, extrinsic base weight (smallest non-zero weight) is mapped to 100 MILLI: - let p = 100 * MILLI; - let q = Balance::from(ExtrinsicBaseWeight::get()); - smallvec![WeightToFeeCoefficient { - degree: 1, - negative: false, - coeff_frac: Perbill::from_rational(p % q, q), - coeff_integer: p / q, - }] - } -} diff --git a/node/runtime/pangolin/src/lib.rs b/node/runtime/pangolin/src/lib.rs index d2798f687b..a9757f8ca0 100644 --- a/node/runtime/pangolin/src/lib.rs +++ b/node/runtime/pangolin/src/lib.rs @@ -28,9 +28,6 @@ pub use pallets::*; pub mod bridges; pub use bridges::*; -pub mod impls; -pub use impls::*; - pub mod wasm { //! Make the WASM binary available. @@ -72,11 +69,11 @@ pub mod wasm { } pub use wasm::*; -pub use common_primitives::{ - self as pangoro_primitives, {self as pangolin_primitives}, -}; +pub use common_primitives as pangoro_primitives; +pub use common_primitives as pangolin_primitives; -pub use pangolin_constants::*; +pub use common_runtime as pangolin_runtime_system_params; +pub use common_runtime as pangoro_runtime_system_params; pub use darwinia_staking::StakerStatus; @@ -99,7 +96,7 @@ use frame_support::{ use frame_system::{ offchain::{AppCrypto, CreateSignedTransaction, SendTransactionTypes, SigningTypes}, ChainContext, CheckEra, CheckGenesis, CheckNonce, CheckSpecVersion, CheckTxVersion, - CheckWeight, + CheckWeight, EnsureRoot, }; use pallet_grandpa::{ fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList, @@ -123,6 +120,7 @@ use sp_version::RuntimeVersion; use bridge_primitives::{PANGOLIN_CHAIN_ID, PANGORO_CHAIN_ID}; use bridges::substrate::pangoro_messages::{ToPangoroMessagePayload, WithPangoroMessageBridge}; use common_primitives::*; +use common_runtime::*; use darwinia_balances_rpc_runtime_api::RuntimeDispatchInfo as BalancesRuntimeDispatchInfo; use darwinia_bridge_ethereum::CheckEthereumRelayHeaderParcel; use darwinia_evm::{Account as EVMAccount, FeeCalculator, Runner}; @@ -165,6 +163,8 @@ pub type SignedPayload = generic::SignedPayload; type Ring = Balances; +pub type RootOrigin = EnsureRoot; + /// This runtime version. #[sp_version::runtime_version] pub const VERSION: RuntimeVersion = RuntimeVersion { @@ -303,7 +303,7 @@ where nonce: Nonce, ) -> Option<(Call, ::SignaturePayload)> { // take the biggest period possible. - let period = BlockHashCount::get() + let period = BlockHashCountForPangolin::get() .checked_next_power_of_two() .map(|c| c / 2) .unwrap_or(2) as u64; diff --git a/node/runtime/pangolin/src/pallets/babe.rs b/node/runtime/pangolin/src/pallets/babe.rs index dfead10d9e..2a79e2bf64 100644 --- a/node/runtime/pangolin/src/pallets/babe.rs +++ b/node/runtime/pangolin/src/pallets/babe.rs @@ -8,7 +8,7 @@ use crate::*; frame_support::parameter_types! { // NOTE: Currently it is not possible to change the epoch duration after the chain has started. // Attempting to do so will brick block production. - pub const EpochDuration: u64 = BLOCKS_PER_SESSION as _; + pub const EpochDuration: u64 = PANGOLIN_BLOCKS_PER_SESSION as _; pub const ExpectedBlockTime: Moment = MILLISECS_PER_BLOCK; pub const ReportLongevity: u64 = BondingDurationInEra::get() as u64 * SessionsPerEra::get() as u64 * EpochDuration::get(); diff --git a/node/runtime/pangolin/src/pallets/bounties.rs b/node/runtime/pangolin/src/pallets/bounties.rs index 8b2b5c1e63..0e9558f2ac 100644 --- a/node/runtime/pangolin/src/pallets/bounties.rs +++ b/node/runtime/pangolin/src/pallets/bounties.rs @@ -6,8 +6,8 @@ use pallet_bounties::Config; frame_support::parameter_types! { pub const BountyDepositBase: Balance = 1 * COIN; - pub const BountyDepositPayoutDelay: BlockNumber = 3 * MINUTES; - pub const BountyUpdatePeriod: BlockNumber = 3 * MINUTES; + pub const BountyDepositPayoutDelay: BlockNumber = 4 * DAYS; + pub const BountyUpdatePeriod: BlockNumber = 90 * DAYS; pub const BountyCuratorDeposit: Permill = Permill::from_percent(50); pub const BountyValueMinimum: Balance = 2 * COIN; } diff --git a/node/runtime/pangolin/src/pallets/bridge_grandpa.rs b/node/runtime/pangolin/src/pallets/bridge_grandpa.rs index b0aa693209..4dded31f43 100644 --- a/node/runtime/pangolin/src/pallets/bridge_grandpa.rs +++ b/node/runtime/pangolin/src/pallets/bridge_grandpa.rs @@ -5,7 +5,7 @@ use bridge_primitives::Pangoro; use pallet_bridge_grandpa::Config; // --- darwinia-network --- use crate::*; -use pangoro_constants::DAYS; +use pangoro_primitives::DAYS; frame_support::parameter_types! { // This is a pretty unscientific cap. diff --git a/node/runtime/pangolin/src/pallets/collective.rs b/node/runtime/pangolin/src/pallets/collective.rs index 80beeeb75b..409d09c041 100644 --- a/node/runtime/pangolin/src/pallets/collective.rs +++ b/node/runtime/pangolin/src/pallets/collective.rs @@ -2,7 +2,7 @@ pub use pallet_collective::{Instance1 as CouncilCollective, Instance2 as TechnicalCollective}; // --- paritytech --- -use frame_system::{EnsureOneOf, EnsureRoot}; +use frame_system::EnsureOneOf; use pallet_collective::{ Config, EnsureProportionAtLeast, EnsureProportionMoreThan, PrimeDefaultVote, }; @@ -12,31 +12,31 @@ use crate::*; pub type EnsureRootOrHalfCouncil = EnsureOneOf< AccountId, - EnsureRoot, + RootOrigin, EnsureProportionAtLeast<_1, _2, AccountId, CouncilCollective>, >; pub type EnsureRootOrMoreThanHalfCouncil = EnsureOneOf< AccountId, - EnsureRoot, + RootOrigin, EnsureProportionMoreThan<_1, _2, AccountId, CouncilCollective>, >; pub type EnsureRootOrHalfTechnicalComittee = EnsureOneOf< AccountId, - EnsureRoot, + RootOrigin, EnsureProportionMoreThan<_1, _2, AccountId, TechnicalCollective>, >; pub type ApproveOrigin = EnsureOneOf< AccountId, - EnsureRoot, + RootOrigin, EnsureProportionAtLeast<_3, _5, AccountId, CouncilCollective>, >; frame_support::parameter_types! { - pub const CouncilMotionDuration: BlockNumber = 3 * MINUTES; + pub const CouncilMotionDuration: BlockNumber = 3 * DAYS; pub const CouncilMaxProposals: u32 = 100; pub const CouncilMaxMembers: u32 = 100; - pub const TechnicalMotionDuration: BlockNumber = 3 * MINUTES; + pub const TechnicalMotionDuration: BlockNumber = 3 * DAYS; pub const TechnicalMaxProposals: u32 = 100; pub const TechnicalMaxMembers: u32 = 100; } diff --git a/node/runtime/pangolin/src/pallets/democracy.rs b/node/runtime/pangolin/src/pallets/democracy.rs index 5815cb5dcd..285ce615e1 100644 --- a/node/runtime/pangolin/src/pallets/democracy.rs +++ b/node/runtime/pangolin/src/pallets/democracy.rs @@ -1,5 +1,5 @@ // --- paritytech --- -use frame_system::{EnsureOneOf, EnsureRoot}; +use frame_system::EnsureOneOf; use pallet_collective::{EnsureMember, EnsureProportionAtLeast}; use sp_core::u32_trait::{_1, _2, _3}; // --- darwinia-network --- @@ -7,13 +7,13 @@ use crate::*; use darwinia_democracy::Config; frame_support::parameter_types! { - pub const LaunchPeriod: BlockNumber = 3 * MINUTES; - pub const VotingPeriod: BlockNumber = 3 * MINUTES; - pub const FastTrackVotingPeriod: BlockNumber = 3 * MINUTES; - pub const MinimumDeposit: Balance = 1 * COIN; - pub const EnactmentPeriod: BlockNumber = 3 * MINUTES; - pub const CooloffPeriod: BlockNumber = 3 * MINUTES; - pub const PreimageByteDeposit: Balance = 1 * MILLI; + pub const LaunchPeriod: BlockNumber = 7 * DAYS; + pub const VotingPeriod: BlockNumber = 7 * DAYS; + pub const FastTrackVotingPeriod: BlockNumber = 3 * HOURS; + pub const MinimumDeposit: Balance = 1 * MILLI; + pub const EnactmentPeriod: BlockNumber = 8 * DAYS; + pub const CooloffPeriod: BlockNumber = 7 * DAYS; + pub const PreimageByteDeposit: Balance = 10 * NANO; pub const InstantAllowed: bool = true; pub const MaxVotes: u32 = 100; pub const MaxProposals: u32 = 100; @@ -46,10 +46,10 @@ impl Config for Runtime { // Root must agree. type CancelProposalOrigin = EnsureOneOf< AccountId, - EnsureRoot, + RootOrigin, EnsureProportionAtLeast<_1, _1, AccountId, TechnicalCollective>, >; - type BlacklistOrigin = EnsureRoot; + type BlacklistOrigin = RootOrigin; // Any single technical committee member may veto a coming council proposal, however they can // only do it once and it lasts only for the cool-off period. type VetoOrigin = EnsureMember; diff --git a/node/runtime/pangolin/src/pallets/election_provider_multi_phase.rs b/node/runtime/pangolin/src/pallets/election_provider_multi_phase.rs index 01bcd23fd5..a95b99ce7e 100644 --- a/node/runtime/pangolin/src/pallets/election_provider_multi_phase.rs +++ b/node/runtime/pangolin/src/pallets/election_provider_multi_phase.rs @@ -1,5 +1,4 @@ // --- paritytech --- -use frame_support::weights::{constants::BlockExecutionWeight, DispatchClass, Weight}; use pallet_election_provider_multi_phase::{Config, FallbackStrategy}; use sp_runtime::{transaction_validity::TransactionPriority, PerU16, Perbill}; // --- darwinia-network --- @@ -7,17 +6,17 @@ use crate::*; sp_npos_elections::generate_solution_type!( #[compact] - pub struct NposCompactSolution16::< + pub struct NposCompactSolution24::< VoterIndex = u32, TargetIndex = u16, Accuracy = PerU16, - >(16) + >(24) ); frame_support::parameter_types! { - // phase durations. 1/4 of the last session for each. - pub const SignedPhase: u32 = BLOCKS_PER_SESSION / 4; - pub const UnsignedPhase: u32 = BLOCKS_PER_SESSION / 4; + // no signed phase for now, just unsigned. + pub const SignedPhase: u32 = 0; + pub const UnsignedPhase: u32 = PANGOLIN_BLOCKS_PER_SESSION / 4; // signed config pub const SignedMaxSubmissions: u32 = 10; @@ -28,22 +27,12 @@ frame_support::parameter_types! { // fallback: no on-chain fallback. pub const Fallback: FallbackStrategy = FallbackStrategy::Nothing; - pub SolutionImprovementThreshold: Perbill = Perbill::from_rational(1u32, 10_000); - pub OffchainRepeat: BlockNumber = 5; + pub SolutionImprovementThreshold: Perbill = Perbill::from_rational(5u32, 10_000); // miner configs - pub const StakingUnsignedPriority: TransactionPriority = TransactionPriority::max_value() / 2; - pub const MultiPhaseUnsignedPriority: TransactionPriority = StakingUnsignedPriority::get() - 1u64; + pub NposSolutionPriority: TransactionPriority = Perbill::from_percent(90) * TransactionPriority::max_value(); pub const MinerMaxIterations: u32 = 10; - pub MinerMaxWeight: Weight = RuntimeBlockWeights::get() - .get(DispatchClass::Normal) - .max_extrinsic.expect("Normal extrinsics have a weight limit configured; qed") - .saturating_sub(BlockExecutionWeight::get()); - // Solution can occupy 90% of normal block size - pub MinerMaxLength: u32 = Perbill::from_rational(9u32, 10) * - *RuntimeBlockLength::get() - .max - .get(DispatchClass::Normal); + pub const OffchainRepeat: BlockNumber = 5; } impl Config for Runtime { @@ -52,22 +41,22 @@ impl Config for Runtime { type SignedPhase = SignedPhase; type UnsignedPhase = UnsignedPhase; type SolutionImprovementThreshold = SolutionImprovementThreshold; - type OffchainRepeat = OffchainRepeat; type MinerMaxIterations = MinerMaxIterations; - type MinerMaxWeight = MinerMaxWeight; - type MinerMaxLength = MinerMaxLength; - type MinerTxPriority = MultiPhaseUnsignedPriority; + type MinerMaxWeight = OffchainSolutionWeightLimit; + type MinerMaxLength = OffchainSolutionLengthLimit; // For now use the one from staking. + type OffchainRepeat = OffchainRepeat; + type MinerTxPriority = NposSolutionPriority; type SignedMaxSubmissions = SignedMaxSubmissions; type SignedRewardBase = SignedRewardBase; type SignedDepositBase = SignedDepositBase; type SignedDepositByte = SignedDepositByte; type SignedDepositWeight = (); - type SignedMaxWeight = MinerMaxWeight; + type SignedMaxWeight = Self::MinerMaxWeight; type SlashHandler = (); // burn slashes type RewardHandler = (); // nothing to do upon rewards type DataProvider = Staking; type OnChainAccuracy = Perbill; - type CompactSolution = NposCompactSolution16; + type CompactSolution = NposCompactSolution24; type Fallback = Fallback; type WeightInfo = (); type ForceOrigin = EnsureRootOrHalfCouncil; diff --git a/node/runtime/pangolin/src/pallets/elections_phragmen.rs b/node/runtime/pangolin/src/pallets/elections_phragmen.rs index 432d15d2f7..cdaa1d8427 100644 --- a/node/runtime/pangolin/src/pallets/elections_phragmen.rs +++ b/node/runtime/pangolin/src/pallets/elections_phragmen.rs @@ -5,16 +5,16 @@ use crate::*; use darwinia_elections_phragmen::Config; frame_support::parameter_types! { - pub const PhragmenElectionPalletId: LockIdentifier = *b"da/phrel"; + pub const PhragmenElectionPalletId: LockIdentifier = *b"phrelect"; pub const CandidacyBond: Balance = 1 * COIN; // 1 storage item created, key size is 32 bytes, value size is 16+16. - pub const VotingBondBase: Balance = pangolin_constants::deposit(1, 64); + pub const VotingBondBase: Balance = pangolin_deposit(1, 64); // additional data per vote is 32 bytes (account id). - pub const VotingBondFactor: Balance = pangolin_constants::deposit(0, 32); - pub const DesiredMembers: u32 = 13; + pub const VotingBondFactor: Balance = pangolin_deposit(0, 32); + pub const DesiredMembers: u32 = 7; pub const DesiredRunnersUp: u32 = 7; /// Daily council elections. - pub const TermDuration: BlockNumber = 3 * MINUTES; + pub const TermDuration: BlockNumber = 24 * HOURS; } impl Config for Runtime { diff --git a/node/runtime/pangolin/src/pallets/fee_market.rs b/node/runtime/pangolin/src/pallets/fee_market.rs index eee93179c0..9d333672ca 100644 --- a/node/runtime/pangolin/src/pallets/fee_market.rs +++ b/node/runtime/pangolin/src/pallets/fee_market.rs @@ -13,8 +13,8 @@ frame_support::parameter_types! { pub const FeeMarketLockId: LockIdentifier = *b"da/feelf"; pub const MinimumRelayFee: Balance = 15 * COIN; - pub const Slot: BlockNumber = 50; - pub const CollateralPerOrder: Balance = 100 * COIN; + pub const CollateralPerOrder: Balance = 50 * COIN; + pub const Slot: BlockNumber = 600; pub const AssignedRelayersRewardRatio: Permill = Permill::from_percent(60); pub const MessageRelayersRewardRatio: Permill = Permill::from_percent(80); diff --git a/node/runtime/pangolin/src/pallets/multisig.rs b/node/runtime/pangolin/src/pallets/multisig.rs index 3de326ae19..be3a247055 100644 --- a/node/runtime/pangolin/src/pallets/multisig.rs +++ b/node/runtime/pangolin/src/pallets/multisig.rs @@ -5,9 +5,9 @@ use crate::*; frame_support::parameter_types! { // One storage item; key size is 32; value is size 4+4+16+32 bytes = 56 bytes. - pub const DepositBase: Balance = pangolin_constants::deposit(1, 88); + pub const DepositBase: Balance = pangolin_deposit(1, 88); // Additional storage item size of 32 bytes. - pub const DepositFactor: Balance = pangolin_constants::deposit(0, 32); + pub const DepositFactor: Balance = pangolin_deposit(0, 32); pub const MaxSignatories: u16 = 100; } diff --git a/node/runtime/pangolin/src/pallets/proxy.rs b/node/runtime/pangolin/src/pallets/proxy.rs index f68d138fc2..035796b3d3 100644 --- a/node/runtime/pangolin/src/pallets/proxy.rs +++ b/node/runtime/pangolin/src/pallets/proxy.rs @@ -102,12 +102,12 @@ impl InstanceFilter for ProxyType { frame_support::parameter_types! { // One storage item; key size 32, value size 8; . - pub const ProxyDepositBase: Balance = pangolin_constants::deposit(1, 8); + pub const ProxyDepositBase: Balance = pangolin_deposit(1, 8); // Additional storage item size of 33 bytes. - pub const ProxyDepositFactor: Balance = pangolin_constants::deposit(0, 33); + pub const ProxyDepositFactor: Balance = pangolin_deposit(0, 33); pub const MaxProxies: u16 = 32; - pub const AnnouncementDepositBase: Balance = pangolin_constants::deposit(1, 8); - pub const AnnouncementDepositFactor: Balance = pangolin_constants::deposit(0, 66); + pub const AnnouncementDepositBase: Balance = pangolin_deposit(1, 8); + pub const AnnouncementDepositFactor: Balance = pangolin_deposit(0, 66); pub const MaxPending: u16 = 32; } diff --git a/node/runtime/pangolin/src/pallets/relayer_game.rs b/node/runtime/pangolin/src/pallets/relayer_game.rs index 31dc4d3801..aa359d6092 100644 --- a/node/runtime/pangolin/src/pallets/relayer_game.rs +++ b/node/runtime/pangolin/src/pallets/relayer_game.rs @@ -1,11 +1,63 @@ -// --- darwinia-network --- pub use darwinia_relayer_game::Instance1 as EthereumRelayerGameInstance; // --- paritytech --- use frame_support::traits::LockIdentifier; // --- darwinia-network --- use crate::*; +use darwinia_relay_primitives::AdjustableRelayerGame; use darwinia_relayer_game::Config; +use ethereum_primitives::EthereumBlockNumber; + +pub struct EthereumRelayerGameAdjustor; +impl AdjustableRelayerGame for EthereumRelayerGameAdjustor { + type Moment = BlockNumber; + type Balance = Balance; + type RelayHeaderId = EthereumBlockNumber; + + fn max_active_games() -> u8 { + 32 + } + + fn affirm_time(round: u32) -> Self::Moment { + match round { + // 3 mins + 0 => 30, + // 1.5 mins + _ => 15, + } + } + + fn complete_proofs_time(_: u32) -> Self::Moment { + // 3 mins + 30 + } + + fn update_sample_points(sample_points: &mut Vec>) { + if let Some(last_round_sample_points) = sample_points.last() { + if let Some(last_sample_point) = last_round_sample_points.last() { + let new_sample_points = vec![*last_sample_point - 1]; + + sample_points.push(new_sample_points); + } else { + // Should never be reached + log::error!(target: "ethereum-relayer-game", "Sample Round - NOT EXISTED"); + } + } else { + // Should never be reached + log::error!(target: "ethereum-relayer-game", "Sample Point - NOT EXISTED"); + } + } + + fn estimate_stake(round: u32, affirmations_count: u32) -> Self::Balance { + match round { + 0 => match affirmations_count { + 0 => 100 * COIN, + _ => 150 * COIN, + }, + _ => 10 * COIN, + } + } +} frame_support::parameter_types! { pub const EthereumRelayerGameLockId: LockIdentifier = *b"ethrgame"; @@ -15,7 +67,7 @@ impl Config for Runtime { type RingCurrency = Ring; type LockId = EthereumRelayerGameLockId; type RingSlash = Treasury; - type RelayerGameAdjustor = relay::EthereumRelayerGameAdjustor; + type RelayerGameAdjustor = EthereumRelayerGameAdjustor; type RelayableChain = EthereumRelay; type WeightInfo = (); } diff --git a/node/runtime/pangolin/src/pallets/scheduler.rs b/node/runtime/pangolin/src/pallets/scheduler.rs index 56aebf1b7e..c393c04917 100644 --- a/node/runtime/pangolin/src/pallets/scheduler.rs +++ b/node/runtime/pangolin/src/pallets/scheduler.rs @@ -1,6 +1,5 @@ // --- paritytech --- use frame_support::weights::Weight; -use frame_system::EnsureRoot; use pallet_scheduler::Config; use sp_runtime::Perbill; // --- darwinia-network --- @@ -18,7 +17,7 @@ impl Config for Runtime { type PalletsOrigin = OriginCaller; type Call = Call; type MaximumWeight = MaximumSchedulerWeight; - type ScheduleOrigin = EnsureRoot; + type ScheduleOrigin = RootOrigin; type MaxScheduledPerBlock = MaxScheduledPerBlock; type WeightInfo = (); } diff --git a/node/runtime/pangolin/src/pallets/society.rs b/node/runtime/pangolin/src/pallets/society.rs index e7e7f3f334..f1e0705192 100644 --- a/node/runtime/pangolin/src/pallets/society.rs +++ b/node/runtime/pangolin/src/pallets/society.rs @@ -9,11 +9,11 @@ frame_support::parameter_types! { pub const CandidateDeposit: Balance = 10 * COIN; pub const WrongSideDeduction: Balance = 2 * COIN; pub const MaxStrikes: u32 = 10; - pub const RotationPeriod: BlockNumber = 3 * MINUTES; + pub const RotationPeriod: BlockNumber = 80 * HOURS; pub const PeriodSpend: Balance = 500 * COIN; - pub const MaxLockDuration: BlockNumber = 3 * MINUTES; - pub const ChallengePeriod: BlockNumber = 3 * MINUTES; - pub const MaxCandidateIntake: u32 = 10; + pub const MaxLockDuration: BlockNumber = 36 * 30 * DAYS; + pub const ChallengePeriod: BlockNumber = 7 * DAYS; + pub const MaxCandidateIntake: u32 = 1; } impl Config for Runtime { diff --git a/node/runtime/pangolin/src/pallets/staking.rs b/node/runtime/pangolin/src/pallets/staking.rs index abc907322d..f0fc8ed846 100644 --- a/node/runtime/pangolin/src/pallets/staking.rs +++ b/node/runtime/pangolin/src/pallets/staking.rs @@ -8,16 +8,17 @@ use sp_staking::SessionIndex; use crate::*; use darwinia_staking::{Config, EraIndex}; -pub const MAX_NOMINATIONS: u32 = ::LIMIT as u32; +pub const MAX_NOMINATIONS: u32 = ::LIMIT as u32; frame_support::parameter_types! { pub const StakingPalletId: PalletId = PalletId(*b"da/staki"); - pub const SessionsPerEra: SessionIndex = SESSIONS_PER_ERA; - pub const BondingDurationInEra: EraIndex = 2; - pub const BondingDurationInBlockNumber: BlockNumber = 2 * BLOCKS_PER_SESSION * SESSIONS_PER_ERA; - pub const SlashDeferDuration: EraIndex = 1; - pub const MaxNominatorRewardedPerValidator: u32 = 128; - pub const Cap: Balance = CAP; + pub const SessionsPerEra: SessionIndex = PANGOLIN_SESSIONS_PER_ERA; + pub const BondingDurationInEra: EraIndex = BondingDurationInBlockNumber::get() + / (PANGORO_SESSIONS_PER_ERA as BlockNumber * PANGORO_BLOCKS_PER_SESSION); + pub const BondingDurationInBlockNumber: BlockNumber = 14 * DAYS; + pub const SlashDeferDuration: EraIndex = BondingDurationInEra::get() - 1; + pub const MaxNominatorRewardedPerValidator: u32 = 64; + pub const Cap: Balance = RING_HARD_CAP; pub const TotalPower: Power = TOTAL_POWER; } diff --git a/node/runtime/pangoro/src/pallets/system/mod.rs b/node/runtime/pangolin/src/pallets/system.rs similarity index 94% rename from node/runtime/pangoro/src/pallets/system/mod.rs rename to node/runtime/pangolin/src/pallets/system.rs index d5b10c59b3..67bd848367 100644 --- a/node/runtime/pangoro/src/pallets/system/mod.rs +++ b/node/runtime/pangolin/src/pallets/system.rs @@ -26,7 +26,6 @@ impl Filter for BaseFilter { } frame_support::parameter_types! { - pub const BlockHashCount: BlockNumber = 256; pub const Version: RuntimeVersion = VERSION; pub const SS58Prefix: u16 = 42; } @@ -46,7 +45,7 @@ impl Config for Runtime { type Lookup = AccountIdLookup; type Header = Header; type Event = Event; - type BlockHashCount = BlockHashCount; + type BlockHashCount = BlockHashCountForPangolin; type Version = Version; type PalletInfo = PalletInfo; type AccountData = AccountData; diff --git a/node/runtime/pangolin/src/pallets/system/params/Cargo.toml b/node/runtime/pangolin/src/pallets/system/params/Cargo.toml deleted file mode 100644 index 2c254deb4a..0000000000 --- a/node/runtime/pangolin/src/pallets/system/params/Cargo.toml +++ /dev/null @@ -1,27 +0,0 @@ -[package] -authors = ["Darwinia Network "] -edition = "2021" -homepage = "https://darwinia.network/" -license = "GPL-3.0" -name = "pangolin-runtime-system-params" -readme = "README.md" -repository = "https://github.com/darwinia-network/darwinia-common/" -version = "2.7.0" - -[dependencies] -# crates.io -static_assertions = { version = "1.1.0" } -# paritytech -frame-support = { default-features = false, git = "https://github.com/darwinia-network/substrate", tag = "darwinia-v0.11.6-1" } -frame-system = { default-features = false, git = "https://github.com/darwinia-network/substrate", tag = "darwinia-v0.11.6-1" } -sp-runtime = { default-features = false, git = "https://github.com/darwinia-network/substrate", tag = "darwinia-v0.11.6-1" } - -[features] -default = ["std"] - -std = [ - # paritytech - "frame-support/std", - "frame-system/std", - "sp-runtime/std", -] diff --git a/node/runtime/pangolin/src/pallets/system/params/src/lib.rs b/node/runtime/pangolin/src/pallets/system/params/src/lib.rs deleted file mode 100644 index 1ce02a5c21..0000000000 --- a/node/runtime/pangolin/src/pallets/system/params/src/lib.rs +++ /dev/null @@ -1,56 +0,0 @@ -#![cfg_attr(not(feature = "std"), no_std)] - -// --- paritytech --- -use frame_support::weights::{ - constants::{BlockExecutionWeight, ExtrinsicBaseWeight, WEIGHT_PER_SECOND}, - DispatchClass, Weight, -}; -use frame_system::limits::{BlockLength, BlockWeights}; -use sp_runtime::Perbill; - -/// We assume that an on-initialize consumes 2.5% of the weight on average, hence a single extrinsic -/// will not be allowed to consume more than `AvailableBlockRatio - 2.5%`. -const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(25); -/// We allow `Normal` extrinsics to fill up the block up to 75%, the rest can be used -/// by Operational extrinsics. -const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75); -/// We allow for 2 seconds of compute with a 6 second average block time. -const MAXIMUM_BLOCK_WEIGHT: Weight = 2 * WEIGHT_PER_SECOND; - -static_assertions::const_assert!( - NORMAL_DISPATCH_RATIO.deconstruct() >= AVERAGE_ON_INITIALIZE_RATIO.deconstruct() -); - -frame_support::parameter_types! { - pub RuntimeBlockLength: BlockLength = - BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO); - pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder() - .base_block(BlockExecutionWeight::get()) - .for_class(DispatchClass::all(), |weights| { - weights.base_extrinsic = ExtrinsicBaseWeight::get(); - }) - .for_class(DispatchClass::Normal, |weights| { - weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT); - }) - .for_class(DispatchClass::Operational, |weights| { - weights.max_total = Some(MAXIMUM_BLOCK_WEIGHT); - // Operational transactions have some extra reserved space, so that they - // are included even if block reached `MAXIMUM_BLOCK_WEIGHT`. - weights.reserved = Some( - MAXIMUM_BLOCK_WEIGHT - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT - ); - }) - .avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO) - .build_or_panic(); -} - -pub fn max_extrinsic_weight() -> Weight { - RuntimeBlockWeights::get() - .get(DispatchClass::Normal) - .max_extrinsic - .unwrap_or(Weight::MAX) -} - -pub fn max_extrinsic_size() -> u32 { - *RuntimeBlockLength::get().max.get(DispatchClass::Normal) -} diff --git a/node/runtime/pangolin/src/pallets/tips.rs b/node/runtime/pangolin/src/pallets/tips.rs index 935f62007b..5110c871ad 100644 --- a/node/runtime/pangolin/src/pallets/tips.rs +++ b/node/runtime/pangolin/src/pallets/tips.rs @@ -7,7 +7,7 @@ use pallet_tips::Config; frame_support::parameter_types! { pub const DataDepositPerByte: Balance = 1 * MILLI; pub const MaximumReasonLength: u32 = 16384; - pub const TipCountdown: BlockNumber = 3 * MINUTES; + pub const TipCountdown: BlockNumber = 1 * DAYS; pub const TipFindersFee: Percent = Percent::from_percent(20); pub const TipReportDepositBase: Balance = 1 * COIN; } diff --git a/node/runtime/pangolin/src/pallets/transaction_payment.rs b/node/runtime/pangolin/src/pallets/transaction_payment.rs index e2c66fe401..e2833e91ae 100644 --- a/node/runtime/pangolin/src/pallets/transaction_payment.rs +++ b/node/runtime/pangolin/src/pallets/transaction_payment.rs @@ -1,30 +1,46 @@ +// --- crates.io --- +use smallvec::smallvec; // --- paritytech --- -use pallet_transaction_payment::{Config, CurrencyAdapter, Multiplier, TargetedFeeAdjustment}; -use sp_runtime::{FixedPointNumber, Perquintill}; +use frame_support::weights::{ + WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial, +}; +use pallet_transaction_payment::{Config, CurrencyAdapter}; +use sp_runtime::Perbill; // --- darwinia-network --- use crate::*; -/// Parameterized slow adjusting fee updated based on -/// https://w3f-research.readthedocs.io/en/latest/polkadot/Token%20Economics.html#-2.-slow-adjusting-mechanism -pub type SlowAdjustingFeeUpdate = - TargetedFeeAdjustment; +/// Handles converting a weight scalar to a fee value, based on the scale and granularity of the +/// node's balance type. +/// +/// This should typically create a mapping between the following ranges: +/// - [0, MAXIMUM_BLOCK_WEIGHT] +/// - [Balance::min, Balance::max] +/// +/// Yet, it can be used for any other sort of change to weight-fee. Some examples being: +/// - Setting it to `0` will essentially disable the weight fee. +/// - Setting it to `1` will cause the literal `#[weight = x]` values to be charged. +pub struct WeightToFee; +impl WeightToFeePolynomial for WeightToFee { + type Balance = Balance; + fn polynomial() -> WeightToFeeCoefficients { + // in Crab, extrinsic base weight (smallest non-zero weight) is mapped to 100 MILLI: + let p = 100 * MILLI; + let q = Balance::from(ExtrinsicBaseWeight::get()); + smallvec![WeightToFeeCoefficient { + degree: 1, + negative: false, + coeff_frac: Perbill::from_rational(p % q, q), + coeff_integer: p / q, + }] + } +} frame_support::parameter_types! { - pub const TransactionByteFee: Balance = 10 * MICRO; - /// The portion of the `AvailableBlockRatio` that we adjust the fees with. Blocks filled less - /// than this will decrease the weight and more will increase. - pub const TargetBlockFullness: Perquintill = Perquintill::from_percent(25); - /// The adjustment variable of the runtime. Higher values will cause `TargetBlockFullness` to - /// change the fees more rapidly. - pub AdjustmentVariable: Multiplier = Multiplier::saturating_from_rational(3, 100_000); - /// Minimum amount of the multiplier. This value cannot be too low. A test case should ensure - /// that combined with `AdjustmentVariable`, we can recover from the minimum. - /// See `multiplier_can_grow_from_zero`. - pub MinimumMultiplier: Multiplier = Multiplier::saturating_from_rational(1, 1_000_000_000u128); + pub const TransactionByteFee: Balance = 5 * MILLI; } impl Config for Runtime { - type OnChargeTransaction = CurrencyAdapter; + type OnChargeTransaction = CurrencyAdapter>; type TransactionByteFee = TransactionByteFee; type WeightToFee = WeightToFee; type FeeMultiplierUpdate = SlowAdjustingFeeUpdate; diff --git a/node/runtime/pangolin/src/pallets/treasury.rs b/node/runtime/pangolin/src/pallets/treasury.rs index 741e2c633e..065cf50df2 100644 --- a/node/runtime/pangolin/src/pallets/treasury.rs +++ b/node/runtime/pangolin/src/pallets/treasury.rs @@ -8,8 +8,9 @@ use pallet_treasury::{Config, Instance2 as KtonTreasuryInstance}; frame_support::parameter_types! { pub const TreasuryPalletId: PalletId = PalletId(*b"da/trsry"); pub const ProposalBond: Permill = Permill::from_percent(5); - pub const ProposalBondMinimum: Balance = 20 * COIN; - pub const SpendPeriod: BlockNumber = 3 * MINUTES; + pub const RingProposalBondMinimum: Balance = 10_000 * COIN; + pub const KtonProposalBondMinimum: Balance = 10 * COIN; + pub const SpendPeriod: BlockNumber = 6 * DAYS; pub const Burn: Permill = Permill::from_percent(0); pub const MaxApprovals: u32 = 100; } @@ -24,7 +25,7 @@ impl Config for Runtime { type Event = Event; type OnSlash = Treasury; type ProposalBond = ProposalBond; - type ProposalBondMinimum = ProposalBondMinimum; + type ProposalBondMinimum = RingProposalBondMinimum; type SpendPeriod = SpendPeriod; type Burn = Burn; type BurnDestination = Society; @@ -40,7 +41,7 @@ impl Config for Runtime { type Event = Event; type OnSlash = KtonTreasury; type ProposalBond = ProposalBond; - type ProposalBondMinimum = ProposalBondMinimum; + type ProposalBondMinimum = KtonProposalBondMinimum; type SpendPeriod = SpendPeriod; type Burn = Burn; type BurnDestination = (); diff --git a/node/runtime/pangoro/Cargo.toml b/node/runtime/pangoro/Cargo.toml index 3eea9e1f2f..7d54c62e18 100644 --- a/node/runtime/pangoro/Cargo.toml +++ b/node/runtime/pangoro/Cargo.toml @@ -1,9 +1,11 @@ [package] authors = ["Darwinia Network "] +build = "build.rs" edition = "2021" homepage = "https://darwinia.network" license = "GPL-3.0" name = "pangoro-runtime" +readme = "README.md" repository = "https://github.com/darwinia-network/darwinia-common/" version = "2.7.0" @@ -12,9 +14,11 @@ version = "2.7.0" array-bytes = { version = "1.4" } codec = { package = "parity-scale-codec", version = "2.1", default-features = false, features = ["derive"] } serde = { version = "1.0", features = ["derive"], optional = true } +smallvec = { version = "1.6" } # darwinia-network bridge-primitives = { default-features = false, path = "../../primitives/bridge" } common-primitives = { default-features = false, path = "../../primitives/common" } +common-runtime = { default-features = false, path = "../common" } darwinia-balances = { default-features = false, path = "../../../frame/balances" } darwinia-balances-rpc-runtime-api = { default-features = false, path = "../../../frame/balances/rpc/runtime-api" } darwinia-evm = { default-features = false, path = "../../../frame/evm" } @@ -26,10 +30,6 @@ dp-asset = { default-features = false, path = "../../ dp-fee = { default-features = false, path = "../../../primitives/fee-market" } dp-s2s = { default-features = false, path = "../../../primitives/s2s" } module-transaction-pause = { default-features = false, path = "../../../frame/transaction-pause" } -pangolin-constants = { default-features = false, path = "../pangolin/src/constants" } -pangolin-runtime-system-params = { default-features = false, path = "../pangolin/src/pallets/system/params" } -pangoro-constants = { default-features = false, path = "src/constants" } -pangoro-runtime-system-params = { default-features = false, path = "src/pallets/system/params" } to-substrate-backing = { default-features = false, path = "../../../frame/wormhole/backing/s2s" } # paritytech bp-header-chain = { default-features = false, git = "https://github.com/darwinia-network/parity-bridges-common", tag = "darwinia-v0.11.6-3" } @@ -63,6 +63,7 @@ pallet-sudo = { default-features = false, git = " pallet-timestamp = { default-features = false, git = "https://github.com/darwinia-network/substrate", tag = "darwinia-v0.11.6-1" } pallet-transaction-payment = { default-features = false, git = "https://github.com/darwinia-network/substrate", tag = "darwinia-v0.11.6-1" } pallet-transaction-payment-rpc-runtime-api = { default-features = false, git = "https://github.com/darwinia-network/substrate", tag = "darwinia-v0.11.6-1" } +pallet-treasury = { default-features = false, git = "https://github.com/darwinia-network/substrate", tag = "darwinia-v0.11.6-1" } sp-api = { default-features = false, git = "https://github.com/darwinia-network/substrate", tag = "darwinia-v0.11.6-1" } sp-authority-discovery = { default-features = false, git = "https://github.com/darwinia-network/substrate", tag = "darwinia-v0.11.6-1" } sp-block-builder = { default-features = false, git = "https://github.com/darwinia-network/substrate", tag = "darwinia-v0.11.6-1" } @@ -93,6 +94,7 @@ std = [ # darwinia-network "bridge-primitives/std", "common-primitives/std", + "common-runtime/std", "darwinia-balances/std", "darwinia-balances-rpc-runtime-api/std", "darwinia-evm/std", @@ -104,10 +106,6 @@ std = [ "dp-fee/std", "dp-s2s/std", "module-transaction-pause/std", - "pangolin-constants/std", - "pangolin-runtime-system-params/std", - "pangoro-constants/std", - "pangoro-runtime-system-params/std", "to-substrate-backing/std", # paritytech "bp-header-chain/std", @@ -141,6 +139,7 @@ std = [ "pallet-timestamp/std", "pallet-transaction-payment/std", "pallet-transaction-payment-rpc-runtime-api/std", + "pallet-treasury/std", "sp-api/std", "sp-authority-discovery/std", "sp-block-builder/std", diff --git a/node/runtime/pangoro/src/constants/Cargo.toml b/node/runtime/pangoro/src/constants/Cargo.toml deleted file mode 100644 index e59e89c479..0000000000 --- a/node/runtime/pangoro/src/constants/Cargo.toml +++ /dev/null @@ -1,25 +0,0 @@ -[package] -authors = ["Darwinia Network "] -edition = "2021" -homepage = "https://darwinia.network/" -license = "GPL-3.0" -name = "pangoro-constants" -readme = "README.md" -repository = "https://github.com/darwinia-network/darwinia-common/" -version = "2.7.0" - -[dependencies] -# darwinia-network -common-primitives = { default-features = false, path = "../../../../primitives/common" } -# paritytech -sp-staking = { default-features = false, git = "https://github.com/darwinia-network/substrate", tag = "darwinia-v0.11.6-1" } - -[features] -default = ["std"] - -std = [ - # darwinia-network - "common-primitives/std", - # paritytech - "sp-staking/std", -] diff --git a/node/runtime/pangoro/src/constants/src/lib.rs b/node/runtime/pangoro/src/constants/src/lib.rs deleted file mode 100644 index af41ac577c..0000000000 --- a/node/runtime/pangoro/src/constants/src/lib.rs +++ /dev/null @@ -1,31 +0,0 @@ -#![cfg_attr(not(feature = "std"), no_std)] - -// --- paritytech --- -use sp_staking::SessionIndex; -// --- darwinia-network --- -use common_primitives::*; - -pub const NANO: Balance = 1; -pub const MICRO: Balance = 1_000 * NANO; -pub const MILLI: Balance = 1_000 * MICRO; -pub const COIN: Balance = 1_000 * MILLI; - -pub const CAP: Balance = 10_000_000_000 * COIN; -pub const TOTAL_POWER: Power = 1_000_000_000; - -// Time is measured by number of blocks. -pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber); -pub const HOURS: BlockNumber = 60 * MINUTES; -pub const DAYS: BlockNumber = 24 * HOURS; - -pub const MILLISECS_PER_BLOCK: Moment = 6000; -// NOTE: Currently it is not possible to change the slot duration after the chain has started. -// Attempting to do so will brick block production. -pub const SLOT_DURATION: Moment = MILLISECS_PER_BLOCK; -// NOTE: Currently it is not possible to change the epoch duration after the chain has started. -// Attempting to do so will brick block production. -pub const BLOCKS_PER_SESSION: BlockNumber = 10 * MINUTES; -pub const SESSIONS_PER_ERA: SessionIndex = 3; - -// 1 in 4 blocks (on average, not counting collisions) will be primary babe blocks. -pub const PRIMARY_PROBABILITY: (u64, u64) = (1, 4); diff --git a/node/runtime/pangoro/src/impls.rs b/node/runtime/pangoro/src/impls.rs deleted file mode 100644 index 3528eade66..0000000000 --- a/node/runtime/pangoro/src/impls.rs +++ /dev/null @@ -1,21 +0,0 @@ -//! Some configurable implementations as associated type for the substrate runtime. - -// --- paritytech --- -use frame_support::{traits::MaxEncodedLen, weights::IdentityFee}; -use sp_runtime::RuntimeDebug; -// --- darwinia-network --- -use crate::*; - -darwinia_support::impl_account_data! { - struct AccountData - for - RingInstance, - KtonInstance - where - Balance = Balance - { - // other data - } -} - -pub type WeightToFee = IdentityFee; diff --git a/node/runtime/pangoro/src/lib.rs b/node/runtime/pangoro/src/lib.rs index b0dbe828a5..f28a9c0cd2 100644 --- a/node/runtime/pangoro/src/lib.rs +++ b/node/runtime/pangoro/src/lib.rs @@ -9,9 +9,6 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); pub mod pallets; pub use pallets::*; -pub mod impls; -pub use impls::*; - pub mod wasm { //! Make the WASM binary available. @@ -56,10 +53,11 @@ pub use wasm::*; pub mod pangolin_messages; use pangolin_messages::{ToPangolinMessagePayload, WithPangolinMessageBridge}; -pub use common_primitives::{ - self as pangoro_primitives, {self as pangolin_primitives}, -}; -pub use pangoro_constants::*; +pub use common_primitives as pangoro_primitives; +pub use common_primitives as pangolin_primitives; + +pub use common_runtime as pangoro_runtime_system_params; +pub use common_runtime as pangolin_runtime_system_params; pub use darwinia_balances::Call as BalancesCall; pub use darwinia_fee_market::Call as FeeMarketCall; @@ -69,7 +67,7 @@ pub use pallet_bridge_messages::Call as BridgeMessagesCall; pub use pallet_sudo::Call as SudoCall; // --- crates.io --- -use codec::{Decode, Encode}; +use codec::Encode; // --- paritytech --- #[allow(unused)] use frame_support::{log, migration}; @@ -80,7 +78,7 @@ use frame_support::{ use frame_system::{ offchain::{AppCrypto, CreateSignedTransaction, SendTransactionTypes, SigningTypes}, ChainContext, CheckEra, CheckGenesis, CheckNonce, CheckSpecVersion, CheckTxVersion, - CheckWeight, + CheckWeight, EnsureRoot, }; use pallet_grandpa::{ fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList, @@ -102,6 +100,7 @@ use sp_version::RuntimeVersion; // --- darwinia-network --- use bridge_primitives::{PANGOLIN_CHAIN_ID, PANGORO_CHAIN_ID}; use common_primitives::*; +use common_runtime::*; use darwinia_balances_rpc_runtime_api::RuntimeDispatchInfo as BalancesRuntimeDispatchInfo; use darwinia_fee_market_rpc_runtime_api::{Fee, InProcessOrders}; @@ -130,6 +129,8 @@ pub type SignedPayload = generic::SignedPayload; pub type Ring = Balances; +pub type RootOrigin = EnsureRoot; + pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: sp_runtime::create_runtime_str!("Pangoro"), impl_name: sp_runtime::create_runtime_str!("Pangoro"), @@ -180,6 +181,8 @@ frame_support::construct_runtime!( ImOnline: pallet_im_online::{Pallet, Call, Storage, Config, Event, ValidateUnsigned} = 14, AuthorityDiscovery: pallet_authority_discovery::{Pallet, Config} = 15, + Treasury: pallet_treasury::{Pallet, Call, Storage, Config, Event} = 24, + Sudo: pallet_sudo::{Pallet, Call, Config, Storage, Event} = 16, Scheduler: pallet_scheduler::{Pallet, Call, Storage, Event} = 21, @@ -206,7 +209,7 @@ where nonce: Nonce, ) -> Option<(Call, ::SignaturePayload)> { // take the biggest period possible. - let period = BlockHashCount::get() + let period = BlockHashCountForPangoro::get() .checked_next_power_of_two() .map(|c| c / 2) .unwrap_or(2) as u64; diff --git a/node/runtime/pangoro/src/pallets/babe.rs b/node/runtime/pangoro/src/pallets/babe.rs index dfead10d9e..fca7c1c1ef 100644 --- a/node/runtime/pangoro/src/pallets/babe.rs +++ b/node/runtime/pangoro/src/pallets/babe.rs @@ -8,7 +8,7 @@ use crate::*; frame_support::parameter_types! { // NOTE: Currently it is not possible to change the epoch duration after the chain has started. // Attempting to do so will brick block production. - pub const EpochDuration: u64 = BLOCKS_PER_SESSION as _; + pub const EpochDuration: u64 = PANGORO_BLOCKS_PER_SESSION as _; pub const ExpectedBlockTime: Moment = MILLISECS_PER_BLOCK; pub const ReportLongevity: u64 = BondingDurationInEra::get() as u64 * SessionsPerEra::get() as u64 * EpochDuration::get(); diff --git a/node/runtime/pangoro/src/pallets/election_provider_multi_phase.rs b/node/runtime/pangoro/src/pallets/election_provider_multi_phase.rs index 48c8874b09..afafd3b21a 100644 --- a/node/runtime/pangoro/src/pallets/election_provider_multi_phase.rs +++ b/node/runtime/pangoro/src/pallets/election_provider_multi_phase.rs @@ -1,6 +1,4 @@ // --- paritytech --- -use frame_support::weights::{constants::BlockExecutionWeight, DispatchClass, Weight}; -use frame_system::EnsureRoot; use pallet_election_provider_multi_phase::{Config, FallbackStrategy}; use sp_runtime::{transaction_validity::TransactionPriority, PerU16, Perbill}; // --- darwinia-network --- @@ -16,9 +14,9 @@ sp_npos_elections::generate_solution_type!( ); frame_support::parameter_types! { - // phase durations. 1/4 of the last session for each. - pub const SignedPhase: u32 = BLOCKS_PER_SESSION / 4; - pub const UnsignedPhase: u32 = BLOCKS_PER_SESSION / 4; + // no signed phase for now, just unsigned. + pub const SignedPhase: u32 = 0; + pub const UnsignedPhase: u32 = PANGORO_BLOCKS_PER_SESSION / 4; // signed config pub const SignedMaxSubmissions: u32 = 10; @@ -29,22 +27,12 @@ frame_support::parameter_types! { // fallback: no on-chain fallback. pub const Fallback: FallbackStrategy = FallbackStrategy::Nothing; - pub SolutionImprovementThreshold: Perbill = Perbill::from_rational(1u32, 10_000); - pub OffchainRepeat: BlockNumber = 5; + pub SolutionImprovementThreshold: Perbill = Perbill::from_rational(5u32, 10_000); // miner configs - pub const StakingUnsignedPriority: TransactionPriority = TransactionPriority::max_value() / 2; - pub const MultiPhaseUnsignedPriority: TransactionPriority = StakingUnsignedPriority::get() - 1u64; + pub NposSolutionPriority: TransactionPriority = Perbill::from_percent(90) * TransactionPriority::max_value(); pub const MinerMaxIterations: u32 = 10; - pub MinerMaxWeight: Weight = RuntimeBlockWeights::get() - .get(DispatchClass::Normal) - .max_extrinsic.expect("Normal extrinsics have a weight limit configured; qed") - .saturating_sub(BlockExecutionWeight::get()); - // Solution can occupy 90% of normal block size - pub MinerMaxLength: u32 = Perbill::from_rational(9u32, 10) * - *RuntimeBlockLength::get() - .max - .get(DispatchClass::Normal); + pub const OffchainRepeat: BlockNumber = 5; } impl Config for Runtime { @@ -53,17 +41,17 @@ impl Config for Runtime { type SignedPhase = SignedPhase; type UnsignedPhase = UnsignedPhase; type SolutionImprovementThreshold = SolutionImprovementThreshold; - type OffchainRepeat = OffchainRepeat; type MinerMaxIterations = MinerMaxIterations; - type MinerMaxWeight = MinerMaxWeight; - type MinerMaxLength = MinerMaxLength; - type MinerTxPriority = MultiPhaseUnsignedPriority; + type MinerMaxWeight = OffchainSolutionWeightLimit; + type MinerMaxLength = OffchainSolutionLengthLimit; // For now use the one from staking. + type OffchainRepeat = OffchainRepeat; + type MinerTxPriority = NposSolutionPriority; type SignedMaxSubmissions = SignedMaxSubmissions; type SignedRewardBase = SignedRewardBase; type SignedDepositBase = SignedDepositBase; type SignedDepositByte = SignedDepositByte; type SignedDepositWeight = (); - type SignedMaxWeight = MinerMaxWeight; + type SignedMaxWeight = Self::MinerMaxWeight; type SlashHandler = (); // burn slashes type RewardHandler = (); // nothing to do upon rewards type DataProvider = Staking; @@ -71,6 +59,6 @@ impl Config for Runtime { type CompactSolution = NposCompactSolution16; type Fallback = Fallback; type WeightInfo = (); - type ForceOrigin = EnsureRoot; + type ForceOrigin = RootOrigin; type BenchmarkingConfig = (); } diff --git a/node/runtime/pangoro/src/pallets/fee_market.rs b/node/runtime/pangoro/src/pallets/fee_market.rs index 71b9ecfa16..bc591fa3d3 100644 --- a/node/runtime/pangoro/src/pallets/fee_market.rs +++ b/node/runtime/pangoro/src/pallets/fee_market.rs @@ -13,9 +13,8 @@ frame_support::parameter_types! { pub const FeeMarketLockId: LockIdentifier = *b"da/feelf"; pub const MinimumRelayFee: Balance = 15 * COIN; - pub const CollateralPerOrder: Balance = 100 * COIN; - pub const SlashPerBlock: Balance = 2 * COIN; - pub const Slot: BlockNumber = 50; + pub const CollateralPerOrder: Balance = 60 * COIN; + pub const Slot: BlockNumber = 600; pub const AssignedRelayersRewardRatio: Permill = Permill::from_percent(60); pub const MessageRelayersRewardRatio: Permill = Permill::from_percent(80); diff --git a/node/runtime/pangoro/src/pallets/mod.rs b/node/runtime/pangoro/src/pallets/mod.rs index dc4d7309ef..a2034b17b9 100644 --- a/node/runtime/pangoro/src/pallets/mod.rs +++ b/node/runtime/pangoro/src/pallets/mod.rs @@ -43,6 +43,9 @@ pub use im_online::*; pub mod authority_discovery; pub use authority_discovery::*; +pub mod treasury; +pub use treasury::*; + pub mod sudo; pub use sudo::*; diff --git a/node/runtime/pangoro/src/pallets/staking.rs b/node/runtime/pangoro/src/pallets/staking.rs index b50957da31..05999ef631 100644 --- a/node/runtime/pangoro/src/pallets/staking.rs +++ b/node/runtime/pangoro/src/pallets/staking.rs @@ -1,7 +1,6 @@ // --- paritytech --- use frame_election_provider_support::onchain::OnChainSequentialPhragmen; use frame_support::PalletId; -use frame_system::EnsureRoot; use pallet_election_provider_multi_phase::OnChainConfig; use sp_npos_elections::CompactSolution; use sp_staking::SessionIndex; @@ -13,12 +12,14 @@ pub const MAX_NOMINATIONS: u32 = ::LIM frame_support::parameter_types! { pub const StakingPalletId: PalletId = PalletId(*b"da/staki"); - pub const SessionsPerEra: SessionIndex = SESSIONS_PER_ERA; - pub const BondingDurationInEra: EraIndex = 2; - pub const BondingDurationInBlockNumber: BlockNumber = 2 * BLOCKS_PER_SESSION * SESSIONS_PER_ERA; - pub const SlashDeferDuration: EraIndex = 1; - pub const MaxNominatorRewardedPerValidator: u32 = 128; - pub const Cap: Balance = CAP; + pub const SessionsPerEra: SessionIndex = PANGORO_SESSIONS_PER_ERA; + pub const BondingDurationInEra: EraIndex = BondingDurationInBlockNumber::get() + / (PANGORO_SESSIONS_PER_ERA as BlockNumber * PANGORO_BLOCKS_PER_SESSION); + pub const BondingDurationInBlockNumber: BlockNumber = 14 * DAYS; + // slightly less than 14 days. + pub const SlashDeferDuration: EraIndex = BondingDurationInEra::get() - 1; + pub const MaxNominatorRewardedPerValidator: u32 = 64; + pub const Cap: Balance = RING_HARD_CAP; pub const TotalPower: Power = TOTAL_POWER; } @@ -31,7 +32,7 @@ impl Config for Runtime { type BondingDurationInEra = BondingDurationInEra; type BondingDurationInBlockNumber = BondingDurationInBlockNumber; type SlashDeferDuration = SlashDeferDuration; - type SlashCancelOrigin = EnsureRoot; + type SlashCancelOrigin = RootOrigin; type SessionInterface = Self; type NextNewSession = Session; type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator; diff --git a/node/runtime/pangolin/src/pallets/system/mod.rs b/node/runtime/pangoro/src/pallets/system.rs similarity index 91% rename from node/runtime/pangolin/src/pallets/system/mod.rs rename to node/runtime/pangoro/src/pallets/system.rs index 861af3e54e..dde5fe305f 100644 --- a/node/runtime/pangolin/src/pallets/system/mod.rs +++ b/node/runtime/pangoro/src/pallets/system.rs @@ -1,5 +1,3 @@ -pub use pangolin_runtime_system_params::*; - // --- paritytech --- use frame_support::{ traits::{Contains, Filter}, @@ -26,7 +24,6 @@ impl Filter for BaseFilter { } frame_support::parameter_types! { - pub const BlockHashCount: BlockNumber = 256; pub const Version: RuntimeVersion = VERSION; pub const SS58Prefix: u16 = 18; } @@ -46,7 +43,7 @@ impl Config for Runtime { type Lookup = AccountIdLookup; type Header = Header; type Event = Event; - type BlockHashCount = BlockHashCount; + type BlockHashCount = BlockHashCountForPangoro; type Version = Version; type PalletInfo = PalletInfo; type AccountData = AccountData; diff --git a/node/runtime/pangoro/src/pallets/system/params/Cargo.toml b/node/runtime/pangoro/src/pallets/system/params/Cargo.toml deleted file mode 100644 index 12258c82d4..0000000000 --- a/node/runtime/pangoro/src/pallets/system/params/Cargo.toml +++ /dev/null @@ -1,27 +0,0 @@ -[package] -authors = ["Darwinia Network "] -edition = "2021" -homepage = "https://darwinia.network/" -license = "GPL-3.0" -name = "pangoro-runtime-system-params" -readme = "README.md" -repository = "https://github.com/darwinia-network/darwinia-common/" -version = "2.7.0" - -[dependencies] -# crates.io -static_assertions = { version = "1.1.0" } -# paritytech -frame-support = { default-features = false, git = "https://github.com/darwinia-network/substrate", tag = "darwinia-v0.11.6-1" } -frame-system = { default-features = false, git = "https://github.com/darwinia-network/substrate", tag = "darwinia-v0.11.6-1" } -sp-runtime = { default-features = false, git = "https://github.com/darwinia-network/substrate", tag = "darwinia-v0.11.6-1" } - -[features] -default = ["std"] - -std = [ - # paritytech - "frame-support/std", - "frame-system/std", - "sp-runtime/std", -] diff --git a/node/runtime/pangoro/src/pallets/system/params/src/lib.rs b/node/runtime/pangoro/src/pallets/system/params/src/lib.rs deleted file mode 100644 index 1ce02a5c21..0000000000 --- a/node/runtime/pangoro/src/pallets/system/params/src/lib.rs +++ /dev/null @@ -1,56 +0,0 @@ -#![cfg_attr(not(feature = "std"), no_std)] - -// --- paritytech --- -use frame_support::weights::{ - constants::{BlockExecutionWeight, ExtrinsicBaseWeight, WEIGHT_PER_SECOND}, - DispatchClass, Weight, -}; -use frame_system::limits::{BlockLength, BlockWeights}; -use sp_runtime::Perbill; - -/// We assume that an on-initialize consumes 2.5% of the weight on average, hence a single extrinsic -/// will not be allowed to consume more than `AvailableBlockRatio - 2.5%`. -const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(25); -/// We allow `Normal` extrinsics to fill up the block up to 75%, the rest can be used -/// by Operational extrinsics. -const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75); -/// We allow for 2 seconds of compute with a 6 second average block time. -const MAXIMUM_BLOCK_WEIGHT: Weight = 2 * WEIGHT_PER_SECOND; - -static_assertions::const_assert!( - NORMAL_DISPATCH_RATIO.deconstruct() >= AVERAGE_ON_INITIALIZE_RATIO.deconstruct() -); - -frame_support::parameter_types! { - pub RuntimeBlockLength: BlockLength = - BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO); - pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder() - .base_block(BlockExecutionWeight::get()) - .for_class(DispatchClass::all(), |weights| { - weights.base_extrinsic = ExtrinsicBaseWeight::get(); - }) - .for_class(DispatchClass::Normal, |weights| { - weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT); - }) - .for_class(DispatchClass::Operational, |weights| { - weights.max_total = Some(MAXIMUM_BLOCK_WEIGHT); - // Operational transactions have some extra reserved space, so that they - // are included even if block reached `MAXIMUM_BLOCK_WEIGHT`. - weights.reserved = Some( - MAXIMUM_BLOCK_WEIGHT - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT - ); - }) - .avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO) - .build_or_panic(); -} - -pub fn max_extrinsic_weight() -> Weight { - RuntimeBlockWeights::get() - .get(DispatchClass::Normal) - .max_extrinsic - .unwrap_or(Weight::MAX) -} - -pub fn max_extrinsic_size() -> u32 { - *RuntimeBlockLength::get().max.get(DispatchClass::Normal) -} diff --git a/node/runtime/pangoro/src/pallets/transaction_pause.rs b/node/runtime/pangoro/src/pallets/transaction_pause.rs index 0a09f5fae7..1512dd6928 100644 --- a/node/runtime/pangoro/src/pallets/transaction_pause.rs +++ b/node/runtime/pangoro/src/pallets/transaction_pause.rs @@ -1,11 +1,9 @@ -// --- paritytech --- -use frame_system::EnsureRoot; // --- darwinia-network --- use crate::*; use module_transaction_pause::Config; impl Config for Runtime { type Event = Event; - type UpdateOrigin = EnsureRoot; + type UpdateOrigin = RootOrigin; type WeightInfo = (); } diff --git a/node/runtime/pangoro/src/pallets/transaction_payment.rs b/node/runtime/pangoro/src/pallets/transaction_payment.rs index 33884df5a4..f141730243 100644 --- a/node/runtime/pangoro/src/pallets/transaction_payment.rs +++ b/node/runtime/pangoro/src/pallets/transaction_payment.rs @@ -1,15 +1,47 @@ +// --- crates.io --- +use smallvec::smallvec; // --- paritytech --- +use frame_support::weights::{ + WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial, +}; use pallet_transaction_payment::{Config, CurrencyAdapter}; +use sp_runtime::Perbill; // --- darwinia-network --- use crate::*; +/// Handles converting a weight scalar to a fee value, based on the scale and granularity of the +/// node's balance type. +/// +/// This should typically create a mapping between the following ranges: +/// - [0, MAXIMUM_BLOCK_WEIGHT] +/// - [Balance::min, Balance::max] +/// +/// Yet, it can be used for any other sort of change to weight-fee. Some examples being: +/// - Setting it to `0` will essentially disable the weight fee. +/// - Setting it to `1` will cause the literal `#[weight = x]` values to be charged. +pub struct WeightToFee; +impl WeightToFeePolynomial for WeightToFee { + type Balance = Balance; + fn polynomial() -> WeightToFeeCoefficients { + // in Darwinia, extrinsic base weight (smallest non-zero weight) is mapped to 10 MILLI: + let p = 10 * MILLI; + let q = Balance::from(ExtrinsicBaseWeight::get()); + smallvec![WeightToFeeCoefficient { + degree: 1, + negative: false, + coeff_frac: Perbill::from_rational(p % q, q), + coeff_integer: p / q, + }] + } +} + frame_support::parameter_types! { - pub const TransactionByteFee: Balance = 1; + pub const TransactionByteFee: Balance = 50 * MICRO; } impl Config for Runtime { - type OnChargeTransaction = CurrencyAdapter; + type OnChargeTransaction = CurrencyAdapter>; type TransactionByteFee = TransactionByteFee; type WeightToFee = WeightToFee; - type FeeMultiplierUpdate = (); + type FeeMultiplierUpdate = SlowAdjustingFeeUpdate; } diff --git a/node/runtime/pangoro/src/pallets/treasury.rs b/node/runtime/pangoro/src/pallets/treasury.rs new file mode 100644 index 0000000000..bda0dac63c --- /dev/null +++ b/node/runtime/pangoro/src/pallets/treasury.rs @@ -0,0 +1,34 @@ +// --- paritytech --- +use frame_support::PalletId; +use sp_runtime::Permill; +// --- darwinia-network --- +use crate::*; +use pallet_treasury::Config; + +frame_support::parameter_types! { + pub const TreasuryPalletId: PalletId = PalletId(*b"da/trsry"); + pub const ProposalBond: Permill = Permill::from_percent(5); + pub const RingProposalBondMinimum: Balance = 1_000 * COIN; + pub const SpendPeriod: BlockNumber = 24 * DAYS; + pub const Burn: Permill = Permill::from_percent(1); + pub const MaxApprovals: u32 = 100; +} + +// In order to use `Tips`, which bounded by `pallet_treasury::Config` rather `pallet_treasury::Config` +// Still use `DefaultInstance` here instead `Instance1` +impl Config for Runtime { + type PalletId = TreasuryPalletId; + type Currency = Ring; + type ApproveOrigin = RootOrigin; + type RejectOrigin = RootOrigin; + type Event = Event; + type OnSlash = Treasury; + type ProposalBond = ProposalBond; + type ProposalBondMinimum = RingProposalBondMinimum; + type SpendPeriod = SpendPeriod; + type Burn = Burn; + type BurnDestination = (); + type WeightInfo = (); + type SpendFunds = (); + type MaxApprovals = MaxApprovals; +} diff --git a/node/service/src/chain_spec/pangolin.rs b/node/service/src/chain_spec/pangolin.rs index 71e76a0520..d3cd345f55 100644 --- a/node/service/src/chain_spec/pangolin.rs +++ b/node/service/src/chain_spec/pangolin.rs @@ -83,7 +83,7 @@ fn session_keys( fn properties() -> Properties { let mut properties = Properties::new(); - properties.insert("ss58Format".into(), 18.into()); + properties.insert("ss58Format".into(), 42.into()); properties.insert("tokenDecimals".into(), vec![9, 9].into()); properties.insert("tokenSymbol".into(), vec!["PRING", "PKTON"].into()); diff --git a/node/service/src/chain_spec/pangoro.rs b/node/service/src/chain_spec/pangoro.rs index 8cca4e7b69..dd13193189 100644 --- a/node/service/src/chain_spec/pangoro.rs +++ b/node/service/src/chain_spec/pangoro.rs @@ -60,7 +60,7 @@ fn session_keys( fn properties() -> Properties { let mut properties = Properties::new(); - properties.insert("ss58Format".into(), 42.into()); + properties.insert("ss58Format".into(), 18.into()); properties.insert("tokenDecimals".into(), vec![9, 9].into()); properties.insert("tokenSymbol".into(), vec!["ORING", "OKTON"].into()); @@ -227,6 +227,7 @@ pub fn genesis_config() -> ChainSpec { grandpa: Default::default(), im_online: Default::default(), authority_discovery: Default::default(), + treasury: Default::default(), sudo: SudoConfig { key: root.clone() }, substrate_2_substrate_backing: Substrate2SubstrateBackingConfig { secure_limited_period: DAYS, @@ -327,6 +328,7 @@ pub fn development_config() -> ChainSpec { grandpa: Default::default(), im_online: Default::default(), authority_discovery: Default::default(), + treasury: Default::default(), sudo: SudoConfig { key: root.clone() }, substrate_2_substrate_backing: Substrate2SubstrateBackingConfig { secure_limited_period: DAYS, diff --git a/primitives/contract/Cargo.toml b/primitives/contract/Cargo.toml index 290ca8b7e5..145465e4a4 100644 --- a/primitives/contract/Cargo.toml +++ b/primitives/contract/Cargo.toml @@ -1,7 +1,7 @@ [package] authors = ["Darwinia Network "] description = "Dawrinia EVM Contract Primitives" -edition = "2018" +edition = "2021" homepage = "https://darwinia.network/" license = "GPL-3.0" name = "dp-contract"