From cfcf1c86771e3508d78d7a3d8431c2e6b92f7491 Mon Sep 17 00:00:00 2001 From: smart_ex Date: Thu, 7 Apr 2022 15:02:28 +1000 Subject: [PATCH] show errors on status page --- src/contollers/status.js | 2 ++ src/healthWatcher.js | 7 +------ src/priceWatcher.js | 9 +++++---- src/treeWatcher.js | 2 +- src/worker.js | 12 ++++-------- 5 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/contollers/status.js b/src/contollers/status.js index 518ca0a..dae519a 100644 --- a/src/contollers/status.js +++ b/src/contollers/status.js @@ -6,6 +6,7 @@ const { redis } = require('../modules/redis') async function status(req, res) { const ethPrices = await redis.hgetall('prices') const health = await redis.hgetall('health') + const errors = await redis.zrevrange('errors', 0, -1) const { waiting: currentQueue } = await queue.queue.getJobCounts() @@ -18,6 +19,7 @@ async function status(req, res) { miningServiceFee, version, health, + errors, currentQueue, }) } diff --git a/src/healthWatcher.js b/src/healthWatcher.js index d6c2917..f942cf0 100644 --- a/src/healthWatcher.js +++ b/src/healthWatcher.js @@ -7,12 +7,6 @@ async function main() { try { const { address } = web3.eth.accounts.privateKeyToAccount(privateKey) const balance = await web3.eth.getBalance(address) - - const errors = await redis.zrevrange('errors', 0, -1) - if (errors.length > 3) { - console.log({ errors }) - throw new Error('Too many errors on relayer') - } if (toBN(balance).lt(toBN(minimumBalance))) { throw new RelayerError(`Not enough balance, less than ${fromWei(minimumBalance)} ETH`, 1) } @@ -20,6 +14,7 @@ async function main() { await redis.hset('health', { status: true, error: '' }) } catch (e) { console.error('healthWatcher', e.message) + redis.zadd('errors', e.score || 0, e.message) await redis.hset('health', { status: false, error: e.message }) } } diff --git a/src/priceWatcher.js b/src/priceWatcher.js index 41c4608..a41ee7b 100644 --- a/src/priceWatcher.js +++ b/src/priceWatcher.js @@ -1,5 +1,5 @@ const { offchainOracleAddress } = require('./config') -const { getArgsForOracle, setSafeInterval, toChecksumAddress, toBN } = require('./utils') +const { getArgsForOracle, setSafeInterval, toChecksumAddress, toBN, RelayerError } = require('./utils') const { redis } = require('./modules/redis') const web3 = require('./modules/web3')() @@ -21,17 +21,18 @@ async function main() { const numerator = toBN(oneUintAmount[i]) const denominator = toBN(10).pow(toBN(18)) // eth decimals const priceFormatted = toBN(price).mul(numerator).div(denominator) - ethPrices[currencyLookup[tokenAddresses[i]]] = priceFormatted.toString() } catch (e) { console.error('cant get price of ', tokenAddresses[i]) } } - + if (!Object.values(ethPrices).length) { + throw new RelayerError('Can`t update prices', 1) + } await redis.hmset('prices', ethPrices) console.log('Wrote following prices to redis', ethPrices) } catch (e) { - redis.zadd('errors', new Date().getTime(), e.message) + redis.zadd('errors', e.score || 1, e.message) console.error('priceWatcher error', e) } } diff --git a/src/treeWatcher.js b/src/treeWatcher.js index 401dbc5..28e8c9e 100644 --- a/src/treeWatcher.js +++ b/src/treeWatcher.js @@ -123,7 +123,7 @@ async function init() { eventSubscription = contract.events.NewAccount({ fromBlock: toBlock + 1 }, processNewEvent) blockSubscription = web3.eth.subscribe('newBlockHeaders', processNewBlock) } catch (e) { - redis.zadd('errors', new Date().getTime(), e.message) + redis.zadd('errors', 1, e.message) console.error('error on init treeWatcher', e.message) } } diff --git a/src/worker.js b/src/worker.js index fb722f5..aa31685 100644 --- a/src/worker.js +++ b/src/worker.js @@ -106,11 +106,7 @@ async function start() { queue.process(processJob) console.log('Worker started') } catch (e) { - if (e instanceof RelayerError) { - if (e.score > 0) redis.zadd('errors', e.score, e.message) - } else { - redis.zadd('errors', 1, e.message) - } + redis.zadd('errors', e.score || 1, e.message) console.error('error on start worker', e.message) } } @@ -191,9 +187,9 @@ async function checkMiningFee({ args }) { const serviceFeePercent = isMiningReward ? toBN(0) : toBN(args.amount) - .sub(providedFee) // args.amount includes fee - .mul(toBN(parseInt(miningServiceFee * 1e10))) - .div(toBN(1e10 * 100)) + .sub(providedFee) // args.amount includes fee + .mul(toBN(parseInt(miningServiceFee * 1e10))) + .div(toBN(1e10 * 100)) /* eslint-enable */ const desiredFee = expenseInPoints.add(serviceFeePercent) // in points console.log(