Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
d045373
feat: add event emitter to xcm executor config and emit sent event on…
jpserrat Jan 18, 2025
2cece4e
Merge branch 'master' of github.com:paritytech/polkadot-sdk into jpse…
jpserrat Jan 18, 2025
4ecc682
feat: send failure events and add doc to event emiter
jpserrat Feb 12, 2025
fae11c8
refact: change tracing log to occur before sending event for xcm::exe…
jpserrat Feb 13, 2025
2f1b65f
Merge branch 'master' of github.com:paritytech/polkadot-sdk into jpse…
jpserrat Feb 13, 2025
840fc9b
feat: add message hash to the event failures
jpserrat Feb 18, 2025
65061ea
Merge branch 'master' of github.com:paritytech/polkadot-sdk into jpse…
jpserrat Feb 18, 2025
b897548
Update polkadot/xcm/xcm-executor/src/traits/event_emitter.rs
raymondkfcheung Feb 27, 2025
f907e5d
Update polkadot/xcm/pallet-xcm/src/lib.rs
raymondkfcheung Feb 27, 2025
e505c76
Update polkadot/xcm/pallet-xcm/src/lib.rs
raymondkfcheung Feb 27, 2025
e128e27
Update polkadot/xcm/xcm-executor/src/traits/event_emitter.rs
raymondkfcheung Feb 27, 2025
5d406d8
Fix conflict
raymondkfcheung Feb 27, 2025
6e18c46
Merge branch 'master' into jpserrat-add-sent-event
raymondkfcheung Feb 27, 2025
ce5d746
Update from raymondkfcheung running command 'fmt'
github-actions[bot] Feb 27, 2025
b78317d
Update from raymondkfcheung running command 'prdoc --audience runtime…
github-actions[bot] Feb 27, 2025
dd5a7de
Update PR Doc
raymondkfcheung Feb 27, 2025
56d500e
Fix bugs
raymondkfcheung Feb 27, 2025
b5db8d5
Update docs
raymondkfcheung Feb 27, 2025
ab43058
Avoid logging the full XCM message to prevent inconsistencies and red…
raymondkfcheung Feb 27, 2025
657ebc0
Fix bugs
raymondkfcheung Feb 27, 2025
9409209
Update emit_sent_event
raymondkfcheung Feb 27, 2025
87c287f
Refactor emit_sent_event
raymondkfcheung Feb 27, 2025
59dd8a3
Merge branch 'master' into jpserrat/add-sent-event
raymondkfcheung Feb 27, 2025
fdccc61
Fix bugs
raymondkfcheung Feb 27, 2025
766bb23
Update emit_sent_event
raymondkfcheung Feb 27, 2025
948f851
Update comments
raymondkfcheung Feb 27, 2025
1a38fa1
Fix bugs
raymondkfcheung Feb 27, 2025
5a50a8d
Update from raymondkfcheung running command 'fmt'
github-actions[bot] Feb 27, 2025
897bff7
Merge branch 'master' into jpserrat/add-sent-event
raymondkfcheung Feb 28, 2025
f592fca
Fix tests
raymondkfcheung Feb 28, 2025
5a0d383
Fix bugs
raymondkfcheung Feb 28, 2025
fb2f40f
Add init_log_capture_for_tests
raymondkfcheung Feb 28, 2025
32159d5
Update PR Doc
raymondkfcheung Feb 28, 2025
d4b3067
Merge branch 'master' into jpserrat/add-sent-event
raymondkfcheung Feb 28, 2025
71f1cd6
Update from raymondkfcheung running command 'fmt'
github-actions[bot] Feb 28, 2025
bc14b1c
Remove unused import
raymondkfcheung Feb 28, 2025
a919206
Add debug log
raymondkfcheung Mar 3, 2025
6f54c39
Add similar functions
raymondkfcheung Mar 3, 2025
507778f
Update comments
raymondkfcheung Mar 3, 2025
b214336
Update comments
raymondkfcheung Mar 3, 2025
76c2734
Merge branch 'master' into jpserrat/add-sent-event
raymondkfcheung Mar 3, 2025
023cb52
Update doc links
raymondkfcheung Mar 3, 2025
a522a80
Merge branch 'master' into jpserrat/add-sent-event
raymondkfcheung Mar 3, 2025
6d9a3c5
Merge branch 'master' into jpserrat/add-sent-event
raymondkfcheung Mar 3, 2025
f3657c7
Merge branch 'master' into jpserrat/add-sent-event
raymondkfcheung Mar 3, 2025
b5c5f3c
Fix tests
raymondkfcheung Mar 3, 2025
be2f75a
Fix format
raymondkfcheung Mar 3, 2025
7274176
Merge branch 'master' into jpserrat/add-sent-event
raymondkfcheung Mar 3, 2025
0e3661e
Fix tests
raymondkfcheung Mar 3, 2025
375b87f
Fix tests
raymondkfcheung Mar 3, 2025
9db8239
Merge branch 'master' into jpserrat/add-sent-event
raymondkfcheung Mar 4, 2025
a95ed5e
Merge branch 'master' into jpserrat/add-sent-event
raymondkfcheung Mar 4, 2025
2a49755
Rename variables
raymondkfcheung Mar 4, 2025
f67af1e
Assert emit_process_failure_event
raymondkfcheung Mar 4, 2025
83a326e
Update log message
raymondkfcheung Mar 4, 2025
8734178
Update log level
raymondkfcheung Mar 4, 2025
54124d3
Merge branch 'master' into jpserrat/add-sent-event
raymondkfcheung Mar 4, 2025
2abf83f
Update polkadot/xcm/pallet-xcm/src/lib.rs
raymondkfcheung Mar 4, 2025
e1be968
Update polkadot/xcm/pallet-xcm/src/lib.rs
raymondkfcheung Mar 4, 2025
ccfabf6
Add missing XcmEventEmitter
raymondkfcheung Mar 4, 2025
3d2d8d5
Add xcm-simulator-fuzzer
raymondkfcheung Mar 4, 2025
1258918
Add sp_tracing::init_for_tests()
raymondkfcheung Mar 4, 2025
d16e6e4
Sync with #7769
raymondkfcheung Mar 5, 2025
66523c3
FIx with init_log_capture
raymondkfcheung Mar 5, 2025
f3c4513
Remove clone
raymondkfcheung Mar 5, 2025
ef7c150
Update PR Doc
raymondkfcheung Mar 5, 2025
07854e8
Update PR Doc
raymondkfcheung Mar 5, 2025
29207c4
Merge branch 'master' into jpserrat/add-sent-event
raymondkfcheung Mar 5, 2025
4fd304f
Merge branch 'master' into jpserrat/add-sent-event
raymondkfcheung Mar 5, 2025
235ce5f
Fix conflicts
raymondkfcheung Mar 5, 2025
bb31ef7
Test Sent event
raymondkfcheung Mar 5, 2025
43dc292
Assert logs
raymondkfcheung Mar 6, 2025
1746618
Remove sp_tracing::init_for_tests()
raymondkfcheung Mar 6, 2025
3056abc
Remove println
raymondkfcheung Mar 6, 2025
848efa8
Fix tests
raymondkfcheung Mar 6, 2025
7db071f
Test emit_send_failure_event()
raymondkfcheung Mar 6, 2025
459c85d
Fxi tests
raymondkfcheung Mar 6, 2025
d22491e
Merge branch 'master' into jpserrat/add-sent-event
raymondkfcheung Mar 6, 2025
94659c2
Update PR Doc
raymondkfcheung Mar 6, 2025
d0e60a9
Update PR Doc
raymondkfcheung Mar 6, 2025
076023d
Update from raymondkfcheung running command 'prdoc --force --audience…
github-actions[bot] Mar 6, 2025
c1514cc
Update PR Doc
raymondkfcheung Mar 6, 2025
4229dbc
Merge branch 'master' into jpserrat/add-sent-event
raymondkfcheung Mar 7, 2025
7d0d4a5
Add delay
raymondkfcheung Mar 7, 2025
8daa51e
Merge branch 'master' into jpserrat-add-sent-event
raymondkfcheung Mar 7, 2025
d50af4d
Add delay
raymondkfcheung Mar 7, 2025
e8f4b18
Capture info
raymondkfcheung Mar 7, 2025
d9b3b83
Remove delay
raymondkfcheung Mar 10, 2025
cf72077
Merge branch 'master' into jpserrat-add-sent-event
raymondkfcheung Mar 10, 2025
2fa8a95
Remove capture_test_logs
raymondkfcheung Mar 10, 2025
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
1 change: 1 addition & 0 deletions bridges/modules/xcm-bridge-hub/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
type RuntimeCall = RuntimeCall;
type XcmSender = ();
type XcmEventEmitter = ();
type AssetTransactor = ();
type OriginConverter = BridgeHubLocationXcmOriginAsRoot<RuntimeOrigin>;
type IsReserve = ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
type RuntimeCall = RuntimeCall;
type XcmSender = XcmRouter;
type XcmEventEmitter = PolkadotXcm;
type AssetTransactor = AssetTransactors;
type OriginConverter = XcmOriginToTransactDispatchOrigin;
// Asset Hub trusts only particular, pre-configured bridged locations from a different consensus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
type RuntimeCall = RuntimeCall;
type XcmSender = XcmRouter;
type XcmEventEmitter = PolkadotXcm;
type AssetTransactor = AssetTransactors;
type OriginConverter = XcmOriginToTransactDispatchOrigin;
// Asset Hub trusts only particular, pre-configured bridged locations from a different consensus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
type RuntimeCall = RuntimeCall;
type XcmSender = XcmRouter;
type XcmEventEmitter = PolkadotXcm;
type AssetTransactor = FungibleTransactor;
type OriginConverter = XcmOriginToTransactDispatchOrigin;
// BridgeHub does not recognize a reserve location for any asset. Users must teleport Native
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
type RuntimeCall = RuntimeCall;
type XcmSender = XcmRouter;
type XcmEventEmitter = PolkadotXcm;
type AssetTransactor = FungibleTransactor;
type OriginConverter = XcmOriginToTransactDispatchOrigin;
// BridgeHub does not recognize a reserve location for any asset. Users must teleport Native
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
type RuntimeCall = RuntimeCall;
type XcmSender = XcmRouter;
type XcmEventEmitter = PolkadotXcm;
type AssetTransactor = FungibleTransactor;
type OriginConverter = XcmOriginToTransactDispatchOrigin;
// Collectives does not recognize a reserve location for any asset. Users must teleport WND
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
type RuntimeCall = RuntimeCall;
type XcmSender = XcmRouter;
type XcmEventEmitter = PolkadotXcm;
type AssetTransactor = FungibleTransactor;
type OriginConverter = XcmOriginToTransactDispatchOrigin;
type IsReserve = NativeAsset;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
type RuntimeCall = RuntimeCall;
type XcmSender = XcmRouter;
type XcmEventEmitter = PolkadotXcm;
type AssetTransactor = AssetTransactors;
type OriginConverter = XcmOriginToTransactDispatchOrigin;
// Coretime chain does not recognize a reserve location for any asset. Users must teleport ROC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
type RuntimeCall = RuntimeCall;
type XcmSender = XcmRouter;
type XcmEventEmitter = PolkadotXcm;
type AssetTransactor = AssetTransactors;
type OriginConverter = XcmOriginToTransactDispatchOrigin;
// Coretime chain does not recognize a reserve location for any asset. Users must teleport ROC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
type RuntimeCall = RuntimeCall;
type XcmSender = (); // sending XCM not supported
type XcmEventEmitter = ();
type AssetTransactor = (); // balances not supported
type OriginConverter = XcmOriginToTransactDispatchOrigin;
type IsReserve = (); // balances not supported
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
type RuntimeCall = RuntimeCall;
type XcmSender = XcmRouter;
type XcmEventEmitter = PolkadotXcm;
type AssetTransactor = FungibleTransactor;
type OriginConverter = XcmOriginToTransactDispatchOrigin;
// People chain does not recognize a reserve location for any asset. Users must teleport ROC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
type RuntimeCall = RuntimeCall;
type XcmSender = XcmRouter;
type XcmEventEmitter = PolkadotXcm;
type AssetTransactor = FungibleTransactor;
type OriginConverter = XcmOriginToTransactDispatchOrigin;
// People does not recognize a reserve location for any asset. Users must teleport WND
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
type RuntimeCall = RuntimeCall;
type XcmSender = XcmRouter;
type XcmEventEmitter = PolkadotXcm;
// How to withdraw and deposit an asset.
type AssetTransactor = AssetTransactors;
type OriginConverter = XcmOriginToTransactDispatchOrigin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
type RuntimeCall = RuntimeCall;
type XcmSender = XcmRouter;
type XcmEventEmitter = PolkadotXcm;
// How to withdraw and deposit an asset.
type AssetTransactor = AssetTransactors;
type OriginConverter = XcmOriginToTransactDispatchOrigin;
Expand Down
1 change: 1 addition & 0 deletions polkadot/runtime/rococo/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
type RuntimeCall = RuntimeCall;
type XcmSender = XcmRouter;
type XcmEventEmitter = XcmPallet;
type AssetTransactor = LocalAssetTransactor;
type OriginConverter = LocalOriginConverter;
type IsReserve = ();
Expand Down
1 change: 1 addition & 0 deletions polkadot/runtime/test-runtime/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
type RuntimeCall = super::RuntimeCall;
type XcmSender = XcmRouter;
type XcmEventEmitter = super::Xcm;
type AssetTransactor = DummyAssetTransactor;
type OriginConverter = OriginConverter;
type IsReserve = ();
Expand Down
1 change: 1 addition & 0 deletions polkadot/runtime/westend/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
type RuntimeCall = RuntimeCall;
type XcmSender = XcmRouter;
type XcmEventEmitter = XcmPallet;
type AssetTransactor = LocalAssetTransactor;
type OriginConverter = LocalOriginConverter;
type IsReserve = ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
type RuntimeCall = RuntimeCall;
type XcmSender = ();
type XcmEventEmitter = ();
type AssetTransactor = asset_transactor::AssetTransactor;
type OriginConverter = ();
// The declaration of which Locations are reserves for which Assets.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
type RuntimeCall = RuntimeCall;
type XcmSender = ();
type XcmEventEmitter = ();
type AssetTransactor = asset_transactor::AssetTransactor;
type OriginConverter = ();
// We don't need to recognize anyone as a reserve
Expand Down
1 change: 1 addition & 0 deletions polkadot/xcm/pallet-xcm-benchmarks/src/fungible/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
type RuntimeCall = RuntimeCall;
type XcmSender = EnsureDecodableXcm<DevNull>;
type XcmEventEmitter = ();
type AssetTransactor = AssetTransactor;
type OriginConverter = ();
type IsReserve = TrustedReserves;
Expand Down
1 change: 1 addition & 0 deletions polkadot/xcm/pallet-xcm-benchmarks/src/generic/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
type RuntimeCall = RuntimeCall;
type XcmSender = EnsureDecodableXcm<DevNull>;
type XcmEventEmitter = ();
type AssetTransactor = NoAssetTransactor;
type OriginConverter = AlwaysSignedByDefault<RuntimeOrigin>;
type IsReserve = AllAssetLocationsPass;
Expand Down
31 changes: 30 additions & 1 deletion polkadot/xcm/pallet-xcm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ use xcm_builder::{
use xcm_executor::{
traits::{
AssetTransferError, CheckSuspension, ClaimAssets, ConvertLocation, ConvertOrigin,
DropAssets, MatchesFungible, OnResponse, Properties, QueryHandler, QueryResponseStatus,
DropAssets, EventEmitter, MatchesFungible, OnResponse, Properties, QueryHandler, QueryResponseStatus,
RecordXcm, TransactAsset, TransferType, VersionChangeNotifier, WeightBounds,
XcmAssetTransfers,
},
Expand Down Expand Up @@ -402,13 +402,42 @@ pub mod pallet {
}
}

impl<T: Config> EventEmitter for Pallet<T> {
fn emit_sent_event(
origin: Location,
destination: Location,
message_id: XcmHash,
) {
Self::deposit_event(Event::Sent { origin, destination, message: Xcm::default(), message_id });
}

fn emit_sent_failure_event(
origin: Location,
destination: Location,
error: SendError,
) {
Self::deposit_event(Event::SentFailed { origin, destination, error });
}

fn emit_process_failure_event(
origin: Location,
error: XcmError,
) {
Self::deposit_event(Event::ProcessXcmError { origin, error });
}
}

#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
/// Execution of an XCM message was attempted.
Attempted { outcome: xcm::latest::Outcome },
/// A XCM message was sent.
Sent { origin: Location, destination: Location, message: Xcm<()>, message_id: XcmHash },
/// A XCM message failed to be sent.
SentFailed { origin: Location, destination: Location, error: SendError },
/// Process XCM message failed.
ProcessXcmError { origin: Location, error: XcmError },
/// Query response received which does not match a registered query. This may be because a
/// matching query was never registered, it may be because it is a duplicate response, or
/// because the query timed out.
Expand Down
1 change: 1 addition & 0 deletions polkadot/xcm/pallet-xcm/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
type RuntimeCall = RuntimeCall;
type XcmSender = XcmRouter;
type XcmEventEmitter = XcmPallet;
type AssetTransactor = AssetTransactors;
type OriginConverter = LocalOriginConverter;
type IsReserve = (Case<TrustedForeign>, Case<TrustedUsdc>, Case<TrustedPaidParaForeign>);
Expand Down
52 changes: 52 additions & 0 deletions polkadot/xcm/pallet-xcm/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1456,3 +1456,55 @@ fn record_xcm_works() {
assert_eq!(RecordedXcm::<Test>::get(), Some(message.into()));
});
}

