Fix insufficient funds error handler (#459)
This commit is contained in:
parent
d17ea2ad2b
commit
fbeb878cdb
@ -177,7 +177,7 @@ async function sendJobTx(jobs) {
|
|||||||
e.message
|
e.message
|
||||||
)
|
)
|
||||||
|
|
||||||
if (e.message.includes('Insufficient funds')) {
|
if (e.message.toLowerCase().includes('insufficient funds')) {
|
||||||
const currentBalance = await web3Instance.eth.getBalance(ORACLE_VALIDATOR_ADDRESS)
|
const currentBalance = await web3Instance.eth.getBalance(ORACLE_VALIDATOR_ADDRESS)
|
||||||
const minimumBalance = gasLimit.multipliedBy(gasPrice)
|
const minimumBalance = gasLimit.multipliedBy(gasPrice)
|
||||||
logger.error(
|
logger.error(
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
require('../env')
|
require('../env')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const { toBN } = require('web3-utils')
|
|
||||||
const { connectSenderToQueue } = require('./services/amqpClient')
|
const { connectSenderToQueue } = require('./services/amqpClient')
|
||||||
const { redis } = require('./services/redisClient')
|
const { redis } = require('./services/redisClient')
|
||||||
const GasPrice = require('./services/gasPrice')
|
const GasPrice = require('./services/gasPrice')
|
||||||
@ -98,10 +97,10 @@ async function main({ msg, ackMsg, nackMsg, channel, scheduleForRetry, scheduleT
|
|||||||
}
|
}
|
||||||
|
|
||||||
const txArray = JSON.parse(msg.content)
|
const txArray = JSON.parse(msg.content)
|
||||||
logger.info(`Msg received with ${txArray.length} Tx to send`)
|
logger.debug(`Msg received with ${txArray.length} Tx to send`)
|
||||||
const gasPrice = GasPrice.getPrice()
|
const gasPrice = GasPrice.getPrice()
|
||||||
|
|
||||||
let nonce = await readNonce()
|
let nonce
|
||||||
let insufficientFunds = false
|
let insufficientFunds = false
|
||||||
let minimumBalance = null
|
let minimumBalance = null
|
||||||
const failedTx = []
|
const failedTx = []
|
||||||
@ -110,9 +109,11 @@ async function main({ msg, ackMsg, nackMsg, channel, scheduleForRetry, scheduleT
|
|||||||
const isResend = txArray.length > 0 && !!txArray[0].txHash
|
const isResend = txArray.length > 0 && !!txArray[0].txHash
|
||||||
|
|
||||||
if (isResend) {
|
if (isResend) {
|
||||||
logger.debug(`Checking status of ${txArray.length} transactions`)
|
logger.info(`Checking status of ${txArray.length} transactions`)
|
||||||
|
nonce = null
|
||||||
} else {
|
} else {
|
||||||
logger.debug(`Sending ${txArray.length} transactions`)
|
logger.info(`Sending ${txArray.length} transactions`)
|
||||||
|
nonce = await readNonce()
|
||||||
}
|
}
|
||||||
await syncForEach(txArray, async job => {
|
await syncForEach(txArray, async job => {
|
||||||
let gasLimit
|
let gasLimit
|
||||||
@ -131,23 +132,20 @@ async function main({ msg, ackMsg, nackMsg, channel, scheduleForRetry, scheduleT
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info(
|
if (nonce === null) {
|
||||||
`Previously sent transaction is stuck, updating gasPrice: ${job.gasPrice} -> ${gasPrice.toString(10)}`
|
nonce = await readNonce(true)
|
||||||
)
|
|
||||||
if (toBN(job.gasPrice).gte(toBN(gasPrice))) {
|
|
||||||
logger.info("Gas price returned from the oracle didn't increase, will reinspect this transaction later")
|
|
||||||
sentTx.push(job)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
job.nonce = nonce++
|
logger.info(
|
||||||
|
`Transaction ${job.txHash} was not mined, updating gasPrice: ${job.gasPrice} -> ${gasPrice.toString(10)}`
|
||||||
|
)
|
||||||
}
|
}
|
||||||
logger.info(`Sending transaction with nonce ${job.nonce}`)
|
logger.info(`Sending transaction with nonce ${nonce}`)
|
||||||
job.gasPrice = gasPrice.toString(10)
|
job.gasPrice = gasPrice.toString(10)
|
||||||
job.txHash = await sendTx({
|
job.txHash = await sendTx({
|
||||||
chain: config.id,
|
chain: config.id,
|
||||||
data: job.data,
|
data: job.data,
|
||||||
nonce: job.nonce,
|
nonce,
|
||||||
gasPrice: job.gasPrice,
|
gasPrice: job.gasPrice,
|
||||||
amount: '0',
|
amount: '0',
|
||||||
gasLimit,
|
gasLimit,
|
||||||
@ -158,6 +156,7 @@ async function main({ msg, ackMsg, nackMsg, channel, scheduleForRetry, scheduleT
|
|||||||
})
|
})
|
||||||
sentTx.push(job)
|
sentTx.push(job)
|
||||||
|
|
||||||
|
nonce++
|
||||||
logger.info(
|
logger.info(
|
||||||
{ eventTransactionHash: job.transactionReference, generatedTransactionHash: job.txHash },
|
{ eventTransactionHash: job.transactionReference, generatedTransactionHash: job.txHash },
|
||||||
`Tx generated ${job.txHash} for event Tx ${job.transactionReference}`
|
`Tx generated ${job.txHash} for event Tx ${job.transactionReference}`
|
||||||
@ -168,11 +167,11 @@ async function main({ msg, ackMsg, nackMsg, channel, scheduleForRetry, scheduleT
|
|||||||
`Tx Failed for event Tx ${job.transactionReference}.`,
|
`Tx Failed for event Tx ${job.transactionReference}.`,
|
||||||
e.message
|
e.message
|
||||||
)
|
)
|
||||||
if (!e.message.includes('Transaction with the same hash was already imported')) {
|
if (!e.message.toLowerCase().includes('transaction with the same hash was already imported')) {
|
||||||
failedTx.push(job)
|
failedTx.push(job)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e.message.includes('Insufficient funds')) {
|
if (e.message.toLowerCase().includes('insufficient funds')) {
|
||||||
insufficientFunds = true
|
insufficientFunds = true
|
||||||
const currentBalance = await web3Instance.eth.getBalance(ORACLE_VALIDATOR_ADDRESS)
|
const currentBalance = await web3Instance.eth.getBalance(ORACLE_VALIDATOR_ADDRESS)
|
||||||
minimumBalance = gasLimit.multipliedBy(gasPrice)
|
minimumBalance = gasLimit.multipliedBy(gasPrice)
|
||||||
|
@ -94,10 +94,11 @@ function privateKeyToAddress(privateKey) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function nonceError(e) {
|
function nonceError(e) {
|
||||||
|
const message = e.message.toLowerCase()
|
||||||
return (
|
return (
|
||||||
e.message.includes('Transaction nonce is too low') ||
|
message.includes('transaction nonce is too low') ||
|
||||||
e.message.includes('nonce too low') ||
|
message.includes('nonce too low') ||
|
||||||
e.message.includes('transaction with same nonce in the queue')
|
message.includes('transaction with same nonce in the queue')
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user