Skip to content

Commit

Permalink
fix(ethToArb): export messageId from dispatchAndProcess
Browse files Browse the repository at this point in the history
  • Loading branch information
PierrickGT committed Nov 3, 2023
1 parent 8eb013b commit 876f27f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 21 deletions.
28 changes: 14 additions & 14 deletions src/ethereum-arbitrum/EthereumToArbitrumDispatcher.sol
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ contract MessageDispatcherArbitrum is IMessageDispatcherArbitrum {

/**
* @inheritdoc IMessageDispatcherArbitrum
* @dev `msg.sender` is passed as `_callValueRefundAddress` cause this address can cancel the retryable ticket.
* @dev `_refundAddress` is passed as `_callValueRefundAddress`, this address can cancel the retryable ticket.
* @dev We store `_message` in memory to avoid a stack too deep error.
*/
function dispatchAndProcessMessage(
Expand All @@ -189,16 +189,16 @@ contract MessageDispatcherArbitrum is IMessageDispatcherArbitrum {
uint256 _gasLimit,
uint256 _maxSubmissionCost,
uint256 _gasPriceBid
) external payable returns (uint256 ticketId) {
) external payable returns (bytes32 messageId, uint256 ticketId) {
address _executorAddress = address(executor);
_checkProcessParams(_executorAddress, _refundAddress);
_checkToChainId(_toChainId);

bytes32 _messageId = _computeMessageId(msg.sender, _to, _data);
messageId = _computeMessageId(msg.sender, _to, _data);
bytes memory _message = MessageLib.encodeMessage(
_to,
_data,
_messageId,
messageId,
block.chainid,
msg.sender
);
Expand All @@ -207,19 +207,19 @@ contract MessageDispatcherArbitrum is IMessageDispatcherArbitrum {
_executorAddress,
_maxSubmissionCost,
_refundAddress,
msg.sender,
_refundAddress,
_gasLimit,
_gasPriceBid,
_message
);

emit MessageDispatched(_messageId, msg.sender, _toChainId, _to, _data);
emit MessageProcessed(_messageId, msg.sender, ticketId);
emit MessageDispatched(messageId, msg.sender, _toChainId, _to, _data);
emit MessageProcessed(messageId, msg.sender, ticketId);
}

/**
* @inheritdoc IMessageDispatcherArbitrum
* @dev `msg.sender` is passed as `_callValueRefundAddress` cause this address can cancel the retryable ticket.
* @dev `_refundAddress` is passed as `_callValueRefundAddress`, this address can cancel the retryable ticket.
* @dev We store `_messageBatch` in memory to avoid a stack too deep error.
*/
function dispatchAndProcessMessageBatch(
Expand All @@ -229,15 +229,15 @@ contract MessageDispatcherArbitrum is IMessageDispatcherArbitrum {
uint256 _gasLimit,
uint256 _maxSubmissionCost,
uint256 _gasPriceBid
) external payable returns (uint256 ticketId) {
) external payable returns (bytes32 messageId, uint256 ticketId) {
address _executorAddress = address(executor);
_checkProcessParams(_executorAddress, _refundAddress);
_checkToChainId(_toChainId);

bytes32 _messageId = _computeMessageBatchId(msg.sender, _messages);
messageId = _computeMessageBatchId(msg.sender, _messages);
bytes memory _messageBatch = MessageLib.encodeMessageBatch(
_messages,
_messageId,
messageId,
block.chainid,
msg.sender
);
Expand All @@ -246,14 +246,14 @@ contract MessageDispatcherArbitrum is IMessageDispatcherArbitrum {
_executorAddress,
_maxSubmissionCost,
_refundAddress,
msg.sender,
_refundAddress,
_gasLimit,
_gasPriceBid,
_messageBatch
);

emit MessageBatchDispatched(_messageId, msg.sender, _toChainId, _messages);
emit MessageBatchProcessed(_messageId, msg.sender, ticketId);
emit MessageBatchDispatched(messageId, msg.sender, _toChainId, _messages);
emit MessageBatchProcessed(messageId, msg.sender, ticketId);
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/interfaces/extensions/IMessageDispatcherArbitrum.sol
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ interface IMessageDispatcherArbitrum is IBatchMessageDispatcher {
* @param gasLimit Maximum amount of gas required for the message to be executed
* @param maxSubmissionCost Max gas deducted from user's L2 balance to cover base submission fee
* @param gasPriceBid Gas price bid for L2 execution
* @return messageId ID uniquely identifying the message
* @return ticketId ID of the retryable ticket that was created
*/
function dispatchAndProcessMessage(
Expand All @@ -108,7 +109,7 @@ interface IMessageDispatcherArbitrum is IBatchMessageDispatcher {
uint256 gasLimit,
uint256 maxSubmissionCost,
uint256 gasPriceBid
) external payable returns (uint256 ticketId);
) external payable returns (bytes32 messageId, uint256 ticketId);

/**
* @notice Dispatch and process a batch of messages in one transaction.
Expand All @@ -120,6 +121,7 @@ interface IMessageDispatcherArbitrum is IBatchMessageDispatcher {
* @param gasLimit Maximum amount of gas required for the message to be executed
* @param maxSubmissionCost Max gas deducted from user's L2 balance to cover base submission fee
* @param gasPriceBid Gas price bid for L2 execution
* @return messageId ID uniquely identifying the message
* @return ticketId ID of the retryable ticket that was created
*/
function dispatchAndProcessMessageBatch(
Expand All @@ -129,7 +131,7 @@ interface IMessageDispatcherArbitrum is IBatchMessageDispatcher {
uint256 gasLimit,
uint256 maxSubmissionCost,
uint256 gasPriceBid
) external payable returns (uint256 ticketId);
) external payable returns (bytes32 messageId, uint256 ticketId);

/**
* @notice Get transaction hash for a single message.
Expand Down
15 changes: 10 additions & 5 deletions test/unit/ethereum-arbitrum/EthereumToArbitrumDispatcher.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ import { Test } from "forge-std/Test.sol";

import { IInbox } from "@arbitrum/nitro-contracts/src/bridge/IInbox.sol";

import { MessageDispatcherArbitrum } from "../../../src/ethereum-arbitrum/EthereumToArbitrumDispatcher.sol";
import { MessageExecutorArbitrum } from "../../../src/ethereum-arbitrum/EthereumToArbitrumExecutor.sol";
import {
MessageDispatcherArbitrum
} from "../../../src/ethereum-arbitrum/EthereumToArbitrumDispatcher.sol";
import {
MessageExecutorArbitrum
} from "../../../src/ethereum-arbitrum/EthereumToArbitrumExecutor.sol";
import { MessageLib } from "../../../src/libraries/MessageLib.sol";

import { Greeter } from "../../contracts/Greeter.sol";
Expand Down Expand Up @@ -249,7 +253,7 @@ contract MessageDispatcherArbitrumUnitTest is Test {
vm.expectEmit(true, true, true, true, address(dispatcher));
emit MessageProcessed(_expectedMessageId, address(this), _randomNumber);

uint256 _ticketId = dispatcher.dispatchAndProcessMessage(
(bytes32 _messageId, uint256 _ticketId) = dispatcher.dispatchAndProcessMessage(
toChainId,
_message.to,
_message.data,
Expand All @@ -259,14 +263,14 @@ contract MessageDispatcherArbitrumUnitTest is Test {
gasPriceBid
);

assertEq(_messageId, _expectedMessageId);
assertEq(_ticketId, _randomNumber);
}

function testDispatchAndProcessMessageBatch() public {
setExecutor();

bytes32 _expectedMessageId = MessageLib.computeMessageBatchId(nonce, address(this), messages);

uint256 _randomNumber = inbox.generateRandomNumber();

vm.expectEmit(true, true, true, true, address(dispatcher));
Expand All @@ -275,7 +279,7 @@ contract MessageDispatcherArbitrumUnitTest is Test {
vm.expectEmit(true, true, true, true, address(dispatcher));
emit MessageBatchProcessed(_expectedMessageId, address(this), _randomNumber);

uint256 _ticketId = dispatcher.dispatchAndProcessMessageBatch(
(bytes32 _messageId, uint256 _ticketId) = dispatcher.dispatchAndProcessMessageBatch(
toChainId,
messages,
msg.sender,
Expand All @@ -284,6 +288,7 @@ contract MessageDispatcherArbitrumUnitTest is Test {
gasPriceBid
);

assertEq(_messageId, _expectedMessageId);
assertEq(_ticketId, _randomNumber);
}

Expand Down

0 comments on commit 876f27f

Please sign in to comment.