Commit 85f68bd3 authored by Matthew Slipper's avatar Matthew Slipper

batch-submitter: ENG-1688 fix bug causing Kovan to fall behind

parent d59341a2
---
'@eth-optimism/batch-submitter': patch
---
Immediately reject on nonce errors to stop falling behind
...@@ -28,6 +28,21 @@ const getGasPriceInGwei = async (signer: Signer): Promise<number> => { ...@@ -28,6 +28,21 @@ const getGasPriceInGwei = async (signer: Signer): Promise<number> => {
) )
} }
export const ynatmRejectOn = (e) => {
// taken almost verbatim from the readme,
// see https://github.com/ethereum-optimism/ynatm.
// immediately rejects on reverts and nonce errors
const errMsg = e.toString().toLowerCase()
const conditions = ['revert', 'nonce']
for (const cond of conditions) {
if (errMsg.includes(cond)) {
return true
}
}
return false
}
export const submitTransactionWithYNATM = async ( export const submitTransactionWithYNATM = async (
tx: PopulatedTransaction, tx: PopulatedTransaction,
signer: Signer, signer: Signer,
...@@ -55,6 +70,7 @@ export const submitTransactionWithYNATM = async ( ...@@ -55,6 +70,7 @@ export const submitTransactionWithYNATM = async (
maxGasPrice: ynatm.toGwei(config.maxGasPriceInGwei), maxGasPrice: ynatm.toGwei(config.maxGasPriceInGwei),
gasPriceScalingFunction: ynatm.LINEAR(config.gasRetryIncrement), gasPriceScalingFunction: ynatm.LINEAR(config.gasRetryIncrement),
delay: config.resubmissionTimeout, delay: config.resubmissionTimeout,
rejectImmediatelyOnCondition: ynatmRejectOn,
}) })
return receipt return receipt
} }
......
...@@ -124,4 +124,41 @@ describe('submitTransactionWithYNATM', async () => { ...@@ -124,4 +124,41 @@ describe('submitTransactionWithYNATM', async () => {
} }
await submitTransactionWithYNATM(tx, signer, config, 0, nullHooks) await submitTransactionWithYNATM(tx, signer, config, 0, nullHooks)
}) })
it('should immediately reject if a nonce error is encountered', async () => {
const tx = {
gasPrice: BigNumber.from(1),
data: 'hello world!',
} as ethers.PopulatedTransaction
let txCount = 0
const waitForTransaction = async (): Promise<TransactionReceipt> => {
return {} as TransactionReceipt
}
const sendTransaction = async () => {
txCount++
throw new Error('Transaction nonce is too low.')
}
const signer = {
getGasPrice: async () => BigNumber.from(1),
sendTransaction: sendTransaction as any,
provider: {
waitForTransaction: waitForTransaction as any,
},
} as Signer
const config: ResubmissionConfig = {
resubmissionTimeout: 100,
minGasPriceInGwei: 0,
maxGasPriceInGwei: 1000,
gasRetryIncrement: 1,
}
try {
await submitTransactionWithYNATM(tx, signer, config, 0, nullHooks)
} catch (e) {
expect(txCount).to.equal(1)
return
}
expect.fail('Expected an error.')
})
}) })
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment