Skip to content

Commit

Permalink
Handle default values for tx watcher
Browse files Browse the repository at this point in the history
  • Loading branch information
pertsev committed May 12, 2020
1 parent 7183af7 commit 05a0431
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ NONCE_WATCHER_INTERVAL=30
# how long a tx can be in pending pool (in seconds)
ALLOWABLE_PENDING_TX_TIMEOUT=180
# in GWEI
MAX_GAS_PRICE=100
MAX_GAS_PRICE=200
# how much to increase the gas price for a stuck tx
GAS_PRICE_BUMP_PERCENTAGE=20

10 changes: 5 additions & 5 deletions config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require('dotenv').config()

module.exports = {
version: 2.5,
version: 2.6,
netId: Number(process.env.NET_ID) || 42,
redisUrl: process.env.REDIS_URL,
rpcUrl: process.env.RPC_URL || 'https://kovan.infura.io/',
Expand Down Expand Up @@ -148,8 +148,8 @@ module.exports = {
gasOracleUrls: ['https://ethgasstation.info/json/ethgasAPI.json', 'https://gas-oracle.zoltu.io/'],
port: process.env.APP_PORT,
relayerServiceFee: Number(process.env.RELAYER_FEE),
maxGasPrice: process.env.MAX_GAS_PRICE,
watherInterval: Number(process.env.NONCE_WATCHER_INTERVAL) * 1000,
pendingTxTimeout: Number(process.env.ALLOWABLE_PENDING_TX_TIMEOUT) * 1000,
gasBumpPercentage: process.env.GAS_PRICE_BUMP_PERCENTAGE
maxGasPrice: process.env.MAX_GAS_PRICE || 200,
watherInterval: Number(process.env.NONCE_WATCHER_INTERVAL || 30) * 1000,
pendingTxTimeout: Number(process.env.ALLOWABLE_PENDING_TX_TIMEOUT || 180) * 1000,
gasBumpPercentage: process.env.GAS_PRICE_BUMP_PERCENTAGE || 20
}
31 changes: 28 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
const express = require('express')
const { netId, port, relayerServiceFee, version } = require('../config')
const {
netId,
port,
relayerServiceFee,
version,
gasBumpPercentage,
pendingTxTimeout,
watherInterval,
maxGasPrice
} = require('../config')
const relayController = require('./relayController')
const { fetcher, web3 } = require('./instances')
const { getMixers } = require('./utils')
Expand Down Expand Up @@ -31,7 +40,7 @@ app.get('/', function (req, res) {
app.get('/status', async function (req, res) {
let nonce = await redisClient.get('nonce')
const { ethPrices, gasPrices } = fetcher
res.json({
res.json({
relayerAddress: web3.eth.defaultAccount,
mixers,
gasPrices,
Expand All @@ -58,4 +67,20 @@ console.log(`mixers: ${JSON.stringify(mixers)}`)
console.log(`gasPrices: ${JSON.stringify(fetcher.gasPrices)}`)
console.log(`netId: ${netId}`)
console.log(`ethPrices: ${JSON.stringify(fetcher.ethPrices)}`)
console.log(`Service fee: ${relayerServiceFee}%`)

const { GAS_PRICE_BUMP_PERCENTAGE, ALLOWABLE_PENDING_TX_TIMEOUT, NONCE_WATCHER_INTERVAL, MAX_GAS_PRICE } = process.env
if(!NONCE_WATCHER_INTERVAL) {
console.log(`NONCE_WATCHER_INTERVAL is not set. Using default value ${watherInterval / 1000} sec`)
}

if(!GAS_PRICE_BUMP_PERCENTAGE) {
console.log(`GAS_PRICE_BUMP_PERCENTAGE is not set. Using default value ${gasBumpPercentage}%`)
}

if(!ALLOWABLE_PENDING_TX_TIMEOUT) {
console.log(`ALLOWABLE_PENDING_TX_TIMEOUT is not set. Using default value ${pendingTxTimeout / 1000} sec`)
}

if(!MAX_GAS_PRICE) {
console.log(`ALLOWABLE_PENDING_TX_TIMEOUT is not set. Using default value ${maxGasPrice} Gwei`)
}

0 comments on commit 05a0431

Please sign in to comment.