Skip to content
This repository has been archived by the owner on Dec 5, 2021. It is now read-only.

Commit

Permalink
custom messenger + relayer (#54)
Browse files Browse the repository at this point in the history
* Merge omgx_contracts into /optimism monorepo; integrate message-relayer-fast; and connect up message-relayer-fast with the Dockers/ops

* further cleanup

* get address from addressManager; add tests for the message-relayer-fast

* testing contract deployments to the new stack

* Deployment working....

* Add fast and slow message contracts (#38)

* wip - simplify system - remove message-relayer-fast

* Update L1LiquidityPool.sol

* message relay working

* almost there

* major wallet functions confirmed working - ready

* fix integration tests

* minor tweaks to get everything to run on rebased develop branch

* Integrate #37, confirm compilation and function

* update .env.example for stable rinkeby endpoint

* adds the message-relayer-fast - goal is to end up with self contained folder for this service and associated tests

* Added whitelist (#44)

* beginning of a fast relayer with unit tests

* basics are working

* feat: modify tests to add custom messenger

* feat: make messenger address pluggable

* feat: depl local

* feat: register custom messenger

* feat: automate

* feat: automate

* feat: add options for using own custom messegner with service

* feat: add options for using own custom messegner with service

* merge master

* rem: dep files

* chore: change build command

* style: rename all vars to _fast

Co-authored-by: CAPtheorem <79423264+CAPtheorem@users.noreply.github.com>
Co-authored-by: cby3149 <46272347+cby3149@users.noreply.github.com>
  • Loading branch information
3 people authored Jun 10, 2021
1 parent d3ae019 commit 9a2f10b
Show file tree
Hide file tree
Showing 20 changed files with 945 additions and 61 deletions.
27 changes: 9 additions & 18 deletions packages/omgx/message-relayer-fast/.env.example
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
# Rinkeby
NODE_ENV=local
L1_NODE_WEB3_URL=https://rinkeby.infura.io/v3/YOUR_INFURA_KEY_HERE
L2_NODE_WEB3_URL=http://3.85.224.26:8545
DEPLOYER_HTTP=
ADDRESS_MANAGER_ADDRESS=
L1_WALLET_KEY=
L1_TARGET=0x0
L1_BLOCK_OFFSET=0
RETRIES=100

# Local
#local
NODE_ENV=local
L1_NODE_WEB3_URL=http://localhost:9545
L2_NODE_WEB3_URL=http://localhost:8545
DEPLOYER_HTTP=http://deployer:8080
ADDRESS_MANAGER_ADDRESS=0x3e4CFaa8730092552d9425575E49bB542e329981
L1_WALLET_KEY=0x5b1c2653250e5c580dcb4e51c2944455e144c57ebd6a0645bd359d2e69ca0f0c
L1_TARGET=0x0
L1_BLOCK_OFFSET=0
RETRIES=100
ADDRESS_MANAGER_ADDRESS=0x5FbDB2315678afecb367f032d93F642f64180aa3
TEST_PRIVATE_KEY_1=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
TEST_PRIVATE_KEY_2=0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d
TEST_PRIVATE_KEY_3=0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a
TARGET_GAS_LIMIT=9000000000
CHAIN_ID=28
L1_WALLET_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
L1_TARGET=0x0
59 changes: 46 additions & 13 deletions packages/omgx/message-relayer-fast/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# OMGX_Alt_Messenger
# OMGX_Messenger_Relayer_Fast

Customized L1 Cross Domain Messenger without dispute period time restrictions and associated message relayer service.

Expand All @@ -10,11 +10,21 @@ The custom `OVM_L1CrossDomainMessenger` works with the default `OVM_L2CrossDomai

- Your bridge/gateway contract must implement `contracts/libraries/OVM_CrossDomainEnabled.sol` instead. This uses the default L1 Messenger to send messages and the custom L1 Messenger to relay.

## Running the Alt_Relayer
## Running the Custom Messenger + Relayer

Env Settings -
- To deploy the custom messenger and start up the associated relayer run-
```
yarn start
```

- To run tests
```
yarn test
```

## env settings

**THESE MAY BE OUTDATED!!!** The examples in the .env are definitive
Use .env.example for quick tests

```
Expand All @@ -23,27 +33,50 @@ L1_NODE_WEB3_URL= <l1 node url>
L2_NODE_WEB3_URL= <l2 node url>
L1_WALLET_KEY= <l1 wallet key>
L1_MESSENGER_ADDRESS= <l1 custom messenger address>
L1_WALLET_KEY= <private_key account for relayer>
L1_TARGET= <target contract to allow relays to, set to 0x0 to skip>
```

Running the message relayer
for tests
```
TEST_PRIVATE_KEY_1=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
TEST_PRIVATE_KEY_2=0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d
TEST_PRIVATE_KEY_3=0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a
```

cd relayer_service
yarn install
yarn build
yarn start
optional - while running message relayer for specific custom messenger
```
L1_MESSENGER_FAST= <optional>
```

### Additional Setting for stopping failed relay attempts

- Add the target contract to the default message relayer's blacklist
- Set the L1_TARGET=<target_contract> for custom message relayer

### Deploying only Custom messenger

Deploy with the deployer private key to also register the custom messenger
```
yarn deploy:contracts
```

#### Deploying only Custom Relayer

```
yarn start:service
```

This starts the service for the registered custom messenger. Specify L1_MESSENGER_FAST=<messenger> to spin up the relayer for your messenger

## Build a DockerHub Message Relayer Alt
## Build a DockerHub Message Relayer Fast

To build the Message Relayer Alt docker image:
To build the Message Relayer Fast docker image:

```bash

docker build . --file Dockerfile.message-relayer-fast --tag omgx/custom-message-relayer:latest
docker push omgx/custom-message-relayer:latest
docker build . --file Dockerfile.message-relayer-fast --tag omgx/message-relayer-fast:latest
docker push omgx/message-relayer-fast:latest

```
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ pragma solidity >0.5.0 <0.8.0;
pragma experimental ABIEncoderV2;

/* Library Imports */
import { Lib_OVMCodec } from "@eth-optimism/contracts/libraries/codec/Lib_OVMCodec.sol";
import { Lib_AddressResolver } from "@eth-optimism/contracts/libraries/resolver/Lib_AddressResolver.sol";
import { Lib_AddressManager } from "@eth-optimism/contracts/libraries/resolver/Lib_AddressManager.sol";
import { Lib_SecureMerkleTrie } from "@eth-optimism/contracts/libraries/trie/Lib_SecureMerkleTrie.sol";
import { Lib_OVMCodec } from "@eth-optimism/contracts/contracts/optimistic-ethereum/libraries/codec/Lib_OVMCodec.sol";
import { Lib_AddressResolver } from "@eth-optimism/contracts/contracts/optimistic-ethereum/libraries/resolver/Lib_AddressResolver.sol";
import { Lib_AddressManager } from "@eth-optimism/contracts/contracts/optimistic-ethereum/libraries/resolver/Lib_AddressManager.sol";
import { Lib_SecureMerkleTrie } from "@eth-optimism/contracts/contracts/optimistic-ethereum/libraries/trie/Lib_SecureMerkleTrie.sol";

/* Interface Imports */
import { iOVM_L1CrossDomainMessenger } from "@eth-optimism/contracts/iOVM/bridge/messaging/iOVM_L1CrossDomainMessenger.sol";
import { iOVM_CanonicalTransactionChain } from "@eth-optimism/contracts/iOVM/chain/iOVM_CanonicalTransactionChain.sol";
import { iOVM_StateCommitmentChain } from "@eth-optimism/contracts/iOVM/chain/iOVM_StateCommitmentChain.sol";
import { iOVM_L1CrossDomainMessenger } from "@eth-optimism/contracts/contracts/optimistic-ethereum/iOVM/bridge/messaging/iOVM_L1CrossDomainMessenger.sol";
import { iOVM_CanonicalTransactionChain } from "@eth-optimism/contracts/contracts/optimistic-ethereum/iOVM/chain/iOVM_CanonicalTransactionChain.sol";
import { iOVM_StateCommitmentChain } from "@eth-optimism/contracts/contracts/optimistic-ethereum/iOVM/chain/iOVM_StateCommitmentChain.sol";

/* Contract Imports */
import { Abs_BaseCrossDomainMessenger } from "@eth-optimism/contracts/OVM/bridge/messaging/Abs_BaseCrossDomainMessenger.sol";
import { Abs_BaseCrossDomainMessenger } from "@eth-optimism/contracts/contracts/optimistic-ethereum/OVM/bridge/messaging/Abs_BaseCrossDomainMessenger.sol";

/**
* @title OVM_L1CrossDomainMessenger
Expand All @@ -25,7 +25,7 @@ import { Abs_BaseCrossDomainMessenger } from "@eth-optimism/contracts/OVM/bridge
* Compiler used: solc
* Runtime target: EVM
*/
contract OVM_L1CrossDomainMessenger is iOVM_L1CrossDomainMessenger, Abs_BaseCrossDomainMessenger, Lib_AddressResolver {
contract OVM_L1CrossDomainMessengerFast is iOVM_L1CrossDomainMessenger, Abs_BaseCrossDomainMessenger, Lib_AddressResolver {

/***************
* Constructor *
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
// SPDX-License-Identifier: MIT
pragma solidity >0.5.0 <0.8.0;
/* Interface Imports */
import { iAbs_BaseCrossDomainMessenger } from "@eth-optimism/contracts/iOVM/bridge/messaging/iAbs_BaseCrossDomainMessenger.sol";
import { iAbs_BaseCrossDomainMessenger } from "@eth-optimism/contracts/contracts/optimistic-ethereum/iOVM/bridge/messaging/iAbs_BaseCrossDomainMessenger.sol";

/**
* @title OVM_CrossDomainEnabled
* @title OVM_CrossDomainEnabledFast
* @dev Helper contract for contracts performing cross-domain communications
*
* Compiler used: defined by inheriting contract
* Runtime target: defined by inheriting contract
*/
contract OVM_CrossDomainEnabled {
// Messenger contract used to send and recieve messages from the other domain.
contract OVM_CrossDomainEnabledFast {

// Messenger contract used to send and receive messages from the other domain.
address public senderMessenger;
address public relayerMessenger;

Expand Down
66 changes: 66 additions & 0 deletions packages/omgx/message-relayer-fast/contracts/message/L1Message.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// SPDX-License-Identifier: MIT
pragma solidity >0.5.0;

/* Library Imports */
import "../libraries/OVM_CrossDomainEnabledFast.sol";
import { L2Message } from "./L2Message.sol";

contract L1Message is OVM_CrossDomainEnabledFast {

address L2MessageAddress;
string crossDomainMessage;

event ReceiveL2Message (
string _message
);

/********************
* Constructor *
********************/
constructor (
address _l1CrossDomainMessenger,
address _l1CrossDomainMessengerFast
)
OVM_CrossDomainEnabledFast(_l1CrossDomainMessenger, _l1CrossDomainMessengerFast)
{}

function init (
address _L2MessageAddress
)
public
{
L2MessageAddress = _L2MessageAddress;
}

function sendMessageL1ToL2 () public {
bytes memory data = abi.encodeWithSelector(
L2Message.receiveL1Message.selector,
"messageFromL1"
);

// Send calldata into L1
sendCrossDomainMessage(
address(L2MessageAddress),
data,
1200000
);
}

/*************************
* Cross-chain Functions *
*************************/

/**
* Receive message from L2
* @param _message message
*/
function receiveL2Message(
string memory _message
)
external
onlyFromCrossDomainAccount(address(L2MessageAddress))
{
crossDomainMessage = _message;
emit ReceiveL2Message(_message);
}
}
68 changes: 68 additions & 0 deletions packages/omgx/message-relayer-fast/contracts/message/L2Message.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// SPDX-License-Identifier: MIT
pragma solidity >0.5.0;

/* Library Imports */
import "@eth-optimism/contracts/contracts/optimistic-ethereum/libraries/bridge/OVM_CrossDomainEnabled.sol";
import { L1Message } from "./L1Message.sol";

contract L2Message is OVM_CrossDomainEnabled {

address L1MessageAddress;
string crossDomainMessage;

event ReceiveL1Message (
string _message
);

/********************
* Constructor *
********************/
/**
* @param _l2CrossDomainMessenger L2 Messenger address being used for sending the cross-chain message.
*/
constructor (
address _l2CrossDomainMessenger
)
OVM_CrossDomainEnabled(_l2CrossDomainMessenger)
{}

function init (
address _L1MessageAddress
)
public
{
L1MessageAddress = _L1MessageAddress;
}

function sendMessageL2ToL1 () public {
bytes memory data = abi.encodeWithSelector(
L1Message.receiveL2Message.selector,
"messageFromL2"
);

// Send calldata into L1
sendCrossDomainMessage(
address(L1MessageAddress),
data,
100000
);
}

/*************************
* Cross-chain Functions *
*************************/

/**
* Receive message from L1
* @param _message message
*/
function receiveL1Message(
string memory _message
)
external
onlyFromCrossDomainAccount(address(L1MessageAddress))
{
crossDomainMessage = _message;
emit ReceiveL1Message(_message);
}
}
36 changes: 36 additions & 0 deletions packages/omgx/message-relayer-fast/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { HardhatUserConfig } from 'hardhat/types'
import '@nomiclabs/hardhat-ethers'
import '@nomiclabs/hardhat-waffle'
import '@eth-optimism/hardhat-ovm'
import 'hardhat-deploy'

const config: HardhatUserConfig = {
mocha: {
timeout: 200000,
},
networks: {
omgx: {
url: 'http://localhost:8545',
// This sets the gas price to 0 for all transactions on L2. We do this
// because account balances are not automatically initiated with an ETH
// balance.
gasPrice: 0,
ovm: true,
},
localhost: {
url: "http://localhost:9545",
allowUnlimitedContractSize: true,
timeout: 1800000,
accounts: ['0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80']
},
},
solidity: '0.7.6',
ovm: {
solcVersion: '0.7.6',
},
namedAccounts: {
deployer: 0
}
}

export default config
Loading

0 comments on commit 9a2f10b

Please sign in to comment.