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 1 commit
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
Prev Previous commit
Next Next commit
Add comments, remove Event
  • Loading branch information
montekki committed Aug 11, 2020
commit cdcd8f0d48a0044eb4db605c17cd751c32ea22a8
44 changes: 25 additions & 19 deletions runtime/common/src/paras_registrar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

//! Module to handle parathread/parachain registration and related fund management.
//! In essence this is a simple wrapper around `paras`.

use sp_std::{prelude::*, result};

use frame_support::{
decl_storage, decl_module, decl_event, decl_error, ensure,
decl_storage, decl_module, decl_error, ensure,
dispatch::DispatchResult,
traits::{Get, Currency, ReservableCurrency},
weights::DispatchClass,
Expand All @@ -39,10 +42,10 @@ type BalanceOf<T> =
<<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::Balance;

pub trait Trait: paras::Trait {
/// The overarching event type.
type Event: From<Event> + Into<<Self as frame_system::Trait>::Event>;

/// The aggregated origin type.
/// The aggregated origin type must support the `parachains` origin. We require that we can
/// infallibly convert between this origin and the system origin, but in reality, they're the
/// same type, we just can't express that to the Rust type system without writing a `where`
/// clause everywhere.
type Origin: From<<Self as frame_system::Trait>::Origin>
+ Into<result::Result<Origin, <Self as Trait>::Origin>>;

Expand All @@ -53,16 +56,6 @@ pub trait Trait: paras::Trait {
type ParathreadDeposit: Get<BalanceOf<Self>>;
}

decl_event! {
pub enum Event {
/// A parathread was registered; its new ID is supplied.
ParathreadRegistered(ParaId),

/// The parathread of the supplied ID was de-registered.
ParathreadDeregistered(ParaId),
}
}

decl_storage! {
trait Store for Module<T: Trait> as Registrar {
/// Pending swap operations.
Expand Down Expand Up @@ -95,6 +88,10 @@ decl_module! {
pub struct Module<T: Trait> for enum Call where origin: <T as frame_system::Trait>::Origin {
type Error = Error<T>;

/// Register a parathread with given code for immediate use.
///
/// Must be sent from a Signed origin that is able to have `ParathreadDeposit` reserved.
/// `gensis_head` and `validation_code` are used to initalize the parathread's state.
#[weight = (5_000_000_000, DispatchClass::Operational)]
pub fn register_parathread(
origin,
Expand Down Expand Up @@ -126,7 +123,9 @@ decl_module! {
Ok(())
}

#[weight = (10_000, DispatchClass::Operational)]
/// Register a parachain with given code. Must be called by root.
/// Fails if given ID is already used.
#[weight = (5_000_000_000, DispatchClass::Operational)]
pub fn register_parachain(
origin,
id: ParaId,
Expand Down Expand Up @@ -155,7 +154,8 @@ decl_module! {
Ok(())
}

#[weight = (10_000, DispatchClass::Operational)]
/// Deregister a parachain with the given ID. Must be called by root.
#[weight = (0, DispatchClass::Operational)]
pub fn deregister_parachain(origin, id: ParaId) -> DispatchResult {
ensure_root(origin)?;

Expand All @@ -168,7 +168,14 @@ decl_module! {
Ok(())
}

#[weight = (10_000_000, DispatchClass::Operational)]
/// Deregister a parathread and retreive the deposit.
///
/// Must be sent from a `Parachain` origin which is currently a parathread.
///
/// Ensure that before calling this that any funds you want emptied from the parathread's
/// account is moved out; after this it will be impossible to retreive them (without
/// governance intervention).
#[weight = (0, DispatchClass::Operational)]
pub fn deregister_parathread(origin) -> DispatchResult {
let id = ensure_parachain(<T as Trait>::Origin::from(origin))?;

Expand Down Expand Up @@ -473,7 +480,6 @@ mod tests {
}

impl Trait for Test {
type Event = ();
type Origin = Origin;
type Currency = pallet_balances::Module<Test>;
type ParathreadDeposit = ParathreadDeposit;
Expand Down
3 changes: 1 addition & 2 deletions runtime/rococo-v1/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ construct_runtime! {
Paras: parachains_paras::{Module, Call, Storage, Origin},
Initializer: parachains_initializer::{Module, Call, Storage},

Registrar: paras_registrar::{Module, Call, Storage, Event},
Registrar: paras_registrar::{Module, Call, Storage},
ParasSudoWrapper: paras_sudo_wrapper::{Module, Call},
}
}
Expand Down Expand Up @@ -733,7 +733,6 @@ impl parachains_initializer::Trait for Runtime {
impl paras_sudo_wrapper::Trait for Runtime { }

impl paras_registrar::Trait for Runtime {
type Event = Event;
type Currency = Balances;
type ParathreadDeposit = ParathreadDeposit;
type Origin = Origin;
Expand Down