Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ decl_test_parachains! {
ParachainInfo: asset_hub_rococo_runtime::ParachainInfo,
MessageOrigin: cumulus_primitives_core::AggregateMessageOrigin,
DigestProvider: (),
AdditionalInherentCode: (),
},
pallets = {
PolkadotXcm: asset_hub_rococo_runtime::PolkadotXcm,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ decl_test_parachains! {
ParachainInfo: asset_hub_westend_runtime::ParachainInfo,
MessageOrigin: cumulus_primitives_core::AggregateMessageOrigin,
DigestProvider: (),
AdditionalInherentCode: (),
},
pallets = {
PolkadotXcm: asset_hub_westend_runtime::PolkadotXcm,
Expand Down
22 changes: 20 additions & 2 deletions cumulus/xcm/xcm-emulator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@ where
}
}

// Implement optional inherent code to be executed
// This will be executed after on-initialize and before on-finalize
pub trait AdditionalInherentCode {
fn on_new_block() -> DispatchResult {
Ok(())
}
}

impl AdditionalInherentCode for () {}

pub trait TestExt {
fn build_new_ext(storage: Storage) -> TestExternalities;
fn new_ext() -> TestExternalities;
Expand Down Expand Up @@ -269,6 +279,7 @@ pub trait Parachain: Chain {
type ParachainSystem;
type MessageProcessor: ProcessMessage + ServiceQueues;
type DigestProvider: Convert<BlockNumberFor<Self::Runtime>, Digest>;
type AdditionalInherentCode: AdditionalInherentCode;

fn init();

Expand Down Expand Up @@ -604,7 +615,8 @@ macro_rules! decl_test_parachains {
LocationToAccountId: $location_to_account:path,
ParachainInfo: $parachain_info:path,
MessageOrigin: $message_origin:path,
$( DigestProvider: $digest_provider:ty, )?
$( DigestProvider: $digest_provider:ty,)?
$( AdditionalInherentCode: $additional_inherent_code:ty,)?
},
pallets = {
$($pallet_name:ident: $pallet_path:path,)*
Expand Down Expand Up @@ -646,6 +658,7 @@ macro_rules! decl_test_parachains {
type ParachainInfo = $parachain_info;
type MessageProcessor = $crate::DefaultParaMessageProcessor<$name<N>, $message_origin>;
$crate::decl_test_parachains!(@inner_digest_provider $($digest_provider)?);
$crate::decl_test_parachains!(@inner_additional_inherent_code $($additional_inherent_code)?);

// We run an empty block during initialisation to open HRMP channels
// and have them ready for the next block
Expand All @@ -666,7 +679,7 @@ macro_rules! decl_test_parachains {

fn new_block() {
use $crate::{
Dispatchable, Chain, Convert, TestExt, Zero,
Dispatchable, Chain, Convert, TestExt, Zero, AdditionalInherentCode
};

let para_id = Self::para_id().into();
Expand Down Expand Up @@ -713,6 +726,9 @@ macro_rules! decl_test_parachains {
$crate::assert_ok!(
timestamp_set.dispatch(<Self as Chain>::RuntimeOrigin::none())
);
$crate::assert_ok!(
<Self as Parachain>::AdditionalInherentCode::on_new_block()
);
});
}

Expand Down Expand Up @@ -775,6 +791,8 @@ macro_rules! decl_test_parachains {
};
( @inner_digest_provider $digest_provider:ty ) => { type DigestProvider = $digest_provider; };
( @inner_digest_provider /* none */ ) => { type DigestProvider = (); };
( @inner_additional_inherent_code $additional_inherent_code:ty ) => { type AdditionalInherentCode = $additional_inherent_code; };
( @inner_additional_inherent_code /* none */ ) => { type AdditionalInherentCode = (); };
}

#[macro_export]
Expand Down
12 changes: 12 additions & 0 deletions prdoc/pr_8809.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
title: Add possibility of executing or mocking additional inherents in xcm-emulator
doc:
- audience: Runtime Dev
description: |-
With the addition of https://github.com/paritytech/polkadot-sdk/pull/8083 there is no possibility right now of making the xcm-executor work with custom inherents. Custom inherents are usually driven by killing a storage item of the form `wasInherentSet` `on_initialize` and asserting that such inherent was set `on_finalize`. Before the xcm-emulator worked as these hooks were running just for the ParachainSystem pallet, but now, they run for all pallets.

My proposal is to add an item to the xcm-emulator parachain configuration of the form `AdditionalInherentCode`, which simply executes code that returns a `DispatchResult`. Whether users want to mock a storage item or run the inherent is up to them, this hook would allow them to do both.

This item is optional, meaning that if it is non-set then it would do nothing
Comment thread
bkchr marked this conversation as resolved.
Outdated
crates:
- name: xcm-emulator
bump: major
Comment thread
bkchr marked this conversation as resolved.
Outdated