From 89367a8b437b5ece5be7d62a80d130e51e3ac87e Mon Sep 17 00:00:00 2001 From: Theo Date: Fri, 27 Oct 2023 23:04:10 -0700 Subject: [PATCH] Estimate gas to check possibly revert of invalid transaction that relayer don't spend gas accidentally --- src/worker.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/worker.js b/src/worker.js index 8ba2a63..4cbdd2e 100644 --- a/src/worker.js +++ b/src/worker.js @@ -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()