Skip to content

Commit

Permalink
reorder execution on receive (#218)
Browse files Browse the repository at this point in the history
  • Loading branch information
minghinmatthewlam authored Jan 3, 2024
1 parent f47d92a commit d7ca03a
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 31 deletions.

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions contracts/src/Teleporter/TeleporterMessenger.sol
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,6 @@ contract TeleporterMessenger is ITeleporterMessenger, ReentrancyGuards {
_relayerRewardAddresses[warpMessage.sourceChainID][teleporterMessage.messageID] =
relayerRewardAddress;

// Execute the message.
if (teleporterMessage.message.length > 0) {
_handleInitialMessageExecution(warpMessage.sourceChainID, teleporterMessage);
}

// Process the receipts that were included in the teleporter message by paying the
// fee for the messages are reward to the given relayers.
uint256 length = teleporterMessage.receipts.length;
Expand Down Expand Up @@ -311,6 +306,11 @@ contract TeleporterMessenger is ITeleporterMessenger, ReentrancyGuards {
relayerRewardAddress,
teleporterMessage
);

// Execute the message.
if (teleporterMessage.message.length > 0) {
_handleInitialMessageExecution(warpMessage.sourceChainID, teleporterMessage);
}
}

/**
Expand Down
14 changes: 7 additions & 7 deletions contracts/src/Teleporter/tests/FallbackReceiveTests.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ contract FallbackReceiveTest is TeleporterMessengerTest {

// Receive the message and check that message execution was successful.
vm.expectEmit(true, true, true, true, address(teleporterMessenger));
emit MessageExecuted(DEFAULT_ORIGIN_CHAIN_ID, messageToReceive.messageID);
vm.expectEmit(true, true, true, true, address(teleporterMessenger));
emit ReceiveCrossChainMessage(
warpMessage.sourceChainID,
messageToReceive.messageID,
address(this),
DEFAULT_RELAYER_REWARD_ADDRESS,
messageToReceive
);
vm.expectEmit(true, true, true, true, address(teleporterMessenger));
emit MessageExecuted(DEFAULT_ORIGIN_CHAIN_ID, messageToReceive.messageID);
teleporterMessenger.receiveCrossChainMessage(0, DEFAULT_RELAYER_REWARD_ADDRESS);

// Check that the nonce was incremented.
Expand All @@ -127,11 +127,7 @@ contract FallbackReceiveTest is TeleporterMessengerTest {
// Mock the call to the warp precompile to get the message.
_setUpSuccessGetVerifiedWarpMessageMock(0, warpMessage);

// Receive the message and check that message execution was successful.
vm.expectEmit(true, true, true, true, address(teleporterMessenger));
emit MessageExecutionFailed(
DEFAULT_ORIGIN_CHAIN_ID, messageToReceive.messageID, messageToReceive
);
// Receive the message and check that message execution failed.
vm.expectEmit(true, true, true, true, address(teleporterMessenger));
emit ReceiveCrossChainMessage(
warpMessage.sourceChainID,
Expand All @@ -140,6 +136,10 @@ contract FallbackReceiveTest is TeleporterMessengerTest {
DEFAULT_RELAYER_REWARD_ADDRESS,
messageToReceive
);
vm.expectEmit(true, true, true, true, address(teleporterMessenger));
emit MessageExecutionFailed(
DEFAULT_ORIGIN_CHAIN_ID, messageToReceive.messageID, messageToReceive
);
teleporterMessenger.receiveCrossChainMessage(0, DEFAULT_RELAYER_REWARD_ADDRESS);

// Check that the nonce was not changed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,15 @@ contract HandleInitialMessageExecutionTest is TeleporterMessengerTest {

// Receive the message and check that message execution was successful.
vm.expectEmit(true, true, true, true, address(teleporterMessenger));
emit MessageExecuted(DEFAULT_ORIGIN_CHAIN_ID, messageToReceive.messageID);
vm.expectEmit(true, true, true, true, address(teleporterMessenger));
emit ReceiveCrossChainMessage(
warpMessage.sourceChainID,
messageToReceive.messageID,
address(this),
DEFAULT_RELAYER_REWARD_ADDRESS,
messageToReceive
);
vm.expectEmit(true, true, true, true, address(teleporterMessenger));
emit MessageExecuted(DEFAULT_ORIGIN_CHAIN_ID, messageToReceive.messageID);
teleporterMessenger.receiveCrossChainMessage(0, DEFAULT_RELAYER_REWARD_ADDRESS);

// Check that the message had the proper affect on the destination contract.
Expand Down Expand Up @@ -184,17 +184,17 @@ contract HandleInitialMessageExecutionTest is TeleporterMessengerTest {
// is considered a failed message execution, but the message itself is
// still successfully delivered.
vm.expectEmit(true, true, true, true, address(teleporterMessenger));
emit MessageExecutionFailed(
DEFAULT_ORIGIN_CHAIN_ID, messageToReceive.messageID, messageToReceive
);
vm.expectEmit(true, true, true, true, address(teleporterMessenger));
emit ReceiveCrossChainMessage(
warpMessage.sourceChainID,
messageToReceive.messageID,
address(this),
DEFAULT_RELAYER_REWARD_ADDRESS,
messageToReceive
);
vm.expectEmit(true, true, true, true, address(teleporterMessenger));
emit MessageExecutionFailed(
DEFAULT_ORIGIN_CHAIN_ID, messageToReceive.messageID, messageToReceive
);
teleporterMessenger.receiveCrossChainMessage(0, DEFAULT_RELAYER_REWARD_ADDRESS);

// Check that the message hash was stored in state and the message did not have any affect on the destination.
Expand Down Expand Up @@ -232,17 +232,17 @@ contract HandleInitialMessageExecutionTest is TeleporterMessengerTest {

// Receive the message.
vm.expectEmit(true, true, true, true, address(teleporterMessenger));
emit MessageExecutionFailed(
DEFAULT_ORIGIN_CHAIN_ID, messageToReceive.messageID, messageToReceive
);
vm.expectEmit(true, true, true, true, address(teleporterMessenger));
emit ReceiveCrossChainMessage(
warpMessage.sourceChainID,
messageToReceive.messageID,
address(this),
DEFAULT_RELAYER_REWARD_ADDRESS,
messageToReceive
);
vm.expectEmit(true, true, true, true, address(teleporterMessenger));
emit MessageExecutionFailed(
DEFAULT_ORIGIN_CHAIN_ID, messageToReceive.messageID, messageToReceive
);
teleporterMessenger.receiveCrossChainMessage(0, DEFAULT_RELAYER_REWARD_ADDRESS);

// Check that the message hash was stored in state and the message did not have any affect on the destination.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,17 +210,17 @@ contract RetryMessageExecutionTest is TeleporterMessengerTest {
// The message should be successfully received, but its execution should fail.
vm.roll(12);
vm.expectEmit(true, true, true, true, address(teleporterMessenger));
emit MessageExecutionFailed(
DEFAULT_ORIGIN_CHAIN_ID, messageToReceive.messageID, messageToReceive
);
vm.expectEmit(true, true, true, true, address(teleporterMessenger));
emit ReceiveCrossChainMessage(
warpMessage.sourceChainID,
messageToReceive.messageID,
address(this),
DEFAULT_RELAYER_REWARD_ADDRESS,
messageToReceive
);
vm.expectEmit(true, true, true, true, address(teleporterMessenger));
emit MessageExecutionFailed(
DEFAULT_ORIGIN_CHAIN_ID, messageToReceive.messageID, messageToReceive
);
teleporterMessenger.receiveCrossChainMessage(0, DEFAULT_RELAYER_REWARD_ADDRESS);

// Check that the message execution didn't have any effect, but
Expand Down
8 changes: 4 additions & 4 deletions contracts/src/Teleporter/tests/TeleporterMessengerTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -213,17 +213,17 @@ contract TeleporterMessengerTest is Test {

// Receive the message - which should fail execution.
vm.expectEmit(true, true, true, true, address(teleporterMessenger));
emit MessageExecutionFailed(
DEFAULT_ORIGIN_CHAIN_ID, messageToReceive.messageID, messageToReceive
);
vm.expectEmit(true, true, true, true, address(teleporterMessenger));
emit ReceiveCrossChainMessage(
warpMessage.sourceChainID,
messageToReceive.messageID,
address(this),
DEFAULT_RELAYER_REWARD_ADDRESS,
messageToReceive
);
vm.expectEmit(true, true, true, true, address(teleporterMessenger));
emit MessageExecutionFailed(
DEFAULT_ORIGIN_CHAIN_ID, messageToReceive.messageID, messageToReceive
);
teleporterMessenger.receiveCrossChainMessage(0, DEFAULT_RELAYER_REWARD_ADDRESS);

return (DEFAULT_ORIGIN_CHAIN_ID, DEFAULT_DESTINATION_ADDRESS, messageToReceive);
Expand Down

0 comments on commit d7ca03a

Please sign in to comment.