increment errors score

This commit is contained in:
smart_ex 2022-04-08 20:29:37 +10:00 committed by Danil Kovtonyuk
parent cfcf1c8677
commit 95c6dc23c6
8 changed files with 36 additions and 10 deletions

View File

@ -54,6 +54,8 @@ services:
redis: redis:
image: redis image: redis
restart: always restart: always
ports:
- '6379:6379'
command: [redis-server, --appendonly, 'yes'] command: [redis-server, --appendonly, 'yes']
volumes: volumes:
- redis:/data - redis:/data

View File

@ -2,11 +2,12 @@ const queue = require('../queue')
const { netId, tornadoServiceFee, miningServiceFee, instances, rewardAccount } = require('../config') const { netId, tornadoServiceFee, miningServiceFee, instances, rewardAccount } = require('../config')
const { version } = require('../../package.json') const { version } = require('../../package.json')
const { redis } = require('../modules/redis') const { redis } = require('../modules/redis')
const { readRelayerErrors } = require('../utils')
async function status(req, res) { async function status(req, res) {
const ethPrices = await redis.hgetall('prices') const ethPrices = await redis.hgetall('prices')
const health = await redis.hgetall('health') const health = await redis.hgetall('health')
const errors = await redis.zrevrange('errors', 0, -1) const errors = await readRelayerErrors(redis)
const { waiting: currentQueue } = await queue.queue.getJobCounts() const { waiting: currentQueue } = await queue.queue.getJobCounts()

View File

@ -14,7 +14,6 @@ async function main() {
await redis.hset('health', { status: true, error: '' }) await redis.hset('health', { status: true, error: '' })
} catch (e) { } catch (e) {
console.error('healthWatcher', e.message) console.error('healthWatcher', e.message)
redis.zadd('errors', e.score || 0, e.message)
await redis.hset('health', { status: false, error: e.message }) await redis.hset('health', { status: false, error: e.message })
} }
} }

View File

@ -1,8 +1,8 @@
const Redis = require('ioredis') const { createClient } = require('ioredis')
const { redisUrl } = require('../config') const { redisUrl } = require('../config')
const redis = new Redis(redisUrl) const redis = createClient(redisUrl)
const redisSubscribe = new Redis(redisUrl) const redisSubscribe = createClient(redisUrl)
module.exports = { module.exports = {
redis, redis,

View File

@ -1,5 +1,12 @@
const { offchainOracleAddress } = require('./config') const { offchainOracleAddress } = require('./config')
const { getArgsForOracle, setSafeInterval, toChecksumAddress, toBN, RelayerError } = require('./utils') const {
getArgsForOracle,
setSafeInterval,
toChecksumAddress,
toBN,
RelayerError,
logRelayerError,
} = require('./utils')
const { redis } = require('./modules/redis') const { redis } = require('./modules/redis')
const web3 = require('./modules/web3')() const web3 = require('./modules/web3')()
@ -32,7 +39,7 @@ async function main() {
await redis.hmset('prices', ethPrices) await redis.hmset('prices', ethPrices)
console.log('Wrote following prices to redis', ethPrices) console.log('Wrote following prices to redis', ethPrices)
} catch (e) { } catch (e) {
redis.zadd('errors', e.score || 1, e.message) await logRelayerError(redis, e.message)
console.error('priceWatcher error', e) console.error('priceWatcher error', e)
} }
} }

View File

@ -1,6 +1,6 @@
const MerkleTree = require('fixed-merkle-tree') const MerkleTree = require('fixed-merkle-tree')
const { minerMerkleTreeHeight, torn, netId } = require('./config') const { minerMerkleTreeHeight, torn, netId } = require('./config')
const { poseidonHash2, toBN } = require('./utils') const { poseidonHash2, toBN, logRelayerError } = require('./utils')
const resolver = require('./modules/resolver') const resolver = require('./modules/resolver')
const web3 = require('./modules/web3')('ws') const web3 = require('./modules/web3')('ws')
const MinerABI = require('../abis/mining.abi.json') const MinerABI = require('../abis/mining.abi.json')
@ -123,7 +123,7 @@ async function init() {
eventSubscription = contract.events.NewAccount({ fromBlock: toBlock + 1 }, processNewEvent) eventSubscription = contract.events.NewAccount({ fromBlock: toBlock + 1 }, processNewEvent)
blockSubscription = web3.eth.subscribe('newBlockHeaders', processNewBlock) blockSubscription = web3.eth.subscribe('newBlockHeaders', processNewBlock)
} catch (e) { } catch (e) {
redis.zadd('errors', 1, e.message) await logRelayerError(redis, e.message)
console.error('error on init treeWatcher', e.message) console.error('error on init treeWatcher', e.message)
} }
} }

View File

@ -125,6 +125,20 @@ class RelayerError extends Error {
} }
} }
const logRelayerError = async (redis, e) => {
await redis.zadd('errors', 'INCR', 1, e.message)
}
const readRelayerErrors = async redis => {
const set = await redis.zrevrange('errors', 0, -1, 'WITHSCORES')
const errors = []
while (set.length) {
const [message, score] = set.splice(0, 2)
errors.push({ message, score })
}
return errors
}
module.exports = { module.exports = {
getInstance, getInstance,
setSafeInterval, setSafeInterval,
@ -140,4 +154,6 @@ module.exports = {
BN, BN,
isAddress, isAddress,
RelayerError, RelayerError,
logRelayerError,
readRelayerErrors,
} }

View File

@ -18,6 +18,7 @@ const {
fromWei, fromWei,
toChecksumAddress, toChecksumAddress,
RelayerError, RelayerError,
logRelayerError,
} = require('./utils') } = require('./utils')
const { jobType, status } = require('./constants') const { jobType, status } = require('./constants')
const { const {
@ -106,7 +107,7 @@ async function start() {
queue.process(processJob) queue.process(processJob)
console.log('Worker started') console.log('Worker started')
} catch (e) { } catch (e) {
redis.zadd('errors', e.score || 1, e.message) await logRelayerError(redis, e.message)
console.error('error on start worker', e.message) console.error('error on start worker', e.message)
} }
} }