mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 07:01:03 +00:00
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:
@@ -471,7 +471,7 @@ impl<T: Config> Module<T> {
|
||||
assert_eq!(
|
||||
params.relay_parent_storage_root,
|
||||
validation_data.relay_parent_storage_root,
|
||||
"Relay parent stoarage root doesn't match",
|
||||
"Relay parent storage root doesn't match",
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -485,25 +485,38 @@ impl<T: Config> Module<T> {
|
||||
downward_messages: Vec<InboundDownwardMessage>,
|
||||
) -> Result<Weight, DispatchError> {
|
||||
let dm_count = downward_messages.len() as u32;
|
||||
|
||||
let mut weight_used = 0;
|
||||
|
||||
// Reference fu to avoid the `move` capture.
|
||||
let weight_used_mut_ref = &mut weight_used;
|
||||
let result_mqc_head = LastDmqMqcHead::mutate(move |mqc| {
|
||||
for downward_message in downward_messages {
|
||||
mqc.extend_downward(&downward_message);
|
||||
*weight_used_mut_ref += T::DownwardMessageHandlers::handle_downward_message(downward_message);
|
||||
}
|
||||
mqc.0
|
||||
});
|
||||
if dm_count != 0 {
|
||||
let mut processed_count = 0;
|
||||
|
||||
// After hashing each message in the message queue chain submitted by the collator, we should
|
||||
// arrive to the MQC head provided by the relay chain.
|
||||
ensure!(
|
||||
result_mqc_head == expected_dmq_mqc_head,
|
||||
Error::<T>::DmpMqcMismatch
|
||||
);
|
||||
Self::deposit_event(RawEvent::DownwardMessagesReceived(dm_count));
|
||||
|
||||
// Reference fu to avoid the `move` capture.
|
||||
let weight_used_ref = &mut weight_used;
|
||||
let processed_count_ref = &mut processed_count;
|
||||
let result_mqc_head = LastDmqMqcHead::mutate(move |mqc| {
|
||||
for downward_message in downward_messages {
|
||||
mqc.extend_downward(&downward_message);
|
||||
*weight_used_ref += T::DownwardMessageHandlers::handle_downward_message(downward_message);
|
||||
*processed_count_ref += 1;
|
||||
}
|
||||
mqc.0
|
||||
});
|
||||
|
||||
Self::deposit_event(RawEvent::DownwardMessagesProcessed(
|
||||
processed_count,
|
||||
weight_used,
|
||||
result_mqc_head.clone(),
|
||||
expected_dmq_mqc_head.clone(),
|
||||
));
|
||||
|
||||
// After hashing each message in the message queue chain submitted by the collator, we should
|
||||
// arrive to the MQC head provided by the relay chain.
|
||||
assert_eq!(result_mqc_head, expected_dmq_mqc_head);
|
||||
} else {
|
||||
assert_eq!(LastDmqMqcHead::get().0, expected_dmq_mqc_head);
|
||||
}
|
||||
|
||||
// Store the processed_downward_messages here so that it will be accessible from
|
||||
// PVF's `validate_block` wrapper and collation pipeline.
|
||||
@@ -791,12 +804,18 @@ impl<T: Config> ProvideInherent for Module<T> {
|
||||
|
||||
decl_event! {
|
||||
pub enum Event<T> where Hash = <T as frame_system::Config>::Hash {
|
||||
// The validation function has been scheduled to apply as of the contained relay chain block number.
|
||||
/// The validation function has been scheduled to apply as of the contained relay chain block number.
|
||||
ValidationFunctionStored(RelayChainBlockNumber),
|
||||
// The validation function was applied as of the contained relay chain block number.
|
||||
/// The validation function was applied as of the contained relay chain block number.
|
||||
ValidationFunctionApplied(RelayChainBlockNumber),
|
||||
// An upgrade has been authorized.
|
||||
/// An upgrade has been authorized.
|
||||
UpgradeAuthorized(Hash),
|
||||
/// Downward messages were processed using the given weight.
|
||||
/// \[ count, weight_used, result_mqc_head, expected_mqc_head \]
|
||||
DownwardMessagesProcessed(u32, Weight, relay_chain::Hash, relay_chain::Hash),
|
||||
/// Some downward messages have been received and will be processed.
|
||||
/// \[ count \]
|
||||
DownwardMessagesReceived(u32),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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" }
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user