mirror of
https://github.com/tornadocash/tornado-relayer.git
synced 2024-10-01 08:25:37 -04:00
getJob status and small fixes
This commit is contained in:
parent
d8a02586c6
commit
a59fdcb2d5
@ -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./,
|
/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 = [
|
const sameTxErrors = ['Returned error: Transaction with the same hash was already imported.']
|
||||||
'Returned error: Transaction with the same hash was already imported.',
|
|
||||||
]
|
|
||||||
|
|
||||||
const defaultConfig = {
|
const defaultConfig = {
|
||||||
MAX_RETRIES: 10,
|
MAX_RETRIES: 10,
|
||||||
@ -77,9 +75,7 @@ class Transaction {
|
|||||||
throw new Error('The transaction was already executed')
|
throw new Error('The transaction was already executed')
|
||||||
}
|
}
|
||||||
this.executed = true
|
this.executed = true
|
||||||
this._execute()
|
this._execute().then(this._promise.resolve).catch(this._promise.reject)
|
||||||
.then(this._promise.resolve)
|
|
||||||
.catch(this._promise.reject)
|
|
||||||
return this._emitter
|
return this._emitter
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,7 +177,6 @@ class Transaction {
|
|||||||
|
|
||||||
this._emitter.emit('transactionHash', signedTx.transactionHash)
|
this._emitter.emit('transactionHash', signedTx.transactionHash)
|
||||||
console.log(`Broadcasted transaction ${signedTx.transactionHash}`)
|
console.log(`Broadcasted transaction ${signedTx.transactionHash}`)
|
||||||
console.log(this.tx)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -219,7 +214,7 @@ class Transaction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Tx is still pending
|
// 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
|
// todo optionally run estimateGas on each iteration and cancel the transaction if it fails
|
||||||
|
|
||||||
// We were waiting too long, increase gas price and resubmit
|
// 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
|
// There is a mined tx with current nonce, but it's not one of ours
|
||||||
// Probably other tx submitted by other process/client
|
// Probably other tx submitted by other process/client
|
||||||
if (!receipt) {
|
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
|
// Give node a few more attempts to respond with our receipt
|
||||||
let retries = 5
|
let retries = 5
|
||||||
while (!receipt && retries--) {
|
while (!receipt && retries--) {
|
||||||
@ -251,7 +246,9 @@ class Transaction {
|
|||||||
// Receipt was not found after a few retries
|
// Receipt was not found after a few retries
|
||||||
// Resubmit our tx
|
// Resubmit our tx
|
||||||
if (!receipt) {
|
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++
|
this.tx.nonce++
|
||||||
// todo drop gas price to original value?
|
// todo drop gas price to original value?
|
||||||
await this._send()
|
await this._send()
|
||||||
@ -327,7 +324,7 @@ class Transaction {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_hasError(message, errors) {
|
_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() {
|
_increaseGasPrice() {
|
||||||
|
@ -28,7 +28,7 @@ async function getJob(uuid) {
|
|||||||
|
|
||||||
async function getJobStatus(uuid) {
|
async function getJobStatus(uuid) {
|
||||||
const job = await getJob(uuid)
|
const job = await getJob(uuid)
|
||||||
// ...
|
return job.data
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
@ -26,7 +26,7 @@ app.use((req, res, next) => {
|
|||||||
|
|
||||||
app.get('/', status.index)
|
app.get('/', status.index)
|
||||||
app.get('/v1/status', status.status)
|
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.post('/v1/tornadoWithdraw', controller.tornadoWithdraw)
|
||||||
app.get('/status', status.status)
|
app.get('/status', status.status)
|
||||||
app.post('/relay', controller.tornadoWithdraw)
|
app.post('/relay', controller.tornadoWithdraw)
|
||||||
|
@ -33,7 +33,7 @@ function index(req, res) {
|
|||||||
|
|
||||||
async function getJob(req, res) {
|
async function getJob(req, res) {
|
||||||
const status = await queue.getJobStatus(req.params.id)
|
const status = await queue.getJobStatus(req.params.id)
|
||||||
return res.send(status)
|
return res.json(status)
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
@ -63,7 +63,7 @@ async function process(job) {
|
|||||||
|
|
||||||
async function processTornadoWithdraw(job) {
|
async function processTornadoWithdraw(job) {
|
||||||
currentJob = 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 { proof, args, contract } = job.data.data
|
||||||
const fee = toBN(args[4])
|
const fee = toBN(args[4])
|
||||||
const refund = toBN(args[5])
|
const refund = toBN(args[5])
|
||||||
@ -93,7 +93,7 @@ async function processTornadoWithdraw(job) {
|
|||||||
|
|
||||||
async function processMiningReward(job) {
|
async function processMiningReward(job) {
|
||||||
currentJob = 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 { proof, args } = job.data.data
|
||||||
|
|
||||||
const contract = new web3.eth.Contract(miningABI, minerAddress)
|
const contract = new web3.eth.Contract(miningABI, minerAddress)
|
||||||
@ -119,7 +119,7 @@ async function processMiningReward(job) {
|
|||||||
|
|
||||||
async function processMiningWithdraw(job) {
|
async function processMiningWithdraw(job) {
|
||||||
currentJob = 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 { proof, args } = job.data.data
|
||||||
|
|
||||||
const contract = new web3.eth.Contract(miningABI, minerAddress)
|
const contract = new web3.eth.Contract(miningABI, minerAddress)
|
||||||
|
Loading…
Reference in New Issue
Block a user