Force update of gas price when getting underprice tx error (#554)

This commit is contained in:
Kirill Fedoseev 2021-04-18 21:30:40 +03:00 committed by GitHub
parent ab51370d5a
commit 59e0bf7565
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 12 deletions

@ -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
}