diff --git a/polkadot/Cargo.lock b/polkadot/Cargo.lock index 41c4a1d5c4..fd3c3615c6 100644 --- a/polkadot/Cargo.lock +++ b/polkadot/Cargo.lock @@ -4945,6 +4945,7 @@ dependencies = [ "pallet-vesting", "parity-scale-codec", "polkadot-primitives", + "polkadot-runtime-parachains", "rustc-hex", "serde", "serde_derive", diff --git a/polkadot/runtime/common/Cargo.toml b/polkadot/runtime/common/Cargo.toml index e00d904915..72694c33b9 100644 --- a/polkadot/runtime/common/Cargo.toml +++ b/polkadot/runtime/common/Cargo.toml @@ -36,6 +36,7 @@ frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = primitives = { package = "polkadot-primitives", path = "../../primitives", default-features = false } libsecp256k1 = { version = "0.3.2", default-features = false, optional = true } +runtime-parachains = { package = "polkadot-runtime-parachains", path = "../parachains", default-features = false } [dev-dependencies] hex-literal = "0.2.1" diff --git a/polkadot/runtime/common/src/lib.rs b/polkadot/runtime/common/src/lib.rs index 55e4df1eed..3fb6e8140b 100644 --- a/polkadot/runtime/common/src/lib.rs +++ b/polkadot/runtime/common/src/lib.rs @@ -27,6 +27,7 @@ pub mod slots; pub mod crowdfund; pub mod purchase; pub mod impls; +pub mod paras_sudo_wrapper; use primitives::v0::BlockNumber; use sp_runtime::{Perquintill, Perbill, FixedPointNumber, traits::Saturating}; diff --git a/polkadot/runtime/common/src/paras_sudo_wrapper.rs b/polkadot/runtime/common/src/paras_sudo_wrapper.rs new file mode 100644 index 0000000000..e1e1ccae09 --- /dev/null +++ b/polkadot/runtime/common/src/paras_sudo_wrapper.rs @@ -0,0 +1,63 @@ +// Copyright 2020 Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot 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. + +// Polkadot 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 Polkadot. If not, see . + +//! A simple wrapper allowing `Sudo` to call into `paras` routines. + +use frame_support::{ + decl_error, decl_module, + dispatch::DispatchResult, + weights::DispatchClass, +}; +use system::ensure_root; +use runtime_parachains::paras::{ + self, + ParaGenesisArgs, +}; +use primitives::v1::Id as ParaId; + +/// The module's configuration trait. +pub trait Trait: paras::Trait { } + +decl_error! { + pub enum Error for Module { } +} + +decl_module! { + /// A sudo wrapper to call into v1 paras module. + pub struct Module for enum Call where origin: ::Origin, system = system { + type Error = Error; + + /// Schedule a para to be initialized at the start of the next session. + #[weight = (1_000, DispatchClass::Operational)] + pub fn sudo_schedule_para_initialize( + origin, + id: ParaId, + genesis: ParaGenesisArgs, + ) -> DispatchResult { + ensure_root(origin)?; + paras::Module::::schedule_para_initialize(id, genesis); + Ok(()) + } + + /// Schedule a para to be cleaned up at the start of the next session. + #[weight = (1_000, DispatchClass::Operational)] + pub fn sudo_schedule_para_cleanup(origin, id: ParaId) -> DispatchResult { + ensure_root(origin)?; + paras::Module::::schedule_para_cleanup(id); + Ok(()) + } + } +} diff --git a/polkadot/runtime/parachains/src/paras.rs b/polkadot/runtime/parachains/src/paras.rs index 4c628818a6..15e69bde6d 100644 --- a/polkadot/runtime/parachains/src/paras.rs +++ b/polkadot/runtime/parachains/src/paras.rs @@ -36,6 +36,7 @@ use frame_support::{ }; use codec::{Encode, Decode}; use crate::{configuration, initializer::SessionChangeNotification}; +use sp_core::RuntimeDebug; #[cfg(feature = "std")] use serde::{Serialize, Deserialize}; @@ -155,7 +156,7 @@ impl ParaPastCodeMeta { } /// Arguments for initializing a para. -#[derive(Encode, Decode)] +#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] pub struct ParaGenesisArgs { /// The initial head data to use. @@ -387,8 +388,7 @@ impl Module { } /// Schedule a para to be initialized at the start of the next session. - #[allow(unused)] - pub(crate) fn schedule_para_initialize(id: ParaId, genesis: ParaGenesisArgs) -> Weight { + pub fn schedule_para_initialize(id: ParaId, genesis: ParaGenesisArgs) -> Weight { let dup = UpcomingParas::mutate(|v| { match v.binary_search(&id) { Ok(_) => true, @@ -410,8 +410,7 @@ impl Module { } /// Schedule a para to be cleaned up at the start of the next session. - #[allow(unused)] - pub(crate) fn schedule_para_cleanup(id: ParaId) -> Weight { + pub fn schedule_para_cleanup(id: ParaId) -> Weight { OutgoingParas::mutate(|v| { match v.binary_search(&id) { Ok(_) => T::DbWeight::get().reads_writes(1, 0), diff --git a/polkadot/runtime/rococo-v1/src/lib.rs b/polkadot/runtime/rococo-v1/src/lib.rs index 7ca90c0399..d7df68199d 100644 --- a/polkadot/runtime/rococo-v1/src/lib.rs +++ b/polkadot/runtime/rococo-v1/src/lib.rs @@ -61,6 +61,7 @@ use sp_core::OpaqueMetadata; use sp_staking::SessionIndex; use session::historical as session_historical; use system::EnsureRoot; +use runtime_common::paras_sudo_wrapper as paras_sudo_wrapper; use runtime_parachains::configuration as parachains_configuration; use runtime_parachains::inclusion as parachains_inclusion; @@ -369,6 +370,8 @@ construct_runtime! { Scheduler: parachains_scheduler::{Module, Call, Storage}, Paras: parachains_paras::{Module, Call, Storage}, Initializer: parachains_initializer::{Module, Call, Storage}, + + ParasSudoWrapper: paras_sudo_wrapper::{Module, Call}, } } @@ -722,3 +725,5 @@ impl parachains_scheduler::Trait for Runtime { } impl parachains_initializer::Trait for Runtime { type Randomness = Babe; } + +impl paras_sudo_wrapper::Trait for Runtime { }