#[test]
fn execute_initiate_transfer_and_check_sent_event() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add tests for the other events too

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned here, I was trying to add this test but, it looks like the events are being rollback due to failed transactions. Do you have any suggestions on how I can retrieve the events after the rollback?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm working on #7594. Once it's merged, you can use the log capture for testing.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @jpserrat , could you please take a look and finalise this PR? #7594 is now merged, so you should be able to use it for test log captures. Let me know if you need anything. Thanks!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@raymondkfcheung If I understood correctly with #7594 I'll check the logs and not the event emitted?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If events are rollback and assertions on events are not possible, then you can assert captured logs, like this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you can finalise it this week, that would be great; otherwise, I'll continue working on it next Monday.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@raymondkfcheung You can work on this one, I'm not going to have the time finish this week as I'm going out on vacation.
Thanks for the help guys!

let balances = vec![(ALICE, INITIAL_BALANCE)];
new_test_ext_with_balances(balances).execute_with(|| {
let dest: Location = Location::new(1, [Junction::AccountId32 { network: None, id: BOB.into() }]);
let assets: Asset = (Parent, SEND_AMOUNT).into();

let message = Xcm(vec![
InitiateReserveWithdraw {
assets: Wild(All),
reserve: Parent.into(),
xcm: Xcm(vec![
BuyExecution { fees: assets.clone(), weight_limit: Unlimited },
DepositAsset { assets: All.into(), beneficiary: dest.clone() },
]),
},
]);

assert_ok!(XcmPallet::execute(
RuntimeOrigin::signed(ALICE),
Box::new(VersionedXcm::from(message.clone())),
BaseXcmWeight::get() * 3,
));

let sender: Location = AccountId32 { network: None, id: ALICE.into() }.into();
let expected_message = Xcm(vec![
WithdrawAsset(Assets::new()),
ClearOrigin,
BuyExecution { fees: assets.clone(), weight_limit: Unlimited },
DepositAsset { assets: All.into(), beneficiary: dest.clone() },
]);
let id = fake_message_hash(&expected_message);

assert_eq!(
last_events(2),
vec![
RuntimeEvent::XcmPallet(crate::Event::Sent {
origin: sender,
destination: Parent.into(),
message: expected_message,
message_id: id,
}),
RuntimeEvent::XcmPallet(crate::Event::Attempted {
outcome: Outcome::Complete {
used: Weight::from_parts(1000, 1000)
}
})
]
);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
type RuntimeCall = RuntimeCall;
type XcmSender = ();
type XcmEventEmitter = ();
type AssetTransactor = FungibleTransactor;
type OriginConverter = ();
type IsReserve = ();
Expand Down
1 change: 1 addition & 0 deletions polkadot/xcm/xcm-builder/src/tests/pay/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
type RuntimeCall = RuntimeCall;
type XcmSender = TestMessageSender;
type XcmEventEmitter = XcmPallet;
type AssetTransactor = LocalAssetsTransactor;
type OriginConverter = OriginConverter;
type IsReserve = ();
Expand Down
1 change: 1 addition & 0 deletions polkadot/xcm/xcm-builder/tests/mock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
type RuntimeCall = RuntimeCall;
type XcmSender = TestXcmRouter;
type XcmEventEmitter = XcmPallet;
type AssetTransactor = LocalAssetTransactor;
type OriginConverter = LocalOriginConverter;
type IsReserve = ();
Expand Down
5 changes: 4 additions & 1 deletion polkadot/xcm/xcm-executor/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

use crate::traits::{
AssetExchange, AssetLock, CallDispatcher, ClaimAssets, ConvertOrigin, DropAssets, ExportXcm,
AssetExchange, AssetLock, CallDispatcher, ClaimAssets, ConvertOrigin, DropAssets, EventEmitter, ExportXcm,
FeeManager, HandleHrmpChannelAccepted, HandleHrmpChannelClosing,
HandleHrmpNewChannelOpenRequest, OnResponse, ProcessTransaction, RecordXcm, ShouldExecute,
TransactAsset, VersionChangeNotifier, WeightBounds, WeightTrader,
Expand All @@ -39,6 +39,9 @@ pub trait Config {
/// the executor.
type XcmSender: SendXcm;

/// How to emit XCM events.
type XcmEventEmitter: EventEmitter;

/// How to withdraw and deposit an asset.
type AssetTransactor: TransactAsset;

Expand Down
25 changes: 22 additions & 3 deletions polkadot/xcm/xcm-executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use xcm::latest::{prelude::*, AssetTransferFilter};
pub mod traits;
use traits::{
validate_export, AssetExchange, AssetLock, CallDispatcher, ClaimAssets, ConvertOrigin,
DropAssets, Enact, ExportXcm, FeeManager, FeeReason, HandleHrmpChannelAccepted,
DropAssets, Enact, ExportXcm, EventEmitter, FeeManager, FeeReason, HandleHrmpChannelAccepted,
HandleHrmpChannelClosing, HandleHrmpNewChannelOpenRequest, OnResponse, ProcessTransaction,
Properties, ShouldExecute, TransactAsset, VersionChangeNotifier, WeightBounds, WeightTrader,
XcmAssetTransfers,
Expand Down Expand Up @@ -427,9 +427,27 @@ impl<Config: config::Config> XcmExecutor<Config> {
reason = ?reason,
"Sending msg",
);
let (ticket, fee) = validate_send::<Config::XcmSender>(dest, msg)?;
let (ticket, fee) = validate_send::<Config::XcmSender>(dest.clone(), msg)?;
self.take_fee(fee, reason)?;
Config::XcmSender::deliver(ticket).map_err(Into::into)
match Config::XcmSender::deliver(ticket) {
Ok(message_id) => {
Config::XcmEventEmitter::emit_sent_event(
self.original_origin.clone(),
dest,
message_id.clone(),
);
Ok(message_id)
},
Err(e) => {
tracing::error!(target: "xcm::send", ?e, "XCM failed to deliver with error");
Config::XcmEventEmitter::emit_sent_failure_event(
self.original_origin.clone(),
dest,
e.clone(),
);
Err(e.into())
},
}
}

/// Remove the registered error handler and return it. Do not refund its weight.
Expand Down Expand Up @@ -813,6 +831,7 @@ impl<Config: config::Config> XcmExecutor<Config> {
self.process_instruction(instr)
});
if let Err(e) = inst_res {
Config::XcmEventEmitter::emit_process_failure_event(self.original_origin.clone(), e.clone());
tracing::trace!(target: "xcm::execute", "!!! ERROR: {:?}", e);
*r = Err(ExecutorError {
index: i as u32,
Expand Down
Loading
Loading