Skip to content

Commit 4063357

Browse files
Add EmittedEvent
1 parent a14782e commit 4063357

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

polkadot/xcm/pallet-xcm/src/lib.rs

+23
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,9 @@ pub mod pallet {
846846
#[pallet::storage]
847847
pub(crate) type RecordedXcm<T: Config> = StorageValue<_, Xcm<()>>;
848848

849+
#[pallet::storage]
850+
pub(crate) type EmittedEvent<T: Config> = StorageValue<_, <T as frame_system::Config>::RuntimeEvent>;
851+
849852
#[pallet::genesis_config]
850853
pub struct GenesisConfig<T: Config> {
851854
#[serde(skip)]
@@ -2589,6 +2592,9 @@ impl<T: Config> Pallet<T> {
25892592

25902593
XcmDryRunApiError::VersionedConversionFailed
25912594
})?;
2595+
if let Some(failed_event) = Pallet::<Runtime>::emitted_event() {
2596+
tracing::debug!("Failed event: {:?}", failed_event);
2597+
}
25922598

25932599
// Should only get messages from this call since we cleared previous ones.
25942600
let forwarded_xcms =
@@ -3502,6 +3508,8 @@ impl<T: Config> CheckSuspension for Pallet<T> {
35023508
}
35033509

35043510
impl<T: Config> RecordXcm for Pallet<T> {
3511+
type RuntimeEvent = <T as frame_system::Config>::RuntimeEvent;
3512+
35053513
fn should_record() -> bool {
35063514
ShouldRecordXcm::<T>::get()
35073515
}
@@ -3517,6 +3525,21 @@ impl<T: Config> RecordXcm for Pallet<T> {
35173525
fn record(xcm: Xcm<()>) {
35183526
RecordedXcm::<T>::put(xcm);
35193527
}
3528+
3529+
fn record_last_event() {
3530+
let records = frame_system::Pallet::<T>::events();
3531+
if let Some(record) = records.last() {
3532+
let event = record.event.clone();
3533+
tracing::debug!("Record last event: {:?}", event);
3534+
EmittedEvent::<T>::put(event);
3535+
}
3536+
}
3537+
3538+
fn emitted_event() -> Option<Self::RuntimeEvent> {
3539+
let event = EmittedEvent::<T>::get();
3540+
tracing::debug!("Emitted event: {:?}", event);
3541+
event
3542+
}
35203543
}
35213544

35223545
/// Ensure that the origin `o` represents an XCM (`Transact`) origin.

polkadot/xcm/xcm-executor/src/lib.rs

+6
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,9 @@ impl<Config: config::Config> XcmExecutor<Config> {
459459
error.clone(),
460460
self.context.message_id,
461461
);
462+
if Config::XcmRecorder::should_record() {
463+
Config::XcmRecorder::record_last_event();
464+
}
462465
Err(error.into())
463466
},
464467
}
@@ -854,6 +857,9 @@ impl<Config: config::Config> XcmExecutor<Config> {
854857
error,
855858
self.context.message_id,
856859
);
860+
if Config::XcmRecorder::should_record() {
861+
Config::XcmRecorder::record_last_event();
862+
}
857863
*r = Err(ExecutorError {
858864
index: i as u32,
859865
xcm_error: error,

polkadot/xcm/xcm-executor/src/traits/record_xcm.rs

+12
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ use xcm::latest::Xcm;
2020

2121
/// Trait for recording XCMs.
2222
pub trait RecordXcm {
23+
type RuntimeEvent;
24+
2325
/// Whether or not we should record incoming XCMs.
2426
fn should_record() -> bool;
2527
/// Enable or disable recording.
@@ -29,9 +31,15 @@ pub trait RecordXcm {
2931
fn recorded_xcm() -> Option<Xcm<()>>;
3032
/// Record `xcm`.
3133
fn record(xcm: Xcm<()>);
34+
/// Record the last event.
35+
fn record_last_event();
36+
/// Get emitted events.
37+
fn emitted_event() -> Option<Self::RuntimeEvent>;
3238
}
3339

3440
impl RecordXcm for () {
41+
type RuntimeEvent = ();
42+
3543
fn should_record() -> bool {
3644
false
3745
}
@@ -43,4 +51,8 @@ impl RecordXcm for () {
4351
}
4452

4553
fn record(_: Xcm<()>) {}
54+
55+
fn record_last_event() {}
56+
57+
fn emitted_event() -> Option<Self::RuntimeEvent> { None }
4658
}

0 commit comments

Comments
 (0)