@@ -14,7 +14,10 @@ const {
1414 waitForFunds,
1515 waitForUnsuspend,
1616 watchdog,
17- nonceError
17+ isGasPriceError,
18+ isSameTransactionError,
19+ isInsufficientBalanceError,
20+ isNonceError
1821} = require ( './utils/utils' )
1922const { EXIT_CODES , EXTRA_GAS_PERCENTAGE , MAX_GAS_LIMIT } = require ( './utils/constants' )
2023
@@ -189,12 +192,11 @@ async function main({ msg, ackMsg, nackMsg, channel, scheduleForRetry, scheduleT
189192 e . message
190193 )
191194
192- const message = e . message . toLowerCase ( )
193- if ( message . includes ( 'replacement transaction underpriced' ) ) {
195+ if ( isGasPriceError ( e ) ) {
194196 logger . info ( 'Replacement transaction underpriced, forcing gas price update' )
195197 GasPrice . start ( config . id )
196198 failedTx . push ( job )
197- } else if ( isResend || message . includes ( 'transaction with the same hash was already imported' ) ) {
199+ } else if ( isResend || isSameTransactionError ( e ) ) {
198200 resendJobs . push ( job )
199201 } else {
200202 // if initial transaction sending has failed not due to the same hash error
@@ -203,14 +205,14 @@ async function main({ msg, ackMsg, nackMsg, channel, scheduleForRetry, scheduleT
203205 failedTx . push ( job )
204206 }
205207
206- if ( message . includes ( 'insufficient funds' ) ) {
208+ if ( isInsufficientBalanceError ( e ) ) {
207209 insufficientFunds = true
208210 const currentBalance = await web3 . eth . getBalance ( config . validatorAddress )
209211 minimumBalance = gasLimit . multipliedBy ( gasPrice )
210212 logger . error (
211213 `Insufficient funds: ${ currentBalance } . Stop processing messages until the balance is at least ${ minimumBalance } .`
212214 )
213- } else if ( nonceError ( e ) ) {
215+ } else if ( isNonceError ( e ) ) {
214216 nonce = await readNonce ( true )
215217 }
216218 }
0 commit comments