Force update of gas price when getting underprice tx error (#554)
This commit is contained in:
parent
ab51370d5a
commit
59e0bf7565
@ -195,7 +195,11 @@ async function main({ msg, ackMsg, nackMsg, channel, scheduleForRetry, scheduleT
|
||||
)
|
||||
|
||||
const message = e.message.toLowerCase()
|
||||
if (isResend || message.includes('transaction with the same hash was already imported')) {
|
||||
if (message.includes('replacement transaction underpriced')) {
|
||||
logger.info('Replacement transaction underpriced, forcing gas price update')
|
||||
GasPrice.start(config.id)
|
||||
failedTx.push(job)
|
||||
} else if (isResend || message.includes('transaction with the same hash was already imported')) {
|
||||
resendJobs.push(job)
|
||||
} else {
|
||||
// if initial transaction sending has failed not due to the same hash error
|
||||
|
@ -73,17 +73,20 @@ async function start(chainId, fetchOnce) {
|
||||
throw new Error(`Unrecognized chainId '${chainId}'`)
|
||||
}
|
||||
|
||||
const fetchFn = gasPriceSupplierUrl === 'gas-price-oracle' ? null : () => fetch(gasPriceSupplierUrl)
|
||||
if (fetchOnce) {
|
||||
await fetchGasPrice(speedType, factor, bridgeContract, fetchFn)
|
||||
return getPrice()
|
||||
let fetchFn = null
|
||||
if (gasPriceSupplierUrl !== 'gas-price-oracle') {
|
||||
fetchFn = () => fetch(gasPriceSupplierUrl, { timeout: 2000 })
|
||||
}
|
||||
|
||||
fetchGasPriceInterval = setIntervalAndRun(
|
||||
() => fetchGasPrice(speedType, factor, bridgeContract, fetchFn),
|
||||
updateInterval
|
||||
)
|
||||
return null
|
||||
if (fetchOnce) {
|
||||
await fetchGasPrice(speedType, factor, bridgeContract, fetchFn)
|
||||
} else {
|
||||
fetchGasPriceInterval = await setIntervalAndRun(
|
||||
() => fetchGasPrice(speedType, factor, bridgeContract, fetchFn),
|
||||
updateInterval
|
||||
)
|
||||
}
|
||||
return getPrice()
|
||||
}
|
||||
|
||||
function getPrice() {
|
||||
|
@ -64,9 +64,9 @@ function addExtraGas(gas, extraPercentage, maxGasLimit = Infinity) {
|
||||
return BigNumber.min(maxGasLimit, gasWithExtra)
|
||||
}
|
||||
|
||||
function setIntervalAndRun(f, interval) {
|
||||
async function setIntervalAndRun(f, interval) {
|
||||
const handler = setInterval(f, interval)
|
||||
f()
|
||||
await f()
|
||||
return handler
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user