Integrate a governance XCM origin (#407)

* Introduce the converter into the hub

* Parachain recognises Rococo governance body as admin

* Whitespace

* Use UsingComponents for fee payment in XCM

* Fixes

* Fixes for XCM permissions

* Remove encode_call test

* Fixes

* Fixes

* Fixes
This commit is contained in:
Gavin Wood
2021-04-28 14:41:18 +02:00
committed by GitHub
parent b03d11b8e0
commit fc82a611ce
8 changed files with 235 additions and 98 deletions
+1
View File
@@ -9,6 +9,7 @@ codec = { package = "parity-scale-codec", version = "2.0.0", default-features =
serde = { version = "1.0.101", optional = true, features = ["derive"] }
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
sp-io = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
frame-support = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
frame-system = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
+59 -3
View File
@@ -20,13 +20,17 @@
#![cfg_attr(not(feature = "std"), no_std)]
use cumulus_primitives_core::ParaId;
use sp_std::convert::TryFrom;
use cumulus_primitives_core::{ParaId, DownwardMessageHandler, InboundDownwardMessage};
use codec::{Encode, Decode};
use sp_runtime::traits::BadOrigin;
use xcm::{VersionedXcm, v0::{Xcm, Junction, Outcome, ExecuteXcm}};
use frame_support::{traits::Get, dispatch::Weight};
pub use pallet::*;
#[frame_support::pallet]
pub mod pallet {
use super::*;
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
@@ -36,16 +40,68 @@ pub mod pallet {
/// The module configuration trait.
#[pallet::config]
pub trait Config: frame_system::Config {}
pub trait Config: frame_system::Config {
/// The overarching event type.
type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
type XcmExecutor: ExecuteXcm<Self::Call>;
#[pallet::constant]
type MaxWeight: Get<Weight>;
}
#[pallet::error]
pub enum Error<T> {}
pub enum Error<T> {
}
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
#[pallet::metadata(T::BlockNumber = "BlockNumber")]
pub enum Event<T: Config> {
/// Downward message is invalid XCM.
/// \[ id \]
InvalidFormat([u8; 8]),
/// Downward message is unsupported version of XCM.
/// \[ id \]
UnsupportedVersion([u8; 8]),
/// Downward message executed with the given outcome.
/// \[ id, outcome \]
ExecutedDownward([u8; 8], Outcome),
}
/// For an incoming downward message, this just adapts an XCM executor and executes DMP messages
/// immediately up until some `MaxWeight` at which point it errors. Their origin is asserted to be
/// the Parent location.
impl<T: Config> DownwardMessageHandler for Pallet<T> {
fn handle_downward_message(msg: InboundDownwardMessage) -> Weight {
let id = sp_io::hashing::twox_64(&msg.msg[..]);
let msg = VersionedXcm::<T::Call>::decode(&mut &msg.msg[..])
.map(Xcm::<T::Call>::try_from);
match msg {
Ok(Ok(x)) => {
let weight_limit = T::MaxWeight::get();
let outcome = T::XcmExecutor::execute_xcm(Junction::Parent.into(), x, weight_limit);
let weight_used = outcome.weight_used();
Self::deposit_event(Event::ExecutedDownward(id, outcome));
weight_used
}
Ok(Err(())) => {
Self::deposit_event(Event::UnsupportedVersion(id));
0
},
Err(_) => {
Self::deposit_event(Event::InvalidFormat(id));
0
},
}
}
}
}
/// Origin for the parachains module.