Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add digest processor xcm emulator #7915

Merged
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -42,6 +42,7 @@ decl_test_parachains! {
LocationToAccountId: asset_hub_rococo_runtime::xcm_config::LocationToAccountId,
ParachainInfo: asset_hub_rococo_runtime::ParachainInfo,
MessageOrigin: cumulus_primitives_core::AggregateMessageOrigin,
DigestProvider: (),
},
pallets = {
PolkadotXcm: asset_hub_rococo_runtime::PolkadotXcm,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ decl_test_parachains! {
LocationToAccountId: asset_hub_westend_runtime::xcm_config::LocationToAccountId,
ParachainInfo: asset_hub_westend_runtime::ParachainInfo,
MessageOrigin: cumulus_primitives_core::AggregateMessageOrigin,
DigestProvider: (),
},
pallets = {
PolkadotXcm: asset_hub_westend_runtime::PolkadotXcm,
Expand Down
17 changes: 12 additions & 5 deletions cumulus/xcm/xcm-emulator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ pub use cumulus_primitives_core::AggregateMessageOrigin as CumulusAggregateMessa
pub use frame_support::{
assert_ok,
sp_runtime::{
traits::{Dispatchable, Header as HeaderT},
DispatchResult,
traits::{Convert, Dispatchable, Header as HeaderT},
Digest, DispatchResult,
},
traits::{
EnqueueMessage, ExecuteOverweightError, Get, Hooks, OnInitialize, OriginTrait,
Expand Down Expand Up @@ -108,7 +108,6 @@ thread_local! {
/// Most recent `HeadData` of each parachain, encoded.
pub static LAST_HEAD: RefCell<HashMap<String, HashMap<u32, HeadData>>> = RefCell::new(HashMap::new());
}

pub trait CheckAssertion<Origin, Destination, Hops, Args>
where
Origin: Chain + Clone,
Expand Down Expand Up @@ -264,6 +263,7 @@ pub trait Parachain: Chain {
type ParachainInfo: Get<ParaId>;
type ParachainSystem;
type MessageProcessor: ProcessMessage + ServiceQueues;
type DigestProvider: sp_runtime::traits::Convert<BlockNumberFor<Self::Runtime>, Digest>;

fn init();

Expand Down Expand Up @@ -599,6 +599,7 @@ macro_rules! decl_test_parachains {
LocationToAccountId: $location_to_account:path,
ParachainInfo: $parachain_info:path,
MessageOrigin: $message_origin:path,
$( DigestProvider: $digest_provider:ty, )?
},
pallets = {
$($pallet_name:ident: $pallet_path:path,)*
Expand Down Expand Up @@ -639,6 +640,7 @@ macro_rules! decl_test_parachains {
type ParachainSystem = $crate::ParachainSystemPallet<<Self as $crate::Chain>::Runtime>;
type ParachainInfo = $parachain_info;
type MessageProcessor = $crate::DefaultParaMessageProcessor<$name<N>, $message_origin>;
$crate::decl_test_parachains!(@inner_digest_provider $($digest_provider)?);

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

fn new_block() {
use $crate::{Chain, HeadData, Network, Hooks, Encode, Parachain, TestExt};
use $crate::{Chain, Convert, HeadData, Network, Hooks, Encode, Parachain, TestExt};

let para_id = Self::para_id().into();

Expand All @@ -677,7 +679,10 @@ macro_rules! decl_test_parachains {
.expect("network not initialized?")
.clone()
);
<Self as Chain>::System::initialize(&block_number, &parent_head_data.hash(), &Default::default());

let digest = <Self as Parachain>::DigestProvider::convert(block_number);

<Self as Chain>::System::initialize(&block_number, &parent_head_data.hash(), &digest);
<<Self as Parachain>::ParachainSystem as Hooks<$crate::BlockNumberFor<Self::Runtime>>>::on_initialize(block_number);

let _ = <Self as Parachain>::ParachainSystem::set_validation_data(
Expand Down Expand Up @@ -734,6 +739,8 @@ macro_rules! decl_test_parachains {
$crate::__impl_check_assertion!($name, N);
)+
};
( @inner_digest_provider $digest_provider:ty ) => { type DigestProvider = $digest_provider; };
( @inner_digest_provider /* none */ ) => { type DigestProvider = (); };
}

#[macro_export]
Expand Down
Loading