Estimate gas to check possibly revert of invalid transaction that relayer don't spend gas accidentally

This commit is contained in:
Theo 2023-10-27 23:04:10 -07:00
parent 8ebcfe6b55
commit 89367a8b43

View File

@ -30,6 +30,7 @@ const {
miningServiceFee,
tornadoServiceFee,
tornadoGoerliProxy,
rewardAccount,
} = require('./config')
const resolver = require('./modules/resolver')
const { TxManager } = require('@tornado/tx-manager')
@ -265,10 +266,20 @@ async function processJob(job) {
}
}
async function checkRevert(tx) {
try {
await web3.eth.estimateGas(Object.assign({ from: rewardAccount }, tx))
} catch (e) {
throw new Error('Estimation error: transaction will possibly be reverted')
}
}
async function submitTx(job, retry = 0) {
await checkRecipient(job)
await checkFee(job)
currentTx = await txManager.createTx(await getTxObject(job))
const tx = await getTxObject(job)
await checkRevert(tx)
currentTx = await txManager.createTx(tx)
if (job.data.type !== jobType.TORNADO_WITHDRAW) {
await fetchTree()