Skip to content

V5 update #106

Draft
wants to merge 60 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
4595085
wip
smart-ex May 10, 2022
8d2bad2
update contracts abis
smart-ex May 12, 2022
6f66b34
remove mining related staff
smart-ex May 12, 2022
9f17840
set relayer mode on init()
smart-ex May 12, 2022
8e3f20f
wip
smart-ex May 13, 2022
8bc5b7b
wip. relayer job flow. server api
smart-ex May 18, 2022
ae61e3e
clean up
smart-ex May 18, 2022
82d3cc6
wip DI implemented, Queue helpers
smart-ex May 23, 2022
1828228
wip tx queue worker
smart-ex May 23, 2022
1a375d1
wip tx service update with DI
smart-ex May 23, 2022
fecac18
Fallback gas prices for light mode
smart-ex May 26, 2022
3279eea
ERC20 abi Torn token
smart-ex May 26, 2022
bee7d46
ERC20 abis
smart-ex May 26, 2022
a35207e
TG notifier
smart-ex May 26, 2022
3a74ebf
dependencies upgrade
smart-ex Jun 6, 2022
03f9bfa
WIP monitoring and alerts
smart-ex Jun 8, 2022
ec2f20b
WIP clear redis store on init. Notifier state
smart-ex Jun 9, 2022
978c70d
WIP health service, error handling
smart-ex Jun 10, 2022
2c20feb
send alert for tx errors, update docker
smart-ex Jun 14, 2022
66dc7ef
use simple pup/sub chanel
smart-ex Jun 22, 2022
eef6bb2
add MockTelegram
smart-ex Jun 22, 2022
3626057
job link
smart-ex Jun 22, 2022
bd0f8d2
update libs, docker file, lint
smart-ex Jun 29, 2022
e997d4d
lint
smart-ex Jun 29, 2022
b48a44a
updates and fixes
smart-ex Jun 30, 2022
1532bfc
updates and fixes 2
smart-ex Jun 30, 2022
5aebdab
yml lint
smart-ex Jun 30, 2022
8c027db
fix pub/sub
smart-ex Jun 30, 2022
cff6427
add name prefix to notify
smart-ex Jul 1, 2022
8649a5d
update conf
smart-ex Jul 1, 2022
a4fdada
tx-manager conf from env
smart-ex Jul 4, 2022
9a0e395
server deps major updates
smart-ex Jul 4, 2022
e8e1384
server deps major updates 2
smart-ex Jul 4, 2022
02d64f6
workflow debug
smart-ex Jul 4, 2022
5de5285
workflow debug
smart-ex Jul 4, 2022
4edf32a
update dockerfile
smart-ex Jul 4, 2022
0e1a904
update config and worker
smart-ex Jul 4, 2022
29fa454
update env config, send alerts for SEND_ERROR code
smart-ex Jul 5, 2022
7557158
error handling
smart-ex Jul 5, 2022
4f63a33
update deps
smart-ex Jul 6, 2022
de279a9
add OVM gas oracle, typechain
smart-ex Jul 7, 2022
be969ca
Fix gasLimits config, check l1Fee for optimism
smart-ex Jul 7, 2022
185b18b
tornado classic fee estimate compatibility
smart-ex Jul 7, 2022
591c2d9
relayer tx job attempts
smart-ex Jul 7, 2022
d32ff07
cleanup and formatting code
smart-ex Jul 8, 2022
15d5529
yarn start
smart-ex Jul 8, 2022
761900d
set resubmitted job status
smart-ex Jul 8, 2022
cf3ed4e
update deps
dan1kov Jul 15, 2022
09429eb
check update job
smart-ex Jul 26, 2022
74dbd94
update docker image, compose file
smart-ex Jul 26, 2022
0ce5dcb
update dockerfile and start commands
smart-ex Jul 28, 2022
32b7714
update readme
smart-ex Jul 28, 2022
340df8b
cleanup
smart-ex Jul 29, 2022
21aac61
update workflow
smart-ex Jul 29, 2022
833b89c
update rpc-node link https://github.com/tornadocash/rpc-nodes
smart-ex Aug 1, 2022
5a8b624
update start command, cleanup
smart-ex Aug 2, 2022
ed0a389
update Dockerfile
smart-ex Aug 2, 2022
1b4f25c
fix types, checkUpdate interval
smart-ex Aug 5, 2022
72f0e83
add tests, update deps
smart-ex Aug 5, 2022
9231f3f
check version fallback
smart-ex Aug 5, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
node_modules
.env
.git
.git
build
test
.nyc_output
7 changes: 4 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
NET_ID=1
HTTP_RPC_URL=https://mainnet.infura.io
WS_RPC_URL=wss://mainnet.infura.io/ws/v3/
# ORACLE_RPC_URL should always point to the mainnet
ORACLE_RPC_URL=https://mainnet.infura.io
REDIS_URL=redis://127.0.0.1:6379
Expand All @@ -14,11 +13,13 @@ APP_PORT=8000
PRIVATE_KEY=
# 0.05 means 0.05%
REGULAR_TORNADO_WITHDRAW_FEE=0.05
MINING_SERVICE_FEE=0.05
REWARD_ACCOUNT=
REWARD_ACCOUNT=0x...
CONFIRMATIONS=4

