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 EventEmitter to XCM executor. #7234

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jpserrat
Copy link
Contributor

@jpserrat jpserrat commented Jan 18, 2025

Closes #6851

@franciscoaguirre I added the EventEmitter trait to the config. I have two questions on this:

  1. I created a new file to put the trait in, is this ok?
  2. For EventEmitter trait I've created a sent event function instead a generic one that emits any event, do you prefer a generic one?

@jpserrat jpserrat requested a review from a team as a code owner January 18, 2025 14:05
@paritytech-review-bot paritytech-review-bot bot requested a review from a team January 18, 2025 14:06
@@ -427,9 +428,20 @@ 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.clone())?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Just thinking out loud, do we really want to log/use msg.clone here?
My concern is that some Config::XcmSender / SendXcm implementations might modify the msg, such as WithUniqueTopic. This could lead to confusion, as the msg in the event might differ from the one actually sent (or received on the other side).

Copy link
Contributor

Choose a reason for hiding this comment

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

definitely don't include full message in event, see my comment in the trait definition


use xcm::latest::prelude::*;

pub trait EventEmitter {
Copy link
Contributor

Choose a reason for hiding this comment

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

please add some documentation here at least

use xcm::latest::prelude::*;

pub trait EventEmitter {
fn emit_sent_event(
Copy link
Contributor

Choose a reason for hiding this comment

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

The emit_sent_event function, with Self::deposit_event(Event::Sent, makes it a single-purpose solution.

I would prefer a more general approach. For example, there’s a very relevant issue where we want/need to emit a failure event from ProcessXcmMessage.

If we could address this issue using an EventEmitter, that would be fantastic.

Copy link
Contributor

Choose a reason for hiding this comment

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

one option is this trait to have multiple functions, each specific to xcm-executor events

fn emit_sent_event is one
fn emit_process_event is another
etc

use xcm::latest::prelude::*;

pub trait EventEmitter {
fn emit_sent_event(
Copy link
Contributor

Choose a reason for hiding this comment

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

one option is this trait to have multiple functions, each specific to xcm-executor events

fn emit_sent_event is one
fn emit_process_event is another
etc

fn emit_sent_event(
origin: Location,
destination: Location,
message: Xcm<()>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
message: Xcm<()>,

definitely cannot include full message in Events, on chain storage should be kept to a minimum

providing the message_id: XcmHash should be enough

@@ -46,6 +46,7 @@ mod assets;
pub use assets::AssetsInHolding;
mod config;
pub use config::Config;
use crate::traits::EventEmitter;
Copy link
Contributor

Choose a reason for hiding this comment

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

move this to the use traits::{... above

@@ -427,9 +428,20 @@ 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.clone())?;
Copy link
Contributor

Choose a reason for hiding this comment

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

definitely don't include full message in event, see my comment in the trait definition

Config::XcmSender::deliver(ticket).map_err(Into::into)
let message_id = match Config::XcmSender::deliver(ticket) {
Ok(message_id) => message_id,
Err(e) => return Err(e.into()),
Copy link
Contributor

Choose a reason for hiding this comment

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

should emit event for error too

message: Xcm<()>,
message_id: XcmHash,
) {
Self::deposit_event(Event::Sent { origin, destination, message, message_id });
Copy link
Contributor

Choose a reason for hiding this comment

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

would not reuse Event::Sent which is used by pallet_xcm::send()

Suggested change
Self::deposit_event(Event::Sent { origin, destination, message, message_id });
Self::deposit_event(Event::XcmExecutorSent { origin, destination, message_id });

Copy link
Contributor

Choose a reason for hiding this comment

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

Why would you not reuse it? Are they really that different?
If they're just one, apps can just subscribe to one event and know all cross-chain messages from that.

Copy link
Contributor

Choose a reason for hiding this comment

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

true, on second thought we could reuse, I am still not sure about including the full message in the event though, some messages could be quite big

@franciscoaguirre franciscoaguirre added the T6-XCM This PR/Issue is related to XCM. label Jan 28, 2025
@franciscoaguirre franciscoaguirre self-assigned this Jan 28, 2025
@acatangiu
Copy link
Contributor

@jpserrat do you plan on finishing this PR or should we take over?

@jpserrat
Copy link
Contributor Author

@acatangiu Sorry for the delay on this. I'm going to finish.

@raymondkfcheung
Copy link

If #7200 is merged before your PR, you may need add the new EventEmitter on the XcmTestConfig.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T6-XCM This PR/Issue is related to XCM.
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

Add "Sent" event when a message is sent via execute
5 participants