show errors on status page

This commit is contained in:
smart_ex 2022-04-07 15:02:28 +10:00 committed by Danil Kovtonyuk
parent 8868040882
commit cfcf1c8677
5 changed files with 13 additions and 19 deletions

View File

@ -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,
})
}

View File

@ -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 })
}
}

View File

@ -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)
}
}

View File

@ -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)
}
}

View File

@ -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(