# in GWEI
MAX_GAS_PRICE=1000
BASE_FEE_RESERVE_PERCENTAGE=25
AGGREGATOR=0x8cb1436F64a3c33aD17bb42F94e255c4c0E871b2
# Telegram bot alerts
TELEGRAM_NOTIFIER_BOT_TOKEN=
TELEGRAM_NOTIFIER_CHAT_ID=
46 changes: 11 additions & 35 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,45 +1,21 @@
{
"env": {
"node": true,
"browser": true,
"es6": true,
"mocha": true
},
"extends": "eslint:recommended",
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
"commonjs": true,
"es2020": true
},
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "prettier"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2018
"ecmaVersion": 11
},
"plugins": ["@typescript-eslint"],
"rules": {
"indent": [
"error",
2,
{
"SwitchCase": 1
}
],
"linebreak-style": ["error", "unix"],
"quotes": [
"error",
"single",
{
"avoidEscape": true
}
],
"semi": ["error", "never"],
"object-curly-spacing": ["error", "always"],
"require-await": "error",
"comma-dangle": ["error", "only-multiline"],
"space-before-function-paren": [
"error",
{
"anonymous": "always",
"named": "never",
"asyncArrow": "always"
}
]
"quotes": ["error", "single"],
"semi": ["error", "always"],
"no-useless-catch": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/explicit-module-boundary-types": "off"
}
}
16 changes: 6 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ jobs:
uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12
node-version: 16
- run: yarn install
- run: yarn test
- run: yarn lint
- name: Telegram Failure Notification
uses: appleboy/telegram-action@master
Expand All @@ -26,7 +25,6 @@ jobs:
format: markdown
to: ${{ secrets.TELEGRAM_CHAT_ID }}
token: ${{ secrets.TELEGRAM_BOT_TOKEN }}

publish:
runs-on: ubuntu-latest
needs: build
Expand All @@ -51,7 +49,7 @@ jobs:
dockerfile: Dockerfile
repository: tornadocash/relayer
tag_with_ref: true
tags: mining,candidate
tags: candidate
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}

Expand All @@ -70,10 +68,9 @@ jobs:
to: ${{ secrets.TELEGRAM_RELAYER_CHAT_ID }}
token: ${{ secrets.TELEGRAM_BOT_TOKEN }}
message: |
🚀 Published a new version of the relayer node service for mainnet to docker hub: `tornadocash/relayer:v${{ steps.vars.outputs.version }}` and `tornadocash/relayer:mining`.
🚀 Published a new version of the relayer node service to docker hub: `tornadocash/relayer:v${{ steps.vars.outputs.version }}` and `tornadocash/relayer`.

❗️Please update your mainnet nodes ❗️
DO NOT TOUCH SIDECHAINS AND NOVA RELAYERS.
❗️Please update your nodes ❗️

