diff --git a/Cargo.lock b/Cargo.lock index 39bbff9fa..f6e4feb62 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1359,7 +1359,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57952ca27b5e3606ff4dd79b0020231aaf9d6aa76dc05fd30137538c50bd3ce8" dependencies = [ "generic-array 0.14.5", - "typenum", + "typenum 1.15.0", ] [[package]] @@ -2822,7 +2822,7 @@ version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ffdf9f34f1447443d37393cc6c2b8313aebddcd96906caf34e54c68d8e57d7bd" dependencies = [ - "typenum", + "typenum 1.15.0", ] [[package]] @@ -2831,7 +2831,7 @@ version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd48d33ec7f05fbfa152300fdad764757cbded343c1aa1cff2fbaf4134851803" dependencies = [ - "typenum", + "typenum 1.15.0", "version_check", ] @@ -4487,7 +4487,7 @@ dependencies = [ "rand 0.8.5", "serde", "sha2 0.9.9", - "typenum", + "typenum 1.15.0", ] [[package]] @@ -4963,7 +4963,7 @@ dependencies = [ "rand 0.8.5", "rand_distr", "simba", - "typenum", + "typenum 1.15.0", ] [[package]] @@ -5023,7 +5023,6 @@ dependencies = [ "pallet-automation-time-rpc-runtime-api", "pallet-balances", "pallet-bounties", - "pallet-collator-selection", "pallet-collective", "pallet-democracy", "pallet-membership", @@ -5039,6 +5038,7 @@ dependencies = [ "pallet-vesting 1.0.0", "pallet-xcm", "parachain-info", + "parachain-staking", "parity-scale-codec", "polkadot-parachain", "polkadot-runtime-common", @@ -5205,6 +5205,7 @@ dependencies = [ "neumann-runtime", "pallet-automation-time-rpc", "pallet-transaction-payment-rpc", + "parachain-staking", "parity-scale-codec", "polkadot-cli", "polkadot-parachain", @@ -5601,26 +5602,6 @@ dependencies = [ "sp-std", ] -[[package]] -name = "pallet-collator-selection" -version = "3.0.0" -source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.18#b1e91afb7421309b203d7627b736d9bcf58260eb" -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" @@ -6305,6 +6286,26 @@ dependencies = [ "serde", ] +[[package]] +name = "parachain-staking" +version = "3.0.0" +source = "git+https://github.com/OAK-Foundation/moonbeam?branch=oak-polkadot-v0.9.18#4b6cb69127f5ff57c1b0d733a454f7520e585206" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "pallet-authorship", + "pallet-session", + "parity-scale-codec", + "scale-info", + "serde", + "sp-runtime", + "sp-staking", + "sp-std", + "substrate-fixed", +] + [[package]] name = "parity-db" version = "0.3.9" @@ -10907,6 +10908,16 @@ dependencies = [ "platforms", ] +[[package]] +name = "substrate-fixed" +version = "0.5.9" +source = "git+https://github.com/encointer/substrate-fixed#a4fb461aae6205ffc55bed51254a40c52be04e5d" +dependencies = [ + "parity-scale-codec", + "scale-info", + "typenum 1.16.0", +] + [[package]] name = "substrate-frame-rpc-system" version = "4.0.0-dev" @@ -11496,7 +11507,6 @@ dependencies = [ "pallet-automation-time-rpc-runtime-api", "pallet-balances", "pallet-bounties", - "pallet-collator-selection", "pallet-collective", "pallet-democracy", "pallet-membership", @@ -11512,6 +11522,7 @@ dependencies = [ "pallet-vesting 1.0.0", "pallet-xcm", "parachain-info", + "parachain-staking", "parity-scale-codec", "polkadot-parachain", "polkadot-runtime-common", @@ -11543,7 +11554,7 @@ version = "1.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ee73e6e4924fe940354b8d4d98cad5231175d615cd855b758adc658c0aac6a0" dependencies = [ - "cfg-if 1.0.0", + "cfg-if 0.1.10", "digest 0.10.3", "rand 0.8.5", "static_assertions", @@ -11555,6 +11566,15 @@ version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" +[[package]] +name = "typenum" +version = "1.16.0" +source = "git+https://github.com/encointer/typenum?tag=v1.16.0#4c8dddaa8bdd13130149e43b4085ad14e960617f" +dependencies = [ + "parity-scale-codec", + "scale-info", +] + [[package]] name = "ucd-trie" version = "0.1.3" diff --git a/node/Cargo.toml b/node/Cargo.toml index c10452e9e..707c1b1b8 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -108,4 +108,7 @@ polkadot-cli = { git = "https://github.com/paritytech/polkadot", branch = "relea polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.18" } polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.18" } polkadot-service = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.18" } -polkadot-test-service = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.18" } \ No newline at end of file +polkadot-test-service = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.18" } + +# Moonbeam Dependencies +parachain-staking = { git = "https://github.com/OAK-Foundation/moonbeam", default-features = false, branch = "oak-polkadot-v0.9.18" } diff --git a/node/src/chain_spec/neumann.rs b/node/src/chain_spec/neumann.rs index 300e1199a..c761bde0f 100644 --- a/node/src/chain_spec/neumann.rs +++ b/node/src/chain_spec/neumann.rs @@ -7,8 +7,8 @@ use sp_core::{crypto::UncheckedInto, sr25519}; use super::TELEMETRY_URL; use crate::chain_spec::{ - get_account_id_from_seed, get_collator_keys_from_seed, validate_allocation, - validate_vesting, Extensions, + get_account_id_from_seed, get_collator_keys_from_seed, validate_allocation, validate_vesting, + Extensions, }; use neumann_runtime::{ CouncilConfig, SudoConfig, TechnicalMembershipConfig, ValveConfig, VestingConfig, DOLLAR, @@ -59,8 +59,6 @@ pub fn development_config() -> ChainSpec { let endowed_accounts: Vec<(AccountId, Balance)> = accounts.iter().cloned().map(|k| (k, initial_balance)).collect(); - let collator_bond = EXISTENTIAL_DEPOSIT * 16; - testnet_genesis( // initial collators. vec![ @@ -80,7 +78,6 @@ pub fn development_config() -> ChainSpec { vec![], vec![get_account_id_from_seed::("Alice")], vec![get_account_id_from_seed::("Alice")], - collator_bond, ) }, Vec::new(), @@ -127,8 +124,6 @@ pub fn local_testnet_config() -> ChainSpec { let initial_vesting: Vec<(u64, Vec<(AccountId, Balance)>)> = serde_json::from_slice(vesting_json).unwrap(); - let collator_bond = EXISTENTIAL_DEPOSIT * 16; - testnet_genesis( // initial collators. vec![ @@ -148,7 +143,6 @@ pub fn local_testnet_config() -> ChainSpec { initial_vesting, vec![get_account_id_from_seed::("Alice")], vec![get_account_id_from_seed::("Alice")], - collator_bond, ) }, // Bootnodes @@ -209,8 +203,6 @@ pub fn neumann_staging_testnet_config() -> ChainSpec { vest_ending_time, ); - let collator_bond = EXISTENTIAL_DEPOSIT * 16; - testnet_genesis( // initial collators. vec![ @@ -257,7 +249,6 @@ pub fn neumann_staging_testnet_config() -> ChainSpec { // 669ocRxey7vxUJs1TTRWe31zwrpGr8B13zRfAHB6yhhfcMud hex!["001fbcefa8c96f3d2e236688da5485a0af67988b78d61ea952f461255d1f4267"].into(), ], - collator_bond, ) }, // Bootnodes @@ -302,8 +293,6 @@ pub fn neumann_latest() -> ChainSpec { EXISTENTIAL_DEPOSIT, ); - let collator_bond = EXISTENTIAL_DEPOSIT * 16; - testnet_genesis( // initial collators. vec![ @@ -350,7 +339,6 @@ pub fn neumann_latest() -> ChainSpec { // 669ocRxey7vxUJs1TTRWe31zwrpGr8B13zRfAHB6yhhfcMud hex!["001fbcefa8c96f3d2e236688da5485a0af67988b78d61ea952f461255d1f4267"].into(), ], - collator_bond, ) }, // Bootnodes @@ -379,7 +367,6 @@ fn testnet_genesis( vesting_schedule: Vec<(u64, Vec<(AccountId, Balance)>)>, general_councils: Vec, technical_memberships: Vec, - collator_bond: u128, ) -> neumann_runtime::GenesisConfig { neumann_runtime::GenesisConfig { system: neumann_runtime::SystemConfig { @@ -389,11 +376,6 @@ fn testnet_genesis( }, balances: neumann_runtime::BalancesConfig { balances: endowed_accounts }, parachain_info: neumann_runtime::ParachainInfoConfig { parachain_id: para_id }, - collator_selection: neumann_runtime::CollatorSelectionConfig { - invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), - candidacy_bond: collator_bond, - ..Default::default() - }, session: neumann_runtime::SessionConfig { keys: invulnerables .into_iter() @@ -406,6 +388,8 @@ fn testnet_genesis( }) .collect(), }, + // Defaults to active collators from session pallet unless configured otherwise + parachain_staking: Default::default(), // no need to pass anything to aura, in fact it will panic if we do. Session will take care // of this. aura: Default::default(), diff --git a/node/src/chain_spec/turing.rs b/node/src/chain_spec/turing.rs index 6a65aab64..08b5d9735 100644 --- a/node/src/chain_spec/turing.rs +++ b/node/src/chain_spec/turing.rs @@ -7,8 +7,8 @@ use sp_core::{crypto::UncheckedInto, sr25519}; use super::TELEMETRY_URL; use crate::chain_spec::{ - get_account_id_from_seed, get_collator_keys_from_seed, validate_allocation, - validate_vesting, Extensions, + get_account_id_from_seed, get_collator_keys_from_seed, validate_allocation, validate_vesting, + Extensions, }; use primitives::{AccountId, AuraId, Balance}; use turing_runtime::{ @@ -60,8 +60,6 @@ pub fn turing_development_config() -> ChainSpec { let endowed_accounts: Vec<(AccountId, Balance)> = accounts.iter().cloned().map(|k| (k, initial_balance)).collect(); - let collator_bond = EXISTENTIAL_DEPOSIT * 16; - testnet_genesis( // initial collators. vec![ @@ -81,7 +79,6 @@ pub fn turing_development_config() -> ChainSpec { vec![], vec![get_account_id_from_seed::("Alice")], vec![get_account_id_from_seed::("Alice")], - collator_bond, ) }, Vec::new(), @@ -135,8 +132,6 @@ pub fn turing_staging() -> ChainSpec { vest_ending_time, ); - let collator_bond = 400_000 * DOLLAR; - testnet_genesis( // initial collators. vec![ @@ -185,7 +180,6 @@ pub fn turing_staging() -> ChainSpec { // 669ocRxey7vxUJs1TTRWe31zwrpGr8B13zRfAHB6yhhfcMud hex!["001fbcefa8c96f3d2e236688da5485a0af67988b78d61ea952f461255d1f4267"].into(), ], - collator_bond, ) }, // Bootnodes @@ -246,8 +240,6 @@ pub fn turing_live() -> ChainSpec { vest_ending_time, ); - let collator_bond = 400_000 * DOLLAR; - testnet_genesis( // initial collators. vec![ @@ -296,7 +288,6 @@ pub fn turing_live() -> ChainSpec { // 669ocRxey7vxUJs1TTRWe31zwrpGr8B13zRfAHB6yhhfcMud hex!["001fbcefa8c96f3d2e236688da5485a0af67988b78d61ea952f461255d1f4267"].into(), ], - collator_bond, ) }, // Bootnodes @@ -325,7 +316,6 @@ fn testnet_genesis( vesting_schedule: Vec<(u64, Vec<(AccountId, Balance)>)>, general_councils: Vec, technical_memberships: Vec, - collator_bond: u128, ) -> turing_runtime::GenesisConfig { turing_runtime::GenesisConfig { system: turing_runtime::SystemConfig { @@ -335,11 +325,6 @@ fn testnet_genesis( }, balances: turing_runtime::BalancesConfig { balances: endowed_accounts }, parachain_info: turing_runtime::ParachainInfoConfig { parachain_id: para_id }, - collator_selection: turing_runtime::CollatorSelectionConfig { - invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), - candidacy_bond: collator_bond, - ..Default::default() - }, session: turing_runtime::SessionConfig { keys: invulnerables .into_iter() @@ -352,6 +337,8 @@ fn testnet_genesis( }) .collect(), }, + // Defaults to active collators from session pallet unless configured otherwise + parachain_staking: Default::default(), // no need to pass anything to aura, in fact it will panic if we do. Session will take care // of this. aura: Default::default(), diff --git a/runtime/neumann/Cargo.toml b/runtime/neumann/Cargo.toml index 395ff17ab..b1d627efd 100644 --- a/runtime/neumann/Cargo.toml +++ b/runtime/neumann/Cargo.toml @@ -78,7 +78,6 @@ cumulus-pallet-xcmp-queue = { git = 'https://github.com/paritytech/cumulus', bra cumulus-primitives-core = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.18', default-features = false } cumulus-primitives-timestamp = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.18', default-features = false } cumulus-primitives-utility = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.18', default-features = false } -pallet-collator-selection = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.18', default-features = false } parachain-info = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.18', default-features = false } # Polkadot Dependencies @@ -89,6 +88,9 @@ xcm = { git = "https://github.com/paritytech/polkadot", default-features = false xcm-builder = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.18" } xcm-executor = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.18" } +# Moonbeam Dependencies +parachain-staking = { git = "https://github.com/OAK-Foundation/moonbeam", default-features = false, branch = "oak-polkadot-v0.9.18" } + [features] default = [ "std", @@ -120,7 +122,6 @@ std = [ "pallet-automation-time-rpc-runtime-api/std", "pallet-balances/std", "pallet-bounties/std", - "pallet-collator-selection/std", "pallet-collective/std", "pallet-democracy/std", "pallet-membership/std", @@ -134,6 +135,7 @@ std = [ "pallet-transaction-payment/std", "pallet-valve/std", "pallet-vesting/std", + "parachain-staking/std", "primitives/std", "cumulus-pallet-aura-ext/std", "cumulus-pallet-parachain-system/std", @@ -161,11 +163,11 @@ runtime-benchmarks = [ "pallet-automation-time/runtime-benchmarks", "pallet-balances/runtime-benchmarks", "pallet-bounties/runtime-benchmarks", - "pallet-collator-selection/runtime-benchmarks", "pallet-collective/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", "pallet-treasury/runtime-benchmarks", "pallet-valve/runtime-benchmarks", "pallet-vesting/runtime-benchmarks", "pallet-xcm/runtime-benchmarks", + "parachain-staking/runtime-benchmarks", ] diff --git a/runtime/neumann/src/lib.rs b/runtime/neumann/src/lib.rs index c371ca478..a3b8fecdd 100644 --- a/runtime/neumann/src/lib.rs +++ b/runtime/neumann/src/lib.rs @@ -27,7 +27,7 @@ use sp_api::impl_runtime_apis; use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; use sp_runtime::{ create_runtime_str, generic, impl_opaque_keys, - traits::{AccountIdLookup, BlakeTwo256, Block as BlockT}, + traits::{AccountIdLookup, BlakeTwo256, Block as BlockT, ConvertInto}, transaction_validity::{TransactionSource, TransactionValidity}, ApplyExtrinsicResult, FixedPointNumber, Percent, }; @@ -39,7 +39,7 @@ use sp_version::RuntimeVersion; use frame_support::{ construct_runtime, parameter_types, - traits::{Contains, EnsureOneOf, Imbalance, OnUnbalanced, PrivilegeCmp}, + traits::{ConstU128, ConstU32, Contains, EnsureOneOf, Imbalance, OnUnbalanced, PrivilegeCmp}, weights::{ constants::{BlockExecutionWeight, ExtrinsicBaseWeight, WEIGHT_PER_SECOND}, DispatchClass, Weight, WeightToFeeCoefficient, WeightToFeeCoefficients, @@ -165,10 +165,10 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("neumann"), impl_name: create_runtime_str!("neumann"), authoring_version: 1, - spec_version: 279, + spec_version: 280, impl_version: 1, apis: RUNTIME_API_VERSIONS, - transaction_version: 6, + transaction_version: 7, state_version: 0, }; @@ -303,7 +303,7 @@ impl frame_system::Config for Runtime { type SS58Prefix = SS58Prefix; /// The action to take on a Runtime Upgrade type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode; - type MaxConsumers = frame_support::traits::ConstU32<16>; + type MaxConsumers = ConstU32<16>; } parameter_types! { @@ -326,7 +326,7 @@ impl pallet_authorship::Config for Runtime { type FindAuthor = pallet_session::FindAccountFromAuthorIndex; type UncleGenerations = UncleGenerations; type FilterUncle = (); - type EventHandler = (CollatorSelection,); + type EventHandler = ParachainStaking; } parameter_types! { @@ -436,11 +436,10 @@ parameter_types! { impl pallet_session::Config for Runtime { type Event = Event; 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; - type ShouldEndSession = pallet_session::PeriodicSessions; - type NextSessionRotation = pallet_session::PeriodicSessions; - type SessionManager = CollatorSelection; + type ValidatorIdOf = ConvertInto; + type ShouldEndSession = ParachainStaking; + type NextSessionRotation = ParachainStaking; + type SessionManager = ParachainStaking; // Essentially just Aura, but lets be pedantic. type SessionHandler = ::KeyTypeIdProviders; type Keys = SessionKeys; @@ -454,31 +453,50 @@ impl pallet_aura::Config for Runtime { } parameter_types! { - pub const PotId: PalletId = PalletId(*b"PotStake"); - pub const MaxCandidates: u32 = 5; - pub const MinCandidates: u32 = 1; - pub const SessionLength: BlockNumber = 6 * HOURS; - pub const MaxInvulnerables: u32 = 100; - pub const ExecutiveBody: BodyId = BodyId::Executive; + /// Default fixed percent a collator takes off the top of due rewards + pub const DefaultCollatorCommission: Perbill = Perbill::from_percent(20); + /// Default percent of inflation set aside for parachain bond every round + pub const DefaultParachainBondReservePercent: Percent = Percent::from_percent(30); } - -// We allow root only to execute privileged collator selection operations. -pub type CollatorSelectionUpdateOrigin = EnsureRoot; - -impl pallet_collator_selection::Config for Runtime { +impl parachain_staking::Config for Runtime { type Event = Event; type Currency = Balances; - type UpdateOrigin = CollatorSelectionUpdateOrigin; - type PotId = PotId; - type MaxCandidates = MaxCandidates; - type MinCandidates = MinCandidates; - type MaxInvulnerables = MaxInvulnerables; - // should be a multiple of session or things will get inconsistent - type KickThreshold = Period; - type ValidatorId = ::AccountId; - type ValidatorIdOf = pallet_collator_selection::IdentityCollator; - type ValidatorRegistration = Session; - type WeightInfo = (); + type MonetaryGovernanceOrigin = EnsureRoot; + /// Minimum round length is 2 minutes (10 * 12 second block times) + type MinBlocksPerRound = ConstU32<10>; + /// Blocks per round + type DefaultBlocksPerRound = ConstU32<{ 5 * MINUTES }>; + /// Rounds before the collator leaving the candidates request can be executed + type LeaveCandidatesDelay = ConstU32<2>; + /// Rounds before the candidate bond increase/decrease can be executed + type CandidateBondLessDelay = ConstU32<2>; + /// Rounds before the delegator exit can be executed + type LeaveDelegatorsDelay = ConstU32<2>; + /// Rounds before the delegator revocation can be executed + type RevokeDelegationDelay = ConstU32<2>; + /// Rounds before the delegator bond increase/decrease can be executed + type DelegationBondLessDelay = ConstU32<2>; + /// Rounds before the reward is paid + type RewardPaymentDelay = ConstU32<2>; + /// Minimum collators selected per round, default at genesis and minimum forever after + type MinSelectedCandidates = ConstU32<5>; + /// Maximum top delegations per candidate + type MaxTopDelegationsPerCandidate = ConstU32<10>; + /// Maximum bottom delegations per candidate + type MaxBottomDelegationsPerCandidate = ConstU32<50>; + /// Maximum delegations per delegator + type MaxDelegationsPerDelegator = ConstU32<10>; + type DefaultCollatorCommission = DefaultCollatorCommission; + type DefaultParachainBondReservePercent = DefaultParachainBondReservePercent; + /// Minimum stake required to become a collator + type MinCollatorStk = ConstU128<{ 1_000_000 * DOLLAR }>; + /// Minimum stake required to be reserved to be a candidate + type MinCandidateStk = ConstU128<{ 500 * DOLLAR }>; + /// Minimum delegation amount after initial + type MinDelegation = ConstU128<{ 50 * DOLLAR }>; + /// Minimum initial stake required to be reserved to be a delegator + type MinDelegatorStk = ConstU128<{ 50 * DOLLAR }>; + type WeightInfo = parachain_staking::weights::SubstrateWeight; } parameter_types! { @@ -775,7 +793,7 @@ impl Contains for ClosedCallFilter { Call::AutomationTime(_) => false, Call::Balances(_) => false, Call::Bounties(_) => false, - Call::CollatorSelection(_) => false, + Call::ParachainStaking(_) => false, Call::Treasury(_) => false, _ => true, } @@ -815,8 +833,8 @@ construct_runtime!( // Collator support. The order of these 4 are important and shall not change. Authorship: pallet_authorship::{Pallet, Call, Storage} = 20, - CollatorSelection: pallet_collator_selection::{Pallet, Call, Storage, Event, Config} = 21, - Session: pallet_session::{Pallet, Call, Storage, Event, Config} = 22, + Session: pallet_session::{Pallet, Call, Storage, Event, Config} = 21, + ParachainStaking: parachain_staking::{Pallet, Call, Storage, Event, Config} = 22, Aura: pallet_aura::{Pallet, Storage, Config} = 23, AuraExt: cumulus_pallet_aura_ext::{Pallet, Storage, Config} = 24, @@ -971,12 +989,14 @@ impl_runtime_apis! { use pallet_automation_time::Pallet as AutomationTime; use pallet_valve::Pallet as Valve; use pallet_vesting::Pallet as Vesting; + use parachain_staking::Pallet as ParachainStaking; let mut list = Vec::::new(); list_benchmark!(list, extra, pallet_automation_time, AutomationTime::); list_benchmark!(list, extra, pallet_valve, Valve::); list_benchmark!(list, extra, pallet_vesting, Vesting::); + list_benchmark!(list, extra, parachain_staking, ParachainStaking::); let storage_info = AllPalletsWithSystem::storage_info(); @@ -992,6 +1012,7 @@ impl_runtime_apis! { use pallet_automation_time::Pallet as AutomationTime; use pallet_valve::Pallet as Valve; use pallet_vesting::Pallet as Vesting; + use parachain_staking::Pallet as ParachainStaking; let whitelist: Vec = vec![ // Block Number @@ -1012,6 +1033,7 @@ impl_runtime_apis! { add_benchmark!(params, batches, pallet_automation_time, AutomationTime::); add_benchmark!(params, batches, pallet_valve, Valve::); add_benchmark!(params, batches, pallet_vesting, Vesting::); + add_benchmark!(params, batches, parachain_staking, ParachainStaking::); if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) } Ok(batches) diff --git a/runtime/turing/Cargo.toml b/runtime/turing/Cargo.toml index 39a370391..a1b73b23d 100644 --- a/runtime/turing/Cargo.toml +++ b/runtime/turing/Cargo.toml @@ -78,7 +78,6 @@ cumulus-pallet-xcmp-queue = { git = 'https://github.com/paritytech/cumulus', bra cumulus-primitives-core = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.18', default-features = false } cumulus-primitives-timestamp = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.18', default-features = false } cumulus-primitives-utility = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.18', default-features = false } -pallet-collator-selection = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.18', default-features = false } parachain-info = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.18', default-features = false } # Polkadot Dependencies @@ -89,6 +88,9 @@ xcm = { git = "https://github.com/paritytech/polkadot", default-features = false xcm-builder = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.18" } xcm-executor = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.18" } +# Moonbeam Dependencies +parachain-staking = { git = "https://github.com/OAK-Foundation/moonbeam", default-features = false, branch = "oak-polkadot-v0.9.18" } + [features] default = [ "std", @@ -120,7 +122,6 @@ std = [ "pallet-automation-time-rpc-runtime-api/std", "pallet-balances/std", "pallet-bounties/std", - "pallet-collator-selection/std", "pallet-collective/std", "pallet-democracy/std", "pallet-membership/std", @@ -134,6 +135,7 @@ std = [ "pallet-transaction-payment/std", "pallet-valve/std", "pallet-vesting/std", + "parachain-staking/std", "primitives/std", "cumulus-pallet-aura-ext/std", "cumulus-pallet-parachain-system/std", @@ -161,11 +163,11 @@ runtime-benchmarks = [ "pallet-automation-time/runtime-benchmarks", "pallet-balances/runtime-benchmarks", "pallet-bounties/runtime-benchmarks", - "pallet-collator-selection/runtime-benchmarks", "pallet-collective/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", "pallet-treasury/runtime-benchmarks", "pallet-valve/runtime-benchmarks", "pallet-vesting/runtime-benchmarks", "pallet-xcm/runtime-benchmarks", + "parachain-staking/runtime-benchmarks", ] diff --git a/runtime/turing/src/lib.rs b/runtime/turing/src/lib.rs index 6231c3a26..4802310ef 100644 --- a/runtime/turing/src/lib.rs +++ b/runtime/turing/src/lib.rs @@ -27,7 +27,7 @@ use sp_api::impl_runtime_apis; use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; use sp_runtime::{ create_runtime_str, generic, impl_opaque_keys, - traits::{AccountIdLookup, BlakeTwo256, Block as BlockT}, + traits::{AccountIdLookup, BlakeTwo256, Block as BlockT, ConvertInto}, transaction_validity::{TransactionSource, TransactionValidity}, ApplyExtrinsicResult, FixedPointNumber, Percent, }; @@ -39,7 +39,10 @@ use sp_version::RuntimeVersion; use frame_support::{ construct_runtime, match_type, parameter_types, - traits::{Contains, EnsureOneOf, Everything, Imbalance, Nothing, OnUnbalanced, PrivilegeCmp}, + traits::{ + ConstU128, ConstU32, Contains, EnsureOneOf, Everything, Imbalance, Nothing, OnUnbalanced, + PrivilegeCmp, + }, weights::{ constants::{BlockExecutionWeight, ExtrinsicBaseWeight, WEIGHT_PER_SECOND}, DispatchClass, IdentityFee, Weight, WeightToFeeCoefficient, WeightToFeeCoefficients, @@ -172,10 +175,10 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("turing"), impl_name: create_runtime_str!("turing"), authoring_version: 1, - spec_version: 279, + spec_version: 280, impl_version: 1, apis: RUNTIME_API_VERSIONS, - transaction_version: 6, + transaction_version: 7, state_version: 0, }; @@ -310,7 +313,7 @@ impl frame_system::Config for Runtime { type SS58Prefix = SS58Prefix; /// The action to take on a Runtime Upgrade type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode; - type MaxConsumers = frame_support::traits::ConstU32<16>; + type MaxConsumers = ConstU32<16>; } parameter_types! { @@ -333,7 +336,7 @@ impl pallet_authorship::Config for Runtime { type FindAuthor = pallet_session::FindAccountFromAuthorIndex; type UncleGenerations = UncleGenerations; type FilterUncle = (); - type EventHandler = (CollatorSelection,); + type EventHandler = ParachainStaking; } parameter_types! { @@ -595,11 +598,10 @@ parameter_types! { impl pallet_session::Config for Runtime { type Event = Event; 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; - type ShouldEndSession = pallet_session::PeriodicSessions; - type NextSessionRotation = pallet_session::PeriodicSessions; - type SessionManager = CollatorSelection; + type ValidatorIdOf = ConvertInto; + type ShouldEndSession = ParachainStaking; + type NextSessionRotation = ParachainStaking; + type SessionManager = ParachainStaking; // Essentially just Aura, but lets be pedantic. type SessionHandler = ::KeyTypeIdProviders; type Keys = SessionKeys; @@ -613,31 +615,50 @@ impl pallet_aura::Config for Runtime { } parameter_types! { - pub const PotId: PalletId = PalletId(*b"PotStake"); - pub const MaxCandidates: u32 = 5; - pub const MinCandidates: u32 = 1; - pub const SessionLength: BlockNumber = 6 * HOURS; - pub const MaxInvulnerables: u32 = 100; - pub const ExecutiveBody: BodyId = BodyId::Executive; + /// Default fixed percent a collator takes off the top of due rewards + pub const DefaultCollatorCommission: Perbill = Perbill::from_percent(20); + /// Default percent of inflation set aside for parachain bond every round + pub const DefaultParachainBondReservePercent: Percent = Percent::from_percent(30); } - -// We allow root only to execute privileged collator selection operations. -pub type CollatorSelectionUpdateOrigin = EnsureRoot; - -impl pallet_collator_selection::Config for Runtime { +impl parachain_staking::Config for Runtime { type Event = Event; type Currency = Balances; - type UpdateOrigin = CollatorSelectionUpdateOrigin; - type PotId = PotId; - type MaxCandidates = MaxCandidates; - type MinCandidates = MinCandidates; - type MaxInvulnerables = MaxInvulnerables; - // should be a multiple of session or things will get inconsistent - type KickThreshold = Period; - type ValidatorId = ::AccountId; - type ValidatorIdOf = pallet_collator_selection::IdentityCollator; - type ValidatorRegistration = Session; - type WeightInfo = (); + type MonetaryGovernanceOrigin = EnsureRoot; + /// Minimum round length is 2 minutes (10 * 12 second block times) + type MinBlocksPerRound = ConstU32<10>; + /// Blocks per round + type DefaultBlocksPerRound = ConstU32<{ 2 * HOURS }>; + /// Rounds before the collator leaving the candidates request can be executed + type LeaveCandidatesDelay = ConstU32<24>; + /// Rounds before the candidate bond increase/decrease can be executed + type CandidateBondLessDelay = ConstU32<24>; + /// Rounds before the delegator exit can be executed + type LeaveDelegatorsDelay = ConstU32<24>; + /// Rounds before the delegator revocation can be executed + type RevokeDelegationDelay = ConstU32<24>; + /// Rounds before the delegator bond increase/decrease can be executed + type DelegationBondLessDelay = ConstU32<24>; + /// Rounds before the reward is paid + type RewardPaymentDelay = ConstU32<2>; + /// Minimum collators selected per round, default at genesis and minimum forever after + type MinSelectedCandidates = ConstU32<5>; + /// Maximum top delegations per candidate + type MaxTopDelegationsPerCandidate = ConstU32<300>; + /// Maximum bottom delegations per candidate + type MaxBottomDelegationsPerCandidate = ConstU32<50>; + /// Maximum delegations per delegator + type MaxDelegationsPerDelegator = ConstU32<100>; + type DefaultCollatorCommission = DefaultCollatorCommission; + type DefaultParachainBondReservePercent = DefaultParachainBondReservePercent; + /// Minimum stake required to become a collator + type MinCollatorStk = ConstU128<{ 400_000 * DOLLAR }>; + /// Minimum stake required to be reserved to be a candidate + type MinCandidateStk = ConstU128<{ 400_000 * DOLLAR }>; + /// Minimum delegation amount after initial + type MinDelegation = ConstU128<{ 50 * DOLLAR }>; + /// Minimum initial stake required to be reserved to be a delegator + type MinDelegatorStk = ConstU128<{ 50 * DOLLAR }>; + type WeightInfo = parachain_staking::weights::SubstrateWeight; } parameter_types! { @@ -935,7 +956,7 @@ impl Contains for ClosedCallFilter { Call::AutomationTime(_) => false, Call::Balances(_) => false, Call::Bounties(_) => false, - Call::CollatorSelection(_) => false, + Call::ParachainStaking(_) => false, Call::Treasury(_) => false, _ => true, } @@ -975,8 +996,8 @@ construct_runtime!( // Collator support. The order of these 4 are important and shall not change. Authorship: pallet_authorship::{Pallet, Call, Storage} = 20, - CollatorSelection: pallet_collator_selection::{Pallet, Call, Storage, Event, Config} = 21, - Session: pallet_session::{Pallet, Call, Storage, Event, Config} = 22, + Session: pallet_session::{Pallet, Call, Storage, Event, Config} = 21, + ParachainStaking: parachain_staking::{Pallet, Call, Storage, Event, Config} = 22, Aura: pallet_aura::{Pallet, Storage, Config} = 23, AuraExt: cumulus_pallet_aura_ext::{Pallet, Storage, Config} = 24, @@ -1131,12 +1152,14 @@ impl_runtime_apis! { use pallet_automation_time::Pallet as AutomationTime; use pallet_valve::Pallet as Valve; use pallet_vesting::Pallet as Vesting; + use parachain_staking::Pallet as ParachainStaking; let mut list = Vec::::new(); list_benchmark!(list, extra, pallet_automation_time, AutomationTime::); list_benchmark!(list, extra, pallet_valve, Valve::); list_benchmark!(list, extra, pallet_vesting, Vesting::); + list_benchmark!(list, extra, parachain_staking, ParachainStaking::); let storage_info = AllPalletsWithSystem::storage_info(); @@ -1152,6 +1175,7 @@ impl_runtime_apis! { use pallet_automation_time::Pallet as AutomationTime; use pallet_valve::Pallet as Valve; use pallet_vesting::Pallet as Vesting; + use parachain_staking::Pallet as ParachainStaking; let whitelist: Vec = vec![ // Block Number @@ -1172,6 +1196,7 @@ impl_runtime_apis! { add_benchmark!(params, batches, pallet_automation_time, AutomationTime::); add_benchmark!(params, batches, pallet_valve, Valve::); add_benchmark!(params, batches, pallet_vesting, Vesting::); + add_benchmark!(params, batches, parachain_staking, ParachainStaking::); if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) } Ok(batches)