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() 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) resendJobs.push(job)
} else { } else {
// if initial transaction sending has failed not due to the same hash error // 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}'`) throw new Error(`Unrecognized chainId '${chainId}'`)
} }
const fetchFn = gasPriceSupplierUrl === 'gas-price-oracle' ? null : () => fetch(gasPriceSupplierUrl) let fetchFn = null
if (fetchOnce) { if (gasPriceSupplierUrl !== 'gas-price-oracle') {
await fetchGasPrice(speedType, factor, bridgeContract, fetchFn) fetchFn = () => fetch(gasPriceSupplierUrl, { timeout: 2000 })
return getPrice()
} }
fetchGasPriceInterval = setIntervalAndRun( if (fetchOnce) {
() => fetchGasPrice(speedType, factor, bridgeContract, fetchFn), await fetchGasPrice(speedType, factor, bridgeContract, fetchFn)
updateInterval } else {
) fetchGasPriceInterval = await setIntervalAndRun(
return null () => fetchGasPrice(speedType, factor, bridgeContract, fetchFn),
updateInterval
)
}
return getPrice()
} }
function getPrice() { function getPrice() {

@ -64,9 +64,9 @@ function addExtraGas(gas, extraPercentage, maxGasLimit = Infinity) {
return BigNumber.min(maxGasLimit, gasWithExtra) return BigNumber.min(maxGasLimit, gasWithExtra)
} }
function setIntervalAndRun(f, interval) { async function setIntervalAndRun(f, interval) {
const handler = setInterval(f, interval) const handler = setInterval(f, interval)
f() await f()
return handler return handler
} }