debug: true
format: markdown
Expand All @@ -84,10 +81,9 @@ jobs:
uses: Ilshidur/action-discord@master
with:
args: |
🚀 Published a new version of the relayer node service for mainnet to docker hub: `tornadocash/relayer:v${{ steps.vars.outputs.version }}` and `tornadocash/relayer:mining`.
🚀 Published a new version of the relayer node service to docker hub: `tornadocash/relayer:v${{ steps.vars.outputs.version }}` and `tornadocash/relayer`.

❗️Please update your mainnet nodes ❗️
DO NOT TOUCH SIDECHAINS AND NOVA RELAYERS.
❗️Please update your nodes ❗️

- name: Telegram Failure Notification
uses: appleboy/telegram-action@master
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ node_modules/
kovan.*
dump.rdb
.idea
build
.nyc_output
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v16.15
1 change: 0 additions & 1 deletion .prettierignore

This file was deleted.

8 changes: 4 additions & 4 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"semi": false,
"arrowParens": "avoid",
"semi": true,
"trailingComma": "all",
"singleQuote": true,
"printWidth": 110,
"trailingComma": "all"
"printWidth": 130,
"tabWidth": 2
}
29 changes: 24 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
FROM node:12
FROM node:16-alpine as dev

ENV NODE_ENV=development

WORKDIR /usr/app

