Skip to content

Commit

Permalink
Merge branch 'master' into Optimist
Browse files Browse the repository at this point in the history
  • Loading branch information
ndkazu committed Sep 19, 2024
2 parents fb51be2 + b230b0e commit eef451c
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 10 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cumulus/xcm/xcm-emulator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ paste = { workspace = true, default-features = true }
log = { workspace = true }
lazy_static = { workspace = true }
impl-trait-for-tuples = { workspace = true }
array-bytes = { workspace = true }

# Substrate
frame-support = { workspace = true, default-features = true }
Expand Down
34 changes: 24 additions & 10 deletions cumulus/xcm/xcm-emulator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

extern crate alloc;

pub use array_bytes;
pub use codec::{Decode, Encode, EncodeLike, MaxEncodedLen};
pub use lazy_static::lazy_static;
pub use log;
Expand Down Expand Up @@ -526,7 +527,10 @@ macro_rules! __impl_test_ext_for_relay_chain {
<$network>::init();

// Execute
let r = $local_ext.with(|v| v.borrow_mut().execute_with(execute));
let r = $local_ext.with(|v| {
$crate::log::info!(target: "xcm::emulator::execute_with", "Executing as {}", stringify!($name));
v.borrow_mut().execute_with(execute)
});

// Send messages if needed
$local_ext.with(|v| {
Expand All @@ -550,7 +554,7 @@ macro_rules! __impl_test_ext_for_relay_chain {

// log events
Self::events().iter().for_each(|event| {
$crate::log::debug!(target: concat!("events::", stringify!($name)), "{:?}", event);
$crate::log::info!(target: concat!("events::", stringify!($name)), "{:?}", event);
});

// clean events
Expand Down Expand Up @@ -826,7 +830,10 @@ macro_rules! __impl_test_ext_for_parachain {
Self::new_block();

// Execute
let r = $local_ext.with(|v| v.borrow_mut().execute_with(execute));
let r = $local_ext.with(|v| {
$crate::log::info!(target: "xcm::emulator::execute_with", "Executing as {}", stringify!($name));
v.borrow_mut().execute_with(execute)
});

// Finalize the block
Self::finalize_block();
Expand Down Expand Up @@ -872,7 +879,7 @@ macro_rules! __impl_test_ext_for_parachain {

// log events
<Self as $crate::Chain>::events().iter().for_each(|event| {
$crate::log::debug!(target: concat!("events::", stringify!($name)), "{:?}", event);
$crate::log::info!(target: concat!("events::", stringify!($name)), "{:?}", event);
});

// clean events
Expand Down Expand Up @@ -1024,7 +1031,10 @@ macro_rules! decl_test_networks {
&mut msg.using_encoded($crate::blake2_256),
);
});
$crate::log::debug!(target: concat!("dmp::", stringify!($name)) , "DMP messages processed {:?} to para_id {:?}", msgs.clone(), &to_para_id);
let messages = msgs.clone().iter().map(|(block, message)| {
(*block, $crate::array_bytes::bytes2hex("0x", message))
}).collect::<Vec<_>>();
$crate::log::info!(target: concat!("xcm::dmp::", stringify!($name)) , "Downward messages processed by para_id {:?}: {:?}", &to_para_id, messages);
$crate::DMP_DONE.with(|b| b.borrow_mut().get_mut(Self::name()).unwrap().push_back((to_para_id, block, msg)));
}
}
Expand All @@ -1037,7 +1047,7 @@ macro_rules! decl_test_networks {

while let Some((to_para_id, messages))
= $crate::HORIZONTAL_MESSAGES.with(|b| b.borrow_mut().get_mut(Self::name()).unwrap().pop_front()) {
let iter = messages.iter().map(|(p, b, m)| (*p, *b, &m[..])).collect::<Vec<_>>().into_iter();
let iter = messages.iter().map(|(para_id, relay_block_number, message)| (*para_id, *relay_block_number, &message[..])).collect::<Vec<_>>().into_iter();
$(
let para_id: u32 = <$parachain<Self>>::para_id().into();

Expand All @@ -1047,7 +1057,10 @@ macro_rules! decl_test_networks {
// Nudge the MQ pallet to process immediately instead of in the next block.
let _ = <$parachain<Self> as Parachain>::MessageProcessor::service_queues($crate::Weight::MAX);
});
$crate::log::debug!(target: concat!("hrmp::", stringify!($name)) , "HRMP messages processed {:?} to para_id {:?}", &messages, &to_para_id);
let messages = messages.clone().iter().map(|(para_id, relay_block_number, message)| {
(*para_id, *relay_block_number, $crate::array_bytes::bytes2hex("0x", message))
}).collect::<Vec<_>>();
$crate::log::info!(target: concat!("xcm::hrmp::", stringify!($name)), "Horizontal messages processed by para_id {:?}: {:?}", &to_para_id, &messages);
}
)*
}
Expand All @@ -1066,7 +1079,8 @@ macro_rules! decl_test_networks {
&mut msg.using_encoded($crate::blake2_256),
);
});
$crate::log::debug!(target: concat!("ump::", stringify!($name)) , "Upward message processed {:?} from para_id {:?}", &msg, &from_para_id);
let message = $crate::array_bytes::bytes2hex("0x", msg.clone());
$crate::log::info!(target: concat!("xcm::ump::", stringify!($name)) , "Upward message processed from para_id {:?}: {:?}", &from_para_id, &message);
}
}

Expand All @@ -1086,7 +1100,7 @@ macro_rules! decl_test_networks {
<<Self::Bridge as Bridge>::Source as TestExt>::ext_wrapper(|| {
<<Self::Bridge as Bridge>::Handler as BridgeMessageHandler>::notify_source_message_delivery(msg.lane_id.clone());
});
$crate::log::debug!(target: concat!("bridge::", stringify!($name)) , "Bridged message processed {:?}", msg);
$crate::log::info!(target: concat!("bridge::", stringify!($name)) , "Bridged message processed {:?}", msg);
}
}
}
Expand Down Expand Up @@ -1297,7 +1311,7 @@ macro_rules! assert_expected_events {
if !message.is_empty() {
// Log events as they will not be logged after the panic
<$chain as $crate::Chain>::events().iter().for_each(|event| {
$crate::log::debug!(target: concat!("events::", stringify!($chain)), "{:?}", event);
$crate::log::info!(target: concat!("events::", stringify!($chain)), "{:?}", event);
});
panic!("{}", message.concat())
}
Expand Down
18 changes: 18 additions & 0 deletions prdoc/pr_5712.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json

title: Better logs for XCM emulator

doc:
- audience: Runtime Dev
description: |
Now the XCM emulator has a log every time `execute_with` is called, to know
which chain is being used.
Also, the logs for UMP, DMP, HRMP processing were included in the `xcm` log filter
and changed from showing the message as an array of bytes to a hex string.
This means running the tests with `RUST_LOG=xcm` should give you everything you need,
you can always filter by `RUST_LOG=xcm::hrmp` or any other if you need it.

crates:
- name: xcm-emulator
bump: patch

0 comments on commit eef451c

Please sign in to comment.