getJob status and small fixes

This commit is contained in:
Alexey 2020-10-01 16:08:33 +03:00
parent d8a02586c6
commit a59fdcb2d5
5 changed files with 14 additions and 17 deletions

@ -16,9 +16,7 @@ const gasPriceErrors = [
/Returned error: Transaction gas price \d+wei is too low. There is another transaction with same nonce in the queue with gas price: \d+wei. Try increasing the gas price or incrementing the nonce./,
]
const sameTxErrors = [
'Returned error: Transaction with the same hash was already imported.',
]
const sameTxErrors = ['Returned error: Transaction with the same hash was already imported.']
const defaultConfig = {
MAX_RETRIES: 10,
@ -77,9 +75,7 @@ class Transaction {
throw new Error('The transaction was already executed')
}
this.executed = true
this._execute()
.then(this._promise.resolve)
.catch(this._promise.reject)
this._execute().then(this._promise.resolve).catch(this._promise.reject)
return this._emitter
}
@ -181,7 +177,6 @@ class Transaction {
this._emitter.emit('transactionHash', signedTx.transactionHash)
console.log(`Broadcasted transaction ${signedTx.transactionHash}`)
console.log(this.tx)
}
/**
@ -219,7 +214,7 @@ class Transaction {
}
// Tx is still pending
if (await this._getLastNonce() <= this.tx.nonce) {
if ((await this._getLastNonce()) <= this.tx.nonce) {
// todo optionally run estimateGas on each iteration and cancel the transaction if it fails
// We were waiting too long, increase gas price and resubmit
@ -240,7 +235,7 @@ class Transaction {
// There is a mined tx with current nonce, but it's not one of ours
// Probably other tx submitted by other process/client
if (!receipt) {
console.log('Can\'t find our transaction receipt, retrying a few times')
console.log("Can't find our transaction receipt, retrying a few times")
// Give node a few more attempts to respond with our receipt
let retries = 5
while (!receipt && retries--) {
@ -251,7 +246,9 @@ class Transaction {
// Receipt was not found after a few retries
// Resubmit our tx
if (!receipt) {
console.log('There is a mined tx with our nonce but unknown tx hash, resubmitting with tx with increased nonce')
console.log(
'There is a mined tx with our nonce but unknown tx hash, resubmitting with tx with increased nonce',
)
this.tx.nonce++
// todo drop gas price to original value?
await this._send()
@ -327,7 +324,7 @@ class Transaction {
* @private
*/
_hasError(message, errors) {
return errors.find(e => typeof e === 'string' ? e === message : message.match(e)) !== undefined
return errors.find((e) => (typeof e === 'string' ? e === message : message.match(e))) !== undefined
}
_increaseGasPrice() {

@ -28,7 +28,7 @@ async function getJob(uuid) {
async function getJobStatus(uuid) {
const job = await getJob(uuid)
// ...
return job.data
}
module.exports = {

@ -26,7 +26,7 @@ app.use((req, res, next) => {
app.get('/', status.index)
app.get('/v1/status', status.status)
app.post('/v1/jobs/:id', status.getJob)
app.get('/v1/jobs/:id', status.getJob)
app.post('/v1/tornadoWithdraw', controller.tornadoWithdraw)
app.get('/status', status.status)
app.post('/relay', controller.tornadoWithdraw)

@ -33,7 +33,7 @@ function index(req, res) {
async function getJob(req, res) {
const status = await queue.getJobStatus(req.params.id)
return res.send(status)
return res.json(status)
}
module.exports = {

@ -63,7 +63,7 @@ async function process(job) {
async function processTornadoWithdraw(job) {
currentJob = job
console.log(Date.now(), ' withdraw started', job.id)
console.log(`Start processing a new Tornado Withdraw job #${job.id}`)
const { proof, args, contract } = job.data.data
const fee = toBN(args[4])
const refund = toBN(args[5])
@ -93,7 +93,7 @@ async function processTornadoWithdraw(job) {
async function processMiningReward(job) {
currentJob = job
console.log(Date.now(), ' reward started', job.id)
console.log(`Start processing a new Mining Reward job #${job.id}`)
const { proof, args } = job.data.data
const contract = new web3.eth.Contract(miningABI, minerAddress)
@ -119,7 +119,7 @@ async function processMiningReward(job) {
async function processMiningWithdraw(job) {
currentJob = job
console.log(Date.now(), ' mining withdraw started', job.id)
console.log(`Start processing a new Mining Withdraw job #${job.id}`)
const { proof, args } = job.data.data
const contract = new web3.eth.Contract(miningABI, minerAddress)