COPY yarn.lock .
COPY package.json .
RUN apk update && apk add --no-cache g++ make python3 && rm -rf /var/cache/apk/*
RUN yarn install
COPY . ./

RUN yarn build

FROM node:16-alpine as prod
ENV NODE_ENV=production

WORKDIR /app

COPY package.json yarn.lock ./
RUN yarn && yarn cache clean --force
COPY . .
RUN apk update && apk add --no-cache g++ make python3 && rm -rf /var/cache/apk/*

COPY --from=dev /usr/app/ /app
COPY --from=dev /usr/app/package.json /app/
COPY --from=dev /usr/app/yarn.lock /app/

RUN yarn install && yarn cache clean -f

EXPOSE 8000
ENTRYPOINT ["yarn"]
106 changes: 78 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

## Deploy with docker-compose

docker-compose.yml contains a stack that will automatically provision SSL certificates for your domain name and will add a https redirect to port 80.
docker-compose.yml contains a stack that will automatically provision SSL certificates for your domain name and will add
a https redirect to port 80.

1. Download [docker-compose.yml](/docker-compose.yml) and [.env.example](/.env.example)

Expand All @@ -13,24 +14,50 @@ wget https://raw.githubusercontent.com/tornadocash/tornado-relayer/master/.env.e

2. Setup environment variables

- set `NET_ID` (1 for mainnet, 5 for Goerli)
- set `HTTP_RPC_URL` rpc url for your ethereum node
- set `WS_RPC_URL` websocket url
- set `ORACLE_RPC_URL` - rpc url for mainnet node for fetching prices(always have to be on mainnet)
- set `PRIVATE_KEY` for your relayer address (without 0x prefix)
- set `VIRTUAL_HOST` and `LETSENCRYPT_HOST` to your domain and add DNS record pointing to your relayer ip address
- set `REGULAR_TORNADO_WITHDRAW_FEE` - fee in % that is used for tornado pool withdrawals
- set `MINING_SERVICE_FEE` - fee in % that is used for mining AP withdrawals
- set `REWARD_ACCOUNT` - eth address that is used to collect fees
- update `AGGREGATOR` if needed - Contract address of aggregator instance.
- update `CONFIRMATIONS` if needed - how many block confirmations to wait before processing an event. Not recommended to set less than 3
- update `MAX_GAS_PRICE` if needed - maximum value of gwei value for relayer's transaction
- update `BASE_FEE_RESERVE_PERCENTAGE` if needed - how much in % will the network baseFee increase

If you want to use more than 1 eth address for relaying transactions, please add as many `workers` as you want. For example, you can comment out `worker2` in docker-compose.yml file, but please use a different `PRIVATE_KEY` for each worker.
- set `NET_ID` (1 for mainnet, [networks list](#compatible-networks))
- set `HTTP_RPC_URL` rpc url for your ethereum node
- set `ORACLE_RPC_URL` - rpc url for mainnet node for fetching prices(always have to be on mainnet)
- set `PRIVATE_KEY` for your relayer address (without 0x prefix)
- set `VIRTUAL_HOST` and `LETSENCRYPT_HOST` to your domain and add DNS record pointing to your relayer ip address
- set `REGULAR_TORNADO_WITHDRAW_FEE` - fee in % that is used for tornado pool withdrawals
- set `REWARD_ACCOUNT` - eth address that is used to collect fees
- update `AGGREGATOR` if needed - Contract address of aggregator instance.
- update `CONFIRMATIONS` if needed - how many block confirmations to wait before processing an event. Not recommended
to set less than 3
- update `MAX_GAS_PRICE` if needed - maximum value of gwei value for relayer's transaction
- update `BASE_FEE_RESERVE_PERCENTAGE` if needed - how much in % will the network baseFee increase
- set `TELEGRAM_NOTIFIER_BOT_TOKEN` and `TELEGRAM_NOTIFIER_CHAT_ID` if your want get notify to telegram

If you want to use more than 1 eth address for relaying transactions, please add as many `workers` as you want. For
example, you can comment out `worker2` in docker-compose.yml file, but please use a different `PRIVATE_KEY` for each
worker.

3. Run `docker-compose up -d`

## V5 Migration Guide

This guide is intended to help with migration from Relayer v4 to v5.

1. Stop relayer

```
docker-compose down
```

2. Download the latest version of relayer`s docker compose file

```
wget https://raw.githubusercontent.com/tornadocash/tornado-relayer/master/docker-compose.yml
```

3. Check your environment variables, add new ones if needed

4. Run updated docker compose file

```
docker-compose up -d --pull
```

## Run locally

1. `yarn`
Expand All @@ -41,32 +68,55 @@ wget https://raw.githubusercontent.com/tornadocash/tornado-relayer/master/.env.e
6. In order to execute withdraw request, you can run following command

```bash
curl -X POST -H 'content-type:application/json' --data '<input data>' http://127.0.0.1:8000/relay
curl -X POST -H 'content-type:application/json' --data '<input data>' http://127.0.0.1:8000/v1/tornadoWithdraw

```

Relayer should return a transaction hash
Relayer should return a job id in uuid v4 format.

In that case you will need to add https termination yourself because browsers with default settings will prevent https
tornado.cash UI from submitting your request over http connection

## Run geth node

It is strongly recommended that you use your own RPC node. Instruction on how to run full node with `geth` can be found [here](https://github.com/feshchenkod/rpc-nodes).
It is strongly recommended that you use your own RPC node. Instruction on how to run full node with `geth` can be
found [here](https://github.com/tornadocash/rpc-nodes).

## Monitoring

### Basic

For basic monitoring setup telegram bot and fill variables in .env file

Alerts about:

- Main relayer currency balance
- Torn balance
- Withdraw transactions send errors

How to create bot: https://core.telegram.org/bots#3-how-do-i-create-a-bot

How to get chat
id: https://stackoverflow.com/questions/32423837/telegram-bot-how-to-get-a-group-chat-id/32572159#32572159

### Advanced

You can find the guide on how to install the Zabbix server in the [/monitoring/README.md](/monitoring/README.md).

## Architecture
## Compatible networks

1. TreeWatcher module keeps track of Account Tree changes and automatically caches the actual state in Redis and emits `treeUpdate` event to redis pub/sub channel
2. Server module is Express.js instance that accepts http requests
3. Controller contains handlers for the Server endpoints. It validates input data and adds a Job to Queue.
4. Queue module is used by Controller to put and get Job from queue (bull wrapper)
5. Status module contains handler to get a Job status. It's used by UI for pull updates
6. Validate contains validation logic for all endpoints
7. Worker is the main module that gets a Job from queue and processes it
- Ethereum Mainnet (1)
- Binance Smart Chain (56)
- Polygon (Matic) Network (137)
- Optimism (10)
- Arbitrum One (42161)
- Gnosis Chain (100)
- Avalanche Mainnet (43114)
- Ethereum Goerli (5)

Disclaimer:

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Loading