Unverified Commit a2b008dd authored by Fedor Sakharov's avatar Fedor Sakharov Committed by GitHub
Browse files

Sudo wrapper for paras (#1517)

* Sudo wrapper for paras

* Move to separate module

* Add some docs
parent b8d0c59b
Pipeline #102661 passed with stages
in 25 minutes and 47 seconds
......@@ -4945,6 +4945,7 @@ dependencies = [
"pallet-vesting",
"parity-scale-codec",
"polkadot-primitives",
"polkadot-runtime-parachains",
"rustc-hex",
"serde",
"serde_derive",
......
......@@ -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"
......
......@@ -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};
......
// 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 <http://www.gnu.org/licenses/>.
//! 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<T: Trait> { }
}
decl_module! {
/// A sudo wrapper to call into v1 paras module.
pub struct Module<T: Trait> for enum Call where origin: <T as system::Trait>::Origin, system = system {
type Error = Error<T>;
/// 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::<T>::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::<T>::schedule_para_cleanup(id);
Ok(())
}
}
}
......@@ -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<N: Ord + Copy> ParaPastCodeMeta<N> {
}
/// 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<T: Trait> Module<T> {
}
/// 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<T: Trait> Module<T> {
}
/// 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),
......
......@@ -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 { }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment