DMP Queue pallet (#416)

* 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

* Rococo Collator supports Shell runtime

* Fixes

* Fixes

* Initial draft of DMP Queue pallet

* DMP Queue builds.

* Companion for Polkadot gav-allow-xcm-exec

* Bump

* Fix std

* Fixes

* fix and improve docs

* fix compile errors in tests

* add test for try_service_message

* update cargo.lock

* Fixes

* Make test name read well

* Fixes

* Add a couple of simple tests

* Tests

* Tests

* Update pallets/dmp-queue/src/lib.rs

Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>

* Update pallets/dmp-queue/src/lib.rs

Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>

* Update pallets/dmp-queue/src/lib.rs

Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>

* Update pallets/dmp-queue/src/lib.rs

Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>

* Update pallets/dmp-queue/src/lib.rs

Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>

* Update pallets/dmp-queue/src/lib.rs

Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>

* Update pallets/dmp-queue/src/lib.rs

Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>

* Chain ID and ParaID don't collide

* Fixes

* Update pallets/dmp-queue/src/lib.rs

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>

* Update pallets/dmp-queue/src/lib.rs

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>

* Fixes

Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>
Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
Gavin Wood
2021-05-02 16:11:58 +02:00
committed by GitHub
parent 67102885dd
commit dd5ad841a0
14 changed files with 1279 additions and 369 deletions
@@ -38,6 +38,7 @@ pallet-transaction-payment = { git = "https://github.com/paritytech/substrate",
cumulus-pallet-parachain-system = { path = "../../pallets/parachain-system", default-features = false }
cumulus-primitives-core = { path = "../../primitives/core", default-features = false }
cumulus-primitives-utility = { path = "../../primitives/utility", default-features = false }
cumulus-pallet-dmp-queue = { path = "../../pallets/dmp-queue", default-features = false }
cumulus-pallet-xcmp-queue = { path = "../../pallets/xcmp-queue", default-features = false }
cumulus-pallet-xcm = { path = "../../pallets/xcm", default-features = false }
cumulus-ping = { path = "../../rococo-parachains/pallets/ping", default-features = false }
@@ -84,6 +85,7 @@ std = [
"pallet-transaction-payment/std",
"parachain-info/std",
"rococo-parachain-primitives/std",
"cumulus-pallet-dmp-queue/std",
"cumulus-pallet-parachain-system/std",
"cumulus-pallet-xcmp-queue/std",
"cumulus-pallet-xcm/std",
+33 -10
View File
@@ -39,7 +39,7 @@ use sp_version::RuntimeVersion;
// A few exports that help ease life for downstream crates.
pub use frame_support::{
construct_runtime, parameter_types, match_type,
traits::{Randomness, IsInVec, All},
traits::{Randomness, IsInVec},
weights::{
constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},
DispatchClass, IdentityFee, Weight,
@@ -65,6 +65,8 @@ use xcm_builder::{
};
use xcm_executor::{Config, XcmExecutor};
use pallet_xcm::{XcmPassthrough, EnsureXcm, IsMajorityOfBody};
use xcm::v0::Xcm;
use frame_support::traits::Contains;
pub type SessionHandlers = ();
@@ -77,7 +79,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("test-parachain"),
impl_name: create_runtime_str!("test-parachain"),
authoring_version: 1,
spec_version: 9,
spec_version: 11,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
@@ -230,14 +232,16 @@ impl pallet_sudo::Config for Runtime {
parameter_types! {
pub const ReservedXcmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT / 4;
pub const ReservedDmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT / 4;
}
impl cumulus_pallet_parachain_system::Config for Runtime {
type Event = Event;
type OnValidationData = ();
type SelfParaId = parachain_info::Module<Runtime>;
type DownwardMessageHandlers = CumulusXcm;
type OutboundXcmpMessageSource = XcmpQueue;
type DmpMessageHandler = DmpQueue;
type ReservedDmpWeight = ReservedDmpWeight;
type XcmpMessageHandler = XcmpQueue;
type ReservedXcmpWeight = ReservedXcmpWeight;
}
@@ -335,10 +339,6 @@ impl Config for XcmConfig {
type ResponseHandler = (); // Don't handle responses for now.
}
parameter_types! {
pub const MaxDownwardMessageWeight: Weight = MAXIMUM_BLOCK_WEIGHT / 10;
}
/// No local origins on this chain are allowed to dispatch XCM sends/executions.
pub type LocalOriginToLocation = ();
@@ -351,19 +351,25 @@ pub type XcmRouter = (
XcmpQueue,
);
// TODO: Remove to frame_support::traits::All once substrate/8691 merged and bumped
/// A `Contains` implementation which always returns `true`.
pub struct All<T>(sp_std::marker::PhantomData<T>);
impl<T> Contains<T> for All<T> {
fn contains(_: &T) -> bool { true }
}
impl pallet_xcm::Config for Runtime {
type Event = Event;
type SendXcmOrigin = EnsureXcmOrigin<Origin, LocalOriginToLocation>;
type XcmRouter = XcmRouter;
type ExecuteXcmOrigin = EnsureXcmOrigin<Origin, LocalOriginToLocation>;
type XcmExecuteFilter = All<(MultiLocation, xcm::v0::Xcm<Call>)>;
type XcmExecuteFilter = All<(MultiLocation, Xcm<Call>)>;
type XcmExecutor = XcmExecutor<XcmConfig>;
}
impl cumulus_pallet_xcm::Config for Runtime {
type Event = Event;
type XcmExecutor = XcmExecutor<XcmConfig>;
type MaxWeight = MaxDownwardMessageWeight;
}
impl cumulus_pallet_xcmp_queue::Config for Runtime {
@@ -372,6 +378,12 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime {
type ChannelInfo = ParachainSystem;
}
impl cumulus_pallet_dmp_queue::Config for Runtime {
type Event = Event;
type XcmExecutor = XcmExecutor<XcmConfig>;
type ExecuteOverweightOrigin = frame_system::EnsureRoot<AccountId>;
}
impl cumulus_ping::Config for Runtime {
type Event = Event;
type Origin = Origin;
@@ -407,6 +419,16 @@ impl pallet_assets::Config for Runtime {
type WeightInfo = pallet_assets::weights::SubstrateWeight<Runtime>;
}
#[test]
fn encode_call() {
let hash = hex_literal::hex!["0af9fef6f950ca3ac8ac4766200454b1039ffb7b2d0827fffd5e47bd43761437"].into();
let call = Call::ParachainSystem(cumulus_pallet_parachain_system::Call::authorize_upgrade(hash));
assert_eq!(
hex::encode(codec::Encode::encode(&call)),
"14030af9fef6f950ca3ac8ac4766200454b1039ffb7b2d0827fffd5e47bd43761437",
);
}
construct_runtime! {
pub enum Runtime where
Block = Block,
@@ -419,7 +441,7 @@ construct_runtime! {
RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Call, Storage},
TransactionPayment: pallet_transaction_payment::{Pallet, Storage},
ParachainSystem: cumulus_pallet_parachain_system::{Pallet, Call, Storage, Inherent, Event<T>} = 20,
ParachainSystem: cumulus_pallet_parachain_system::{Pallet, Call, Storage, Inherent, Event<T>, ValidateUnsigned} = 20,
ParachainInfo: parachain_info::{Pallet, Storage, Config} = 21,
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>} = 30,
@@ -429,6 +451,7 @@ construct_runtime! {
XcmpQueue: cumulus_pallet_xcmp_queue::{Pallet, Call, Storage, Event<T>} = 50,
PolkadotXcm: pallet_xcm::{Pallet, Call, Event<T>, Origin} = 51,
CumulusXcm: cumulus_pallet_xcm::{Pallet, Call, Event<T>, Origin} = 52,
DmpQueue: cumulus_pallet_dmp_queue::{Pallet, Call, Storage, Event<T>} = 53,
Spambot: cumulus_ping::{Pallet, Call, Storage, Event<T>} = 99,
}
@@ -32,7 +32,7 @@ frame-system = { git = "https://github.com/paritytech/substrate", default-featur
cumulus-pallet-parachain-system = { path = "../../pallets/parachain-system", default-features = false }
cumulus-primitives-core = { path = "../../primitives/core", default-features = false }
cumulus-primitives-utility = { path = "../../primitives/utility", default-features = false }
cumulus-pallet-xcmp-queue = { path = "../../pallets/xcmp-queue", default-features = false }
cumulus-pallet-dmp-queue = { path = "../../pallets/dmp-queue", default-features = false }
cumulus-pallet-xcm = { path = "../../pallets/xcm", default-features = false }
# Polkadot dependencies
@@ -71,7 +71,7 @@ std = [
"parachain-info/std",
"rococo-parachain-primitives/std",
"cumulus-pallet-parachain-system/std",
"cumulus-pallet-xcmp-queue/std",
"cumulus-pallet-dmp-queue/std",
"cumulus-pallet-xcm/std",
"cumulus-primitives-core/std",
"cumulus-primitives-utility/std",
@@ -155,15 +155,16 @@ impl frame_system::Config for Runtime {
parameter_types! {
// We do anything the parent chain tells us in this runtime.
pub const ReservedDmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT;
pub const ReservedDmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT / 2;
}
impl cumulus_pallet_parachain_system::Config for Runtime {
type Event = Event;
type OnValidationData = ();
type SelfParaId = parachain_info::Module<Runtime>;
type DownwardMessageHandlers = CumulusXcm;
type OutboundXcmpMessageSource = ();
type DmpMessageHandler = cumulus_pallet_xcm::UnlimitedDmpExecution<Runtime>;
type ReservedDmpWeight = ReservedDmpWeight;
type XcmpMessageHandler = ();
type ReservedXcmpWeight = ();
}
@@ -198,16 +199,6 @@ parameter_types! {
pub UnitWeightCost: Weight = 1_000_000;
}
pub struct NoTrader;
impl xcm_executor::traits::WeightTrader for NoTrader {
fn new() -> Self { NoTrader }
fn buy_weight(&mut self, _: Weight, _: xcm_executor::Assets)
-> Result<xcm_executor::Assets, xcm::v0::Error>
{
Err(xcm::v0::Error::Unimplemented)
}
}
pub struct XcmConfig;
impl Config for XcmConfig {
type Call = Call;
@@ -219,18 +210,23 @@ impl Config for XcmConfig {
type LocationInverter = LocationInverter<Ancestry>;
type Barrier = AllowUnpaidExecutionFrom<JustTheParent>;
type Weigher = FixedWeightBounds<UnitWeightCost, Call>; // balances not supported
type Trader = NoTrader; // balances not supported
type Trader = (); // balances not supported
type ResponseHandler = (); // Don't handle responses for now.
}
parameter_types! {
pub const MaxDownwardMessageWeight: Weight = MAXIMUM_BLOCK_WEIGHT / 2;
}
impl cumulus_pallet_xcm::Config for Runtime {
type Event = Event;
type XcmExecutor = XcmExecutor<XcmConfig>;
type MaxWeight = MaxDownwardMessageWeight;
}
#[test]
fn encode_call() {
let hash = hex_literal::hex!["0af9fef6f950ca3ac8ac4766200454b1039ffb7b2d0827fffd5e47bd43761437"].into();
let call = Call::ParachainSystem(cumulus_pallet_parachain_system::Call::authorize_upgrade(hash));
assert_eq!(
hex::encode(codec::Encode::encode(&call)),
"01030af9fef6f950ca3ac8ac4766200454b1039ffb7b2d0827fffd5e47bd43761437",
);
}
construct_runtime! {