Adds propose parachain pallet (#2243)

* Adds propose parachain pallet

* Update runtime/rococo/src/propose_parachain.rs

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>

* Fix runtime benchmarks

* Get rid of staking

* Fix benchmarking feature..

* Remove accidentally added crate

* Bump Rococo spec_version

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
Bastian Köcher
2021-01-12 11:25:31 +01:00
committed by GitHub
parent 978bd86205
commit 844a574d40
8 changed files with 476 additions and 77 deletions
+71 -72
View File
@@ -32,22 +32,18 @@ use primitives::v1::{
SessionInfo as SessionInfoData,
};
use runtime_common::{
SlowAdjustingFeeUpdate,
impls::ToAuthor,
BlockHashCount, BlockWeights, BlockLength, RocksDbWeight, OffchainSolutionWeightLimit,
SlowAdjustingFeeUpdate, impls::ToAuthor, BlockHashCount, BlockWeights, BlockLength, RocksDbWeight,
};
use runtime_parachains::{
self,
runtime_api_impl::v1 as runtime_api_impl,
};
use frame_support::{
parameter_types, construct_runtime, debug,
traits::{KeyOwnerProofSystem, Filter},
weights::Weight,
parameter_types, construct_runtime, debug, traits::{KeyOwnerProofSystem, Filter, EnsureOrigin}, weights::Weight,
};
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
ApplyExtrinsicResult, KeyTypeId, Perbill, curve::PiecewiseLinear,
ApplyExtrinsicResult, KeyTypeId, Perbill,
transaction_validity::{TransactionValidity, TransactionSource, TransactionPriority},
traits::{
BlakeTwo256, Block as BlockT, OpaqueKeys, IdentityLookup,
@@ -64,7 +60,7 @@ use pallet_grandpa::{AuthorityId as GrandpaId, fg_primitives};
use sp_core::OpaqueMetadata;
use sp_staking::SessionIndex;
use pallet_session::historical as session_historical;
use frame_system::EnsureRoot;
use frame_system::{EnsureRoot, EnsureOneOf, EnsureSigned};
use runtime_common::{paras_sudo_wrapper, paras_registrar};
use runtime_parachains::origin as parachains_origin;
@@ -78,10 +74,8 @@ use runtime_parachains::dmp as parachains_dmp;
use runtime_parachains::ump as parachains_ump;
use runtime_parachains::hrmp as parachains_hrmp;
use runtime_parachains::scheduler as parachains_scheduler;
use runtime_parachains::reward_points::RewardValidatorsWithEraPoints;
pub use pallet_balances::Call as BalancesCall;
pub use pallet_staking::StakerStatus;
use polkadot_parachain::primitives::Id as ParaId;
use xcm::v0::{MultiLocation, NetworkId};
@@ -91,10 +85,11 @@ use xcm_builder::{
CurrencyAdapter as XcmCurrencyAdapter, ChildParachainAsNative,
SignedAccountId32AsNative, ChildSystemParachainAsSuperuser, LocationInverter,
};
use constants::{time::*, currency::*, fee::*};
/// Constant values used within the runtime.
pub mod constants;
use constants::{time::*, currency::*, fee::*};
mod propose_parachain;
// Make the WASM binary available.
#[cfg(feature = "std")]
@@ -105,7 +100,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("rococo"),
impl_name: create_runtime_str!("parity-rococo-v1"),
authoring_version: 0,
spec_version: 14,
spec_version: 15,
impl_version: 0,
#[cfg(not(feature = "disable-runtime-api"))]
apis: RUNTIME_API_VERSIONS,
@@ -182,7 +177,6 @@ construct_runtime! {
// Consensus support.
Authorship: pallet_authorship::{Module, Call, Storage},
Staking: pallet_staking::{Module, Call, Storage, Config<T>, Event<T>, ValidateUnsigned},
Offences: pallet_offences::{Module, Call, Storage, Event},
Historical: session_historical::{Module},
Session: pallet_session::{Module, Call, Storage, Event, Config<T>},
@@ -208,6 +202,9 @@ construct_runtime! {
// Sudo
Sudo: pallet_sudo::{Module, Call, Storage, Event<T>, Config<T>},
// Propose parachain pallet.
ProposeParachain: propose_parachain::{Module, Call, Storage, Event},
}
}
@@ -304,35 +301,15 @@ impl frame_system::offchain::SigningTypes for Runtime {
type Signature = Signature;
}
/// Special `FullIdentificationOf` implementation that is returning for every input `Some(Default::default())`.
pub struct FullIdentificationOf;
impl sp_runtime::traits::Convert<AccountId, Option<()>> for FullIdentificationOf {
fn convert(_: AccountId) -> Option<()> { Some(Default::default()) }
}
impl pallet_session::historical::Config for Runtime {
type FullIdentification = pallet_staking::Exposure<AccountId, Balance>;
type FullIdentificationOf = pallet_staking::ExposureOf<Runtime>;
}
pallet_staking_reward_curve::build! {
const REWARD_CURVE: PiecewiseLinear<'static> = curve!(
min_inflation: 0_025_000,
max_inflation: 0_100_000,
ideal_stake: 0_500_000,
falloff: 0_050_000,
max_piece_count: 40,
test_precision: 0_005_000,
);
}
parameter_types! {
// Six sessions in an era (6 hours).
pub const SessionsPerEra: SessionIndex = 6;
// 28 eras for unbonding (7 days).
pub const BondingDuration: pallet_staking::EraIndex = 28;
// 27 eras in which slashes can be cancelled (~7 days).
pub const SlashDeferDuration: pallet_staking::EraIndex = 27;
pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE;
pub const MaxNominatorRewardedPerValidator: u32 = 64;
// quarter of the last session will be for election.
pub ElectionLookahead: BlockNumber = EpochDurationInBlocks::get() / 4;
pub const MaxIterations: u32 = 10;
pub MinSolutionScoreBump: Perbill = Perbill::from_rational_approximation(5u32, 10_000);
type FullIdentification = ();
type FullIdentificationOf = FullIdentificationOf;
}
parameter_types! {
@@ -353,32 +330,6 @@ impl pallet_im_online::Config for Runtime {
type WeightInfo = ();
}
impl pallet_staking::Config for Runtime {
type Currency = Balances;
type UnixTime = Timestamp;
type CurrencyToVote = frame_support::traits::U128CurrencyToVote;
type RewardRemainder = ();
type Event = Event;
type Slash = ();
type Reward = ();
type SessionsPerEra = SessionsPerEra;
type BondingDuration = BondingDuration;
type SlashDeferDuration = SlashDeferDuration;
// A majority of the council can cancel the slash.
type SlashCancelOrigin = EnsureRoot<AccountId>;
type SessionInterface = Self;
type RewardCurve = RewardCurve;
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
type NextNewSession = Session;
type ElectionLookahead = ElectionLookahead;
type Call = Call;
type UnsignedPriority = StakingUnsignedPriority;
type MaxIterations = MaxIterations;
type OffchainSolutionWeightLimit = OffchainSolutionWeightLimit;
type MinSolutionScoreBump = MinSolutionScoreBump;
type WeightInfo = ();
}
parameter_types! {
pub const ExistentialDeposit: Balance = 1 * CENTS;
pub const MaxLocks: u32 = 50;
@@ -414,7 +365,7 @@ parameter_types! {
impl pallet_offences::Config for Runtime {
type Event = Event;
type IdentificationTuple = pallet_session::historical::IdentificationTuple<Self>;
type OnOffenceHandler = Staking;
type OnOffenceHandler = ();
type WeightSoftLimit = OffencesWeightSoftLimit;
}
@@ -445,13 +396,19 @@ parameter_types! {
pub const DisabledValidatorsThreshold: Perbill = Perbill::from_percent(17);
}
/// Special `ValidatorIdOf` implementation that is just returning the input as result.
pub struct ValidatorIdOf;
impl sp_runtime::traits::Convert<AccountId, Option<AccountId>> for ValidatorIdOf {
fn convert(a: AccountId) -> Option<AccountId> { Some(a) }
}
impl pallet_session::Config for Runtime {
type Event = Event;
type ValidatorId = AccountId;
type ValidatorIdOf = pallet_staking::StashOf<Self>;
type ValidatorIdOf = ValidatorIdOf;
type ShouldEndSession = Babe;
type NextSessionRotation = Babe;
type SessionManager = pallet_session::historical::NoteHistoricalRoot<Self, Staking>;
type SessionManager = pallet_session::historical::NoteHistoricalRoot<Self, ProposeParachain>;
type SessionHandler = <SessionKeys as OpaqueKeys>::KeyTypeIdProviders;
type Keys = SessionKeys;
type DisabledValidatorsThreshold = DisabledValidatorsThreshold;
@@ -531,16 +488,23 @@ impl pallet_authorship::Config for Runtime {
type FindAuthor = pallet_session::FindAccountFromAuthorIndex<Self, Babe>;
type UncleGenerations = UncleGenerations;
type FilterUncle = ();
type EventHandler = (Staking, ImOnline);
type EventHandler = ImOnline;
}
impl parachains_origin::Config for Runtime {}
impl parachains_configuration::Config for Runtime {}
/// Special `RewardValidators` that does nothing ;)
pub struct RewardValidators;
impl runtime_parachains::inclusion::RewardValidators for RewardValidators {
fn reward_backing(_: impl IntoIterator<Item=ValidatorIndex>) {}
fn reward_bitfields(_: impl IntoIterator<Item=ValidatorIndex>) {}
}
impl parachains_inclusion::Config for Runtime {
type Event = Event;
type RewardValidators = RewardValidatorsWithEraPoints<Runtime>;
type RewardValidators = RewardValidators;
}
impl parachains_paras::Config for Runtime {
@@ -621,6 +585,41 @@ impl pallet_sudo::Config for Runtime {
type Call = Call;
}
/// Priviledged origin used by propose parachain.
pub struct PriviledgedOrigin;
impl EnsureOrigin<Origin> for PriviledgedOrigin {
type Success = ();
fn try_origin(o: Origin) -> Result<Self::Success, Origin> {
let allowed = [
hex_literal::hex!("b44c58e50328768ac06ed44b842bfa69d86ea10f60bc36156c9ffc5e00867220"),
hex_literal::hex!("762a6a38ba72b139cba285a39a6766e02046fb023f695f5ecf7f48b037c0dd6b")
];
let origin = o.clone();
match EnsureSigned::try_origin(o) {
Ok(who) if allowed.iter().any(|a| a == &who.as_ref()) => Ok(()),
_ => Err(origin),
}
}
#[cfg(feature = "runtime-benchmarks")]
fn successful_origin() -> Origin { Origin::root() }
}
parameter_types! {
pub const ProposeDeposit: Balance = 1000 * DOLLARS;
pub const MaxNameLength: u32 = 20;
}
impl propose_parachain::Config for Runtime {
type Event = Event;
type MaxNameLength = MaxNameLength;
type ProposeDeposit = ProposeDeposit;
type PriviledgedOrigin = EnsureOneOf<AccountId, EnsureRoot<AccountId>, PriviledgedOrigin>;
}
#[cfg(not(feature = "disable-runtime-api"))]
sp_api::impl_runtime_apis! {
impl sp_api::Core<Block> for Runtime {