mirror of
https://github.com/tornadocash/tornado-relayer
synced 2024-02-02 15:04:06 +01:00
write errors with positive score
This commit is contained in:
parent
50054e0516
commit
8868040882
2
app.js
2
app.js
@ -1 +1 @@
|
|||||||
module.exports = require('./src/index')
|
module.exports = require('./src/server')
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
const { setSafeInterval, toBN, fromWei } = require('./utils')
|
const { setSafeInterval, toBN, fromWei, RelayerError } = require('./utils')
|
||||||
const { privateKey, minimumBalance } = require('./config')
|
const { privateKey, minimumBalance } = require('./config')
|
||||||
const { redis } = require('./modules/redis')
|
const { redis } = require('./modules/redis')
|
||||||
const web3 = require('./modules/web3')()
|
const web3 = require('./modules/web3')()
|
||||||
@ -14,7 +14,7 @@ async function main() {
|
|||||||
throw new Error('Too many errors on relayer')
|
throw new Error('Too many errors on relayer')
|
||||||
}
|
}
|
||||||
if (toBN(balance).lt(toBN(minimumBalance))) {
|
if (toBN(balance).lt(toBN(minimumBalance))) {
|
||||||
throw new Error(`Not enough balance, less than ${fromWei(minimumBalance)} ETH`)
|
throw new RelayerError(`Not enough balance, less than ${fromWei(minimumBalance)} ETH`, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
await redis.hset('health', { status: true, error: '' })
|
await redis.hset('health', { status: true, error: '' })
|
||||||
|
@ -106,7 +106,11 @@ async function start() {
|
|||||||
queue.process(processJob)
|
queue.process(processJob)
|
||||||
console.log('Worker started')
|
console.log('Worker started')
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
redis.zadd('errors', new Date().getTime(), e.message)
|
if (e instanceof RelayerError) {
|
||||||
|
if (e.score > 0) redis.zadd('errors', e.score, e.message)
|
||||||
|
} else {
|
||||||
|
redis.zadd('errors', 1, e.message)
|
||||||
|
}
|
||||||
console.error('error on start worker', e.message)
|
console.error('error on start worker', e.message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -187,9 +191,9 @@ async function checkMiningFee({ args }) {
|
|||||||
const serviceFeePercent = isMiningReward
|
const serviceFeePercent = isMiningReward
|
||||||
? toBN(0)
|
? toBN(0)
|
||||||
: toBN(args.amount)
|
: toBN(args.amount)
|
||||||
.sub(providedFee) // args.amount includes fee
|
.sub(providedFee) // args.amount includes fee
|
||||||
.mul(toBN(parseInt(miningServiceFee * 1e10)))
|
.mul(toBN(parseInt(miningServiceFee * 1e10)))
|
||||||
.div(toBN(1e10 * 100))
|
.div(toBN(1e10 * 100))
|
||||||
/* eslint-enable */
|
/* eslint-enable */
|
||||||
const desiredFee = expenseInPoints.add(serviceFeePercent) // in points
|
const desiredFee = expenseInPoints.add(serviceFeePercent) // in points
|
||||||
console.log(
|
console.log(
|
||||||
@ -199,7 +203,7 @@ async function checkMiningFee({ args }) {
|
|||||||
serviceFeePercent.toString(),
|
serviceFeePercent.toString(),
|
||||||
)
|
)
|
||||||
if (toBN(providedFee).lt(desiredFee)) {
|
if (toBN(providedFee).lt(desiredFee)) {
|
||||||
throw new Error('Provided fee is not enough. Probably it is a Gas Price spike, try to resubmit.')
|
throw new RelayerError('Provided fee is not enough. Probably it is a Gas Price spike, try to resubmit.')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -277,7 +281,7 @@ async function processJob(job) {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('processJob', e.message)
|
console.error('processJob', e.message)
|
||||||
await updateStatus(status.FAILED)
|
await updateStatus(status.FAILED)
|
||||||
throw e
|
throw new RelayerError(e.message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user