From b833ed8a5e4701f37b5bc187df105e96862024c9 Mon Sep 17 00:00:00 2001 From: Alexey Date: Thu, 5 Dec 2019 15:51:01 +0300 Subject: [PATCH 1/2] gas oracle fix; entry point update; docker-compose removing --- README.md | 25 +++++++++++++------------ app.js | 1 + config.js | 2 +- deploy/kovan/docker-compose.yml | 18 ------------------ deploy/mainnet/docker-compose.yml | 18 ------------------ package.json | 4 ++-- src/Fetcher.js | 15 ++++++++++----- src/index.js | 2 +- 8 files changed, 28 insertions(+), 57 deletions(-) create mode 100644 app.js delete mode 100644 deploy/kovan/docker-compose.yml delete mode 100644 deploy/mainnet/docker-compose.yml diff --git a/README.md b/README.md index b983ea0..42934a6 100644 --- a/README.md +++ b/README.md @@ -1,22 +1,23 @@ # Relayer for Tornado mixer [![Build Status](https://travis-ci.org/tornadocash/relayer.svg?branch=master)](https://travis-ci.org/tornadocash/relayer) [![Docker Cloud Build Status](https://img.shields.io/docker/cloud/build/tornadocash/relayer.svg)](https://hub.docker.com/r/tornadocash/relayer/builds) -## Setup +## Run locally 1. `npm i` 2. `cp .env.example .env` 3. Modify `.env` as needed -4. If you want to change contracts' addresses go to [config.js](./config.js) file. - -## Deploy Kovan -1. `cp .env.example deploy/kovan/.env` -2. `cd deploy/kovan` -2. Modify `.env` as needed -3. `docker-compose -p kovan up -d` - -## Run locally -1. `npm run start` -2. `curl -X POST -H 'content-type:application/json' --data '' http://127.0.0.1:8000/relay` +4. `npm run start` +5. Go to `http://127.0.0.1:8000` +6. In order to execute withdraw request, you can run following command +```bash +curl -X POST -H 'content-type:application/json' --data '' http://127.0.0.1:8000/relay +``` Relayer should return a transaction hash. +*Note.* If you want to change contracts' addresses go to [config.js](./config.js) file. + +## Deploy as a Docker container +1. `cp .env.example .env` +2. Modify `.env` as needed +3. `docker run -d --env-file .env -p 80:8000 tornadocash/relayer:v2` ## Input data example ```json diff --git a/app.js b/app.js new file mode 100644 index 0000000..93dd2bc --- /dev/null +++ b/app.js @@ -0,0 +1 @@ +module.exports = require('./src/index') \ No newline at end of file diff --git a/config.js b/config.js index e5a96d3..b14e1ed 100644 --- a/config.js +++ b/config.js @@ -50,7 +50,7 @@ module.exports = { } }, defaultGasPrice: 2, - gasOracleUrls: ['https://www.etherchain.org/api/gasPriceOracle', 'https://gasprice.poa.network/'], + gasOracleUrls: ['https://ethgasstation.info/json/ethgasAPI.json', 'https://gasprice.poa.network/'], port: process.env.APP_PORT, relayerServiceFee: Number(process.env.RELAYER_FEE) } \ No newline at end of file diff --git a/deploy/kovan/docker-compose.yml b/deploy/kovan/docker-compose.yml deleted file mode 100644 index 2594476..0000000 --- a/deploy/kovan/docker-compose.yml +++ /dev/null @@ -1,18 +0,0 @@ -version: '2.2' - -services: - relayer: - build: ../../ - restart: always - environment: - NODE_ENV: production - VIRTUAL_HOST: kovan.tornado.cash - LETSENCRYPT_HOST: kovan.tornado.cash - env_file: ./.env - healthcheck: - test: curl -sS http://127.0.0.1:8000 || exit 1 - -networks: - default: - external: - name: frontend_default \ No newline at end of file diff --git a/deploy/mainnet/docker-compose.yml b/deploy/mainnet/docker-compose.yml deleted file mode 100644 index 2f1c21c..0000000 --- a/deploy/mainnet/docker-compose.yml +++ /dev/null @@ -1,18 +0,0 @@ -version: '2.2' - -services: - relayer: - build: ../../ - restart: always - environment: - NODE_ENV: production - VIRTUAL_HOST: mainnet.tornado.cash - LETSENCRYPT_HOST: mainnet.tornado.cash - env_file: ./.env - healthcheck: - test: curl -sS http://127.0.0.1:8000 || exit 1 - -networks: - default: - external: - name: frontend_default \ No newline at end of file diff --git a/package.json b/package.json index 3564874..4966f1b 100644 --- a/package.json +++ b/package.json @@ -2,9 +2,9 @@ "name": "relay", "version": "1.0.0", "description": "Relayer for Tornado mixer. https://tornado.cash", - "main": "src/index.js", + "main": "app.js", "scripts": { - "start": "node src/index.js", + "start": "node app.js", "eslint": "npx eslint --ignore-path .gitignore .", "test": "echo \"Error: no test specified\" && exit 1" }, diff --git a/src/Fetcher.js b/src/Fetcher.js index 5e16f0c..b3a2485 100644 --- a/src/Fetcher.js +++ b/src/Fetcher.js @@ -38,22 +38,27 @@ class Fetcher { } async fetchGasPrice({ oracleIndex = 0 } = {}) { oracleIndex = (oracleIndex + 1) % gasOracleUrls.length + const url = gasOracleUrls[oracleIndex] + const delimiter = url === 'https://ethgasstation.info/json/ethgasAPI.json' ? 10 : 1 try { - const response = await fetch(gasOracleUrls[oracleIndex]) + const response = await fetch(url) if (response.status === 200) { const json = await response.json() + if (Number(json.fast) === 0) { + throw new Error('Fetch gasPrice failed') + } if (json.slow) { - this.gasPrices.low = Number(json.slow) + this.gasPrices.low = Number(json.slow) / delimiter } if (json.safeLow) { - this.gasPrices.low = Number(json.safeLow) + this.gasPrices.low = Number(json.safeLow) / delimiter } if (json.standard) { - this.gasPrices.standard = Number(json.standard) + this.gasPrices.standard = Number(json.standard) / delimiter } if (json.fast) { - this.gasPrices.fast = Number(json.fast) + this.gasPrices.fast = Number(json.fast) / delimiter } } else { throw Error('Fetch gasPrice failed') diff --git a/src/index.js b/src/index.js index f505d50..819c6d2 100644 --- a/src/index.js +++ b/src/index.js @@ -25,7 +25,7 @@ app.use(function(req, res, next) { app.get('/', function (req, res) { // just for testing purposes - res.send('This is tornado.cash Relayer service. Check the /status for settings') + res.send('This is tornado.cash Relayer service. Check the /status for settings') }) app.get('/status', function (req, res) { From d356478cd6b3eaeaea67da8912787c3c03adbc0b Mon Sep 17 00:00:00 2001 From: Alexey Date: Thu, 5 Dec 2019 17:41:12 +0300 Subject: [PATCH 2/2] fix docker command --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 42934a6..2bfb9ac 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Relayer should return a transaction hash. ## Deploy as a Docker container 1. `cp .env.example .env` 2. Modify `.env` as needed -3. `docker run -d --env-file .env -p 80:8000 tornadocash/relayer:v2` +3. `docker run -d --env-file .env -p 80:8000 tornadocash/relayer` ## Input data example ```json