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

Message execution events #66

Merged
merged 16 commits into from
Oct 26, 2023
Merged

Message execution events #66

merged 16 commits into from
Oct 26, 2023

Conversation

minghinmatthewlam
Copy link

Why this should be merged

Clean up of message execution events, consolidating event for message execution success and failure.

How this works

Previously we just had an event for successful retry MessageExecutionRetried and execution failure FailedMessageExecution, but not an event emitted for successful execution. We now emit MessageExecuted for successful initial or retry execution, and MessageExecutionFailed when execution fails.

How this was tested

  • unit tests

How is this documented

  • updated natspec comments

geoff-vball
geoff-vball previously approved these changes Oct 25, 2023
Copy link
Contributor

@geoff-vball geoff-vball left a comment

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

@bernard-avalabs bernard-avalabs left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -388,7 +389,7 @@ contract TeleporterMessenger is ITeleporterMessenger, ReentrancyGuards {

// Clear the failed message hash from state prior to retrying its execution to redundantly prevent
// reentrance attacks (on top of the nonReentrant guard).
emit MessageExecutionRetried(originChainID, message.messageID);
emit MessageExecuted(originChainID, message.messageID);
Copy link
Contributor

Choose a reason for hiding this comment

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

Won't affect correctness since we revert on execution failure, but can we move this to after the call itself and the associated require?

Copy link
Contributor

Choose a reason for hiding this comment

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

It might also be worth keeping MessageExecutionRetried so that an indexer can distinguish between calls to retryMessageExecution and receiveCrossChainMessage based solely on the logs.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think if we want to distinguish these two, it might be better for have a bool flag in MessageExecuted instead. I think it would be good to have all executed messages emit a MessageExecuted event, so they can all be easily grouped together.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yup, agreed that all executed messages should emit MessageExecuted. No strong preference if the distinction between retryMessageExecution and receiveCrossChainMessage is done with a bool flag or a separate MessageExecutionRetried event, but I think the distinction should be made one way or another.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, yeah emitting two events is probably a little cleaner, and should be okay since retries shouldn't be too common

Copy link
Author

Choose a reason for hiding this comment

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

added isRetry to the MessageExecuted event to differentiate

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, I have a preference for separate retry vs executed events over the boolean flag approach.

If we expect retries to be relatively rare, then it doesn't make as much sense for every MessageExecuted event to pay gas for the indexed isRetry field.

OTOH, if retries are common enough, then it's possible for the average gas needed to eventually execute the message would be lower by only having a single event type.

I suspect the former case to be more likely, so would prefer separate events over the bool flag.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I think I agree with Cam here

Copy link
Contributor

Choose a reason for hiding this comment

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

We synced offline and decided that it makes the most sense to not distinguish between the initial execution and retry cases, and have retryMessageExecution emit only MessageExecuted without the bool flag. The main reason for this is gas savings by not emitting more events than are necessary to reconstruct on-chain activity. An indexer should be able to construct all the scenarios with the existing events associated with a particular message ID:

  • (Happy case) initial execution succeeds - observe MessageExecuted
  • Initial execution fails - observe MessageExecutionFailed
  • Successful retry - observe MessageExecutionFailed followed by MessageExecuted in a later tx
  • Failed retry - observe MessageExecutionFailed followed by a tx revert on the failed call to retryMessageExecution

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for writing this up

Copy link
Collaborator

@michaelkaplan13 michaelkaplan13 left a comment

Choose a reason for hiding this comment

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

Just one nit on comment wording, but otherwise LGTM

contracts/src/Teleporter/ITeleporterMessenger.sol Outdated Show resolved Hide resolved
@@ -766,7 +770,7 @@ contract TeleporterMessenger is ITeleporterMessenger, ReentrancyGuards {
] = keccak256(abi.encode(message));

// Emit a failed execution event for anyone monitoring unsuccessful messages to retry.
emit FailedMessageExecution(originChainID, message.messageID, message);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to add the failure reason to this log?

Copy link
Collaborator

@michaelkaplan13 michaelkaplan13 Oct 26, 2023

Choose a reason for hiding this comment

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

IMO, that is best left for consideration at a later point in time because we're not sure what the return data will contain in various failure cases. Up to @minghinmatthewlam either way though

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good. I created an issue here: #81. @minghinmatthewlam up to you if you want to include that in this PR.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks will tackle in separate PR, definitely think will be helpful for developers for debugging so we should add.

cam-schultz
cam-schultz previously approved these changes Oct 26, 2023
@@ -752,6 +752,7 @@ contract TeleporterMessenger is ITeleporterMessenger, ReentrancyGuards {
// provided enough gas to meet the required gas limit.
if (!success) {
_storeFailedMessageExecution(originChainID, message);
return;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice catch

Copy link
Contributor

@geoff-vball geoff-vball left a comment

Choose a reason for hiding this comment

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

👍

@minghinmatthewlam minghinmatthewlam merged commit 28def26 into main Oct 26, 2023
9 of 11 checks passed
@geoff-vball geoff-vball deleted the execution-events branch October 26, 2023 22:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants