Skip to content

Commit e86cb88

Browse files
bkchrshawntabrizi
authored andcommitted
Adds propose parachain pallet (paritytech#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>
1 parent 3b0dc3c commit e86cb88

File tree

8 files changed

+475
-76
lines changed

8 files changed

+475
-76
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node/service/Cargo.toml

+8-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,14 @@ db = ["service/db"]
103103
full-node = [
104104
"polkadot-node-core-av-store",
105105
]
106-
runtime-benchmarks = ["polkadot-runtime/runtime-benchmarks", "kusama-runtime/runtime-benchmarks", "westend-runtime/runtime-benchmarks"]
106+
107+
runtime-benchmarks = [
108+
"polkadot-runtime/runtime-benchmarks",
109+
"kusama-runtime/runtime-benchmarks",
110+
"westend-runtime/runtime-benchmarks",
111+
"rococo-runtime/runtime-benchmarks"
112+
]
113+
107114
real-overseer = [
108115
"polkadot-availability-bitfield-distribution",
109116
"polkadot-availability-distribution",

node/service/src/chain_spec.rs

-2
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,6 @@ fn rococo_staging_testnet_config_genesis(wasm_binary: &[u8]) -> rococo_runtime::
856856
pallet_authority_discovery: Some(rococo_runtime::AuthorityDiscoveryConfig {
857857
keys: vec![],
858858
}),
859-
pallet_staking: Some(Default::default()),
860859
pallet_sudo: Some(rococo_runtime::SudoConfig {
861860
key: endowed_accounts[0].clone(),
862861
}),
@@ -1343,7 +1342,6 @@ pub fn rococo_testnet_genesis(
13431342
pallet_authority_discovery: Some(rococo_runtime::AuthorityDiscoveryConfig {
13441343
keys: vec![],
13451344
}),
1346-
pallet_staking: Some(Default::default()),
13471345
pallet_sudo: Some(rococo_runtime::SudoConfig { key: root_key }),
13481346
parachains_configuration: Some(rococo_runtime::ParachainsConfigurationConfig {
13491347
config: polkadot_runtime_parachains::configuration::HostConfiguration {

runtime/common/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub type NegativeImbalance<T> = <pallet_balances::Module<T> as Currency<<T as fr
5252

5353
/// The sequence of bytes a valid wasm module binary always starts with. Apart from that it's also a
5454
/// valid wasm module.
55-
const WASM_MAGIC: &[u8] = &[0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00];
55+
pub const WASM_MAGIC: &[u8] = &[0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00];
5656

5757
/// We assume that an on-initialize consumes 2.5% of the weight on average, hence a single extrinsic
5858
/// will not be allowed to consume more than `AvailableBlockRatio - 2.5%`.

runtime/parachains/src/paras.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ decl_storage! {
209209

210210
/// Upcoming paras (chains and threads). These are only updated on session change. Corresponds to an
211211
/// entry in the upcoming-genesis map.
212-
UpcomingParas: Vec<ParaId>;
212+
UpcomingParas get(fn upcoming_paras): Vec<ParaId>;
213213
/// Upcoming paras instantiation arguments.
214214
UpcomingParasGenesis: map hasher(twox_64_concat) ParaId => Option<ParaGenesisArgs>;
215215
/// Paras that are to be cleaned up at the end of the session.

runtime/rococo/Cargo.toml

+14
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ parity-scale-codec = { version = "1.3.6", default-features = false, features = [
1010
serde = { version = "1.0.118", default-features = false }
1111
serde_derive = { version = "1.0.117", optional = true }
1212
smallvec = "1.6.1"
13+
hex-literal = "0.3.1"
1314

1415
frame-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
1516
sp-api = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
@@ -113,3 +114,16 @@ std = [
113114
# runtime without clashing with the runtime api exported functions
114115
# in WASM.
115116
disable-runtime-api = []
117+
runtime-benchmarks = [
118+
"runtime-common/runtime-benchmarks",
119+
"frame-support/runtime-benchmarks",
120+
"frame-system/runtime-benchmarks",
121+
"sp-runtime/runtime-benchmarks",
122+
"pallet-babe/runtime-benchmarks",
123+
"pallet-balances/runtime-benchmarks",
124+
"pallet-grandpa/runtime-benchmarks",
125+
"pallet-im-online/runtime-benchmarks",
126+
"pallet-indices/runtime-benchmarks",
127+
"pallet-staking/runtime-benchmarks",
128+
"pallet-timestamp/runtime-benchmarks",
129+
]

runtime/rococo/src/lib.rs

+70-71
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,18 @@ use primitives::v1::{
3232
SessionInfo as SessionInfoData,
3333
};
3434
use runtime_common::{
35-
SlowAdjustingFeeUpdate,
36-
impls::ToAuthor,
37-
BlockHashCount, BlockWeights, BlockLength, RocksDbWeight, OffchainSolutionWeightLimit,
35+
SlowAdjustingFeeUpdate, impls::ToAuthor, BlockHashCount, BlockWeights, BlockLength, RocksDbWeight,
3836
};
3937
use runtime_parachains::{
4038
self,
4139
runtime_api_impl::v1 as runtime_api_impl,
4240
};
4341
use frame_support::{
44-
parameter_types, construct_runtime, debug,
45-
traits::{KeyOwnerProofSystem, Filter},
46-
weights::Weight,
42+
parameter_types, construct_runtime, debug, traits::{KeyOwnerProofSystem, Filter, EnsureOrigin}, weights::Weight,
4743
};
4844
use sp_runtime::{
4945
create_runtime_str, generic, impl_opaque_keys,
50-
ApplyExtrinsicResult, KeyTypeId, Perbill, curve::PiecewiseLinear,
46+
ApplyExtrinsicResult, KeyTypeId, Perbill,
5147
transaction_validity::{TransactionValidity, TransactionSource, TransactionPriority},
5248
traits::{
5349
BlakeTwo256, Block as BlockT, OpaqueKeys, IdentityLookup,
@@ -64,7 +60,7 @@ use pallet_grandpa::{AuthorityId as GrandpaId, fg_primitives};
6460
use sp_core::OpaqueMetadata;
6561
use sp_staking::SessionIndex;
6662
use pallet_session::historical as session_historical;
67-
use frame_system::EnsureRoot;
63+
use frame_system::{EnsureRoot, EnsureOneOf, EnsureSigned};
6864
use runtime_common::{paras_sudo_wrapper, paras_registrar};
6965

7066
use runtime_parachains::origin as parachains_origin;
@@ -78,10 +74,8 @@ use runtime_parachains::dmp as parachains_dmp;
7874
use runtime_parachains::ump as parachains_ump;
7975
use runtime_parachains::hrmp as parachains_hrmp;
8076
use runtime_parachains::scheduler as parachains_scheduler;
81-
use runtime_parachains::reward_points::RewardValidatorsWithEraPoints;
8277

8378
pub use pallet_balances::Call as BalancesCall;
84-
pub use pallet_staking::StakerStatus;
8579

8680
use polkadot_parachain::primitives::Id as ParaId;
8781
use xcm::v0::{MultiLocation, NetworkId};
@@ -91,10 +85,11 @@ use xcm_builder::{
9185
CurrencyAdapter as XcmCurrencyAdapter, ChildParachainAsNative,
9286
SignedAccountId32AsNative, ChildSystemParachainAsSuperuser, LocationInverter,
9387
};
88+
use constants::{time::*, currency::*, fee::*};
9489

9590
/// Constant values used within the runtime.
9691
pub mod constants;
97-
use constants::{time::*, currency::*, fee::*};
92+
mod propose_parachain;
9893

9994
// Make the WASM binary available.
10095
#[cfg(feature = "std")]
@@ -105,7 +100,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
105100
spec_name: create_runtime_str!("rococo"),
106101
impl_name: create_runtime_str!("parity-rococo-v1"),
107102
authoring_version: 0,
108-
spec_version: 14,
103+
spec_version: 15,
109104
impl_version: 0,
110105
#[cfg(not(feature = "disable-runtime-api"))]
111106
apis: RUNTIME_API_VERSIONS,
@@ -182,7 +177,6 @@ construct_runtime! {
182177

183178
// Consensus support.
184179
Authorship: pallet_authorship::{Module, Call, Storage},
185-
Staking: pallet_staking::{Module, Call, Storage, Config<T>, Event<T>, ValidateUnsigned},
186180
Offences: pallet_offences::{Module, Call, Storage, Event},
187181
Historical: session_historical::{Module},
188182
Session: pallet_session::{Module, Call, Storage, Event, Config<T>},
@@ -208,6 +202,9 @@ construct_runtime! {
208202

209203
// Sudo
210204
Sudo: pallet_sudo::{Module, Call, Storage, Event<T>, Config<T>},
205+
206+
// Propose parachain pallet.
207+
ProposeParachain: propose_parachain::{Module, Call, Storage, Event},
211208
}
212209
}
213210

@@ -304,35 +301,15 @@ impl frame_system::offchain::SigningTypes for Runtime {
304301
type Signature = Signature;
305302
}
306303

307-
impl pallet_session::historical::Config for Runtime {
308-
type FullIdentification = pallet_staking::Exposure<AccountId, Balance>;
309-
type FullIdentificationOf = pallet_staking::ExposureOf<Runtime>;
304+
/// Special `FullIdentificationOf` implementation that is returning for every input `Some(Default::default())`.
305+
pub struct FullIdentificationOf;
306+
impl sp_runtime::traits::Convert<AccountId, Option<()>> for FullIdentificationOf {
307+
fn convert(_: AccountId) -> Option<()> { Some(Default::default()) }
310308
}
311309

312-
pallet_staking_reward_curve::build! {
313-
const REWARD_CURVE: PiecewiseLinear<'static> = curve!(
314-
min_inflation: 0_025_000,
315-
max_inflation: 0_100_000,
316-
ideal_stake: 0_500_000,
317-
falloff: 0_050_000,
318-
max_piece_count: 40,
319-
test_precision: 0_005_000,
320-
);
321-
}
322-
323-
parameter_types! {
324-
// Six sessions in an era (6 hours).
325-
pub const SessionsPerEra: SessionIndex = 6;
326-
// 28 eras for unbonding (7 days).
327-
pub const BondingDuration: pallet_staking::EraIndex = 28;
328-
// 27 eras in which slashes can be cancelled (~7 days).
329-
pub const SlashDeferDuration: pallet_staking::EraIndex = 27;
330-
pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE;
331-
pub const MaxNominatorRewardedPerValidator: u32 = 64;
332-
// quarter of the last session will be for election.
333-
pub ElectionLookahead: BlockNumber = EpochDurationInBlocks::get() / 4;
334-
pub const MaxIterations: u32 = 10;
335-
pub MinSolutionScoreBump: Perbill = Perbill::from_rational_approximation(5u32, 10_000);
310+
impl pallet_session::historical::Config for Runtime {
311+
type FullIdentification = ();
312+
type FullIdentificationOf = FullIdentificationOf;
336313
}
337314

338315
parameter_types! {
@@ -353,32 +330,6 @@ impl pallet_im_online::Config for Runtime {
353330
type WeightInfo = ();
354331
}
355332

356-
impl pallet_staking::Config for Runtime {
357-
type Currency = Balances;
358-
type UnixTime = Timestamp;
359-
type CurrencyToVote = frame_support::traits::U128CurrencyToVote;
360-
type RewardRemainder = ();
361-
type Event = Event;
362-
type Slash = ();
363-
type Reward = ();
364-
type SessionsPerEra = SessionsPerEra;
365-
type BondingDuration = BondingDuration;
366-
type SlashDeferDuration = SlashDeferDuration;
367-
// A majority of the council can cancel the slash.
368-
type SlashCancelOrigin = EnsureRoot<AccountId>;
369-
type SessionInterface = Self;
370-
type RewardCurve = RewardCurve;
371-
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
372-
type NextNewSession = Session;
373-
type ElectionLookahead = ElectionLookahead;
374-
type Call = Call;
375-
type UnsignedPriority = StakingUnsignedPriority;
376-
type MaxIterations = MaxIterations;
377-
type OffchainSolutionWeightLimit = OffchainSolutionWeightLimit;
378-
type MinSolutionScoreBump = MinSolutionScoreBump;
379-
type WeightInfo = ();
380-
}
381-
382333
parameter_types! {
383334
pub const ExistentialDeposit: Balance = 1 * CENTS;
384335
pub const MaxLocks: u32 = 50;
@@ -414,7 +365,7 @@ parameter_types! {
414365
impl pallet_offences::Config for Runtime {
415366
type Event = Event;
416367
type IdentificationTuple = pallet_session::historical::IdentificationTuple<Self>;
417-
type OnOffenceHandler = Staking;
368+
type OnOffenceHandler = ();
418369
type WeightSoftLimit = OffencesWeightSoftLimit;
419370
}
420371

@@ -445,13 +396,19 @@ parameter_types! {
445396
pub const DisabledValidatorsThreshold: Perbill = Perbill::from_percent(17);
446397
}
447398

399+
/// Special `ValidatorIdOf` implementation that is just returning the input as result.
400+
pub struct ValidatorIdOf;
401+
impl sp_runtime::traits::Convert<AccountId, Option<AccountId>> for ValidatorIdOf {
402+
fn convert(a: AccountId) -> Option<AccountId> { Some(a) }
403+
}
404+
448405
impl pallet_session::Config for Runtime {
449406
type Event = Event;
450407
type ValidatorId = AccountId;
451-
type ValidatorIdOf = pallet_staking::StashOf<Self>;
408+
type ValidatorIdOf = ValidatorIdOf;
452409
type ShouldEndSession = Babe;
453410
type NextSessionRotation = Babe;
454-
type SessionManager = pallet_session::historical::NoteHistoricalRoot<Self, Staking>;
411+
type SessionManager = pallet_session::historical::NoteHistoricalRoot<Self, ProposeParachain>;
455412
type SessionHandler = <SessionKeys as OpaqueKeys>::KeyTypeIdProviders;
456413
type Keys = SessionKeys;
457414
type DisabledValidatorsThreshold = DisabledValidatorsThreshold;
@@ -531,16 +488,23 @@ impl pallet_authorship::Config for Runtime {
531488
type FindAuthor = pallet_session::FindAccountFromAuthorIndex<Self, Babe>;
532489
type UncleGenerations = UncleGenerations;
533490
type FilterUncle = ();
534-
type EventHandler = (Staking, ImOnline);
491+
type EventHandler = ImOnline;
535492
}
536493

537494
impl parachains_origin::Config for Runtime {}
538495

539496
impl parachains_configuration::Config for Runtime {}
540497

498+
/// Special `RewardValidators` that does nothing ;)
499+
pub struct RewardValidators;
500+
impl runtime_parachains::inclusion::RewardValidators for RewardValidators {
501+
fn reward_backing(_: impl IntoIterator<Item=ValidatorIndex>) {}
502+
fn reward_bitfields(_: impl IntoIterator<Item=ValidatorIndex>) {}
503+
}
504+
541505
impl parachains_inclusion::Config for Runtime {
542506
type Event = Event;
543-
type RewardValidators = RewardValidatorsWithEraPoints<Runtime>;
507+
type RewardValidators = RewardValidators;
544508
}
545509

546510
impl parachains_paras::Config for Runtime {
@@ -621,6 +585,41 @@ impl pallet_sudo::Config for Runtime {
621585
type Call = Call;
622586
}
623587

588+
/// Priviledged origin used by propose parachain.
589+
pub struct PriviledgedOrigin;
590+
591+
impl EnsureOrigin<Origin> for PriviledgedOrigin {
592+
type Success = ();
593+
594+
fn try_origin(o: Origin) -> Result<Self::Success, Origin> {
595+
let allowed = [
596+
hex_literal::hex!("b44c58e50328768ac06ed44b842bfa69d86ea10f60bc36156c9ffc5e00867220"),
597+
hex_literal::hex!("762a6a38ba72b139cba285a39a6766e02046fb023f695f5ecf7f48b037c0dd6b")
598+
];
599+
600+
let origin = o.clone();
601+
match EnsureSigned::try_origin(o) {
602+
Ok(who) if allowed.iter().any(|a| a == &who.as_ref()) => Ok(()),
603+
_ => Err(origin),
604+
}
605+
}
606+
607+
#[cfg(feature = "runtime-benchmarks")]
608+
fn successful_origin() -> Origin { Origin::root() }
609+
}
610+
611+
parameter_types! {
612+
pub const ProposeDeposit: Balance = 1000 * DOLLARS;
613+
pub const MaxNameLength: u32 = 20;
614+
}
615+
616+
impl propose_parachain::Config for Runtime {
617+
type Event = Event;
618+
type MaxNameLength = MaxNameLength;
619+
type ProposeDeposit = ProposeDeposit;
620+
type PriviledgedOrigin = EnsureOneOf<AccountId, EnsureRoot<AccountId>, PriviledgedOrigin>;
621+
}
622+
624623
#[cfg(not(feature = "disable-runtime-api"))]
625624
sp_api::impl_runtime_apis! {
626625
impl sp_api::Core<Block> for Runtime {

0 commit comments

Comments
 (0)