Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions runtime/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
63 changes: 63 additions & 0 deletions runtime/common/src/paras_sudo_wrapper.rs
Original file line number Diff line number Diff line change
@@ -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 <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(())
}
}
}
9 changes: 4 additions & 5 deletions runtime/parachains/src/paras.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand All @@ -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),
Expand Down
5 changes: 5 additions & 0 deletions runtime/rococo-v1/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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},
}
}

Expand Down Expand Up @@ -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 { }