14. Cross Domain Messengers
Cross domain messengers provide a higher level API for users interested in sending cross domain messages.
Complexity is abstracted away by means of additional contracts. Therefore a user does not have to interact with more complex lower level system contracts that actually facilitate the L1-L2 messaging functionality.
CrossDomainMessenger
is extended to create both:
- L1CrossDomainMessenger
- L2CrossDomainMessenger
L2CrossDomainMessenger
โ Predeploy at 0x4200000000000000000000000000000000000007
interface CrossDomainMessenger {
event FailedRelayedMessage(bytes32 indexed msgHash);
event RelayedMessage(bytes32 indexed msgHash);
event SentMessage(address indexed target, address sender, bytes message, uint256 messageNonce, uint256 gasLimit);
event SentMessageExtension1(address indexed sender, uint256 value);
function MESSAGE_VERSION() external view returns (uint16);
function MIN_GAS_CALLDATA_OVERHEAD() external view returns (uint64);
function MIN_GAS_CONSTANT_OVERHEAD() external view returns (uint64);
function MIN_GAS_DYNAMIC_OVERHEAD_DENOMINATOR() external view returns (uint64);
function MIN_GAS_DYNAMIC_OVERHEAD_NUMERATOR() external view returns (uint64);
function OTHER_MESSENGER() external view returns (address);
function baseGas(bytes memory _message, uint32 _minGasLimit) external pure returns (uint64);
function failedMessages(bytes32) external view returns (bool);
function messageNonce() external view returns (uint256);
function relayMessage(
uint256 _nonce,
address _sender,
address _target,
uint256 _value,
uint256 _minGasLimit,
bytes memory _message
) external payable;
function sendMessage(address _target, bytes memory _message, uint32 _minGasLimit) external payable;
function successfulMessages(bytes32) external view returns (bool);
function xDomainMessageSender() external view returns (address);
}
Sending side: Calls
sendMessage
function.Receiving side: Calls
relayMessage
function (to trigger execution)Cross domain messenger contracts on both L1 and L2 should be deployed behind upgradable proxies.
We want to so we will be able to update the message version in the future.
There are currently 2 message versions:
1) Message version 0
2) Message version 1
Message Version 0:
abi.encodeWithSignature(
"relayMessage(address,address,bytes,uint256)",
_target,
_sender,
_message,
_messageNonce
);
Message Version 1:
abi.encodeWithSignature(
"relayMessage(uint256,address,address,uint256,uint256,bytes)",
_nonce,
_sender,
_target,
_value,
_gasLimit,
_data
);
ย
ย