From d543dbb3396803e2d7426633c48aa4d55b4ed057 Mon Sep 17 00:00:00 2001 From: Kirill Fedoseev Date: Thu, 7 Oct 2021 20:44:14 +0300 Subject: [PATCH] Use more accurate gas estimates for very high message gas limits (#611) --- oracle/src/events/processAMBAffirmationRequests/estimateGas.js | 2 +- oracle/src/events/processAMBInformationRequests/estimateGas.js | 3 ++- oracle/src/utils/constants.js | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/oracle/src/events/processAMBAffirmationRequests/estimateGas.js b/oracle/src/events/processAMBAffirmationRequests/estimateGas.js index 40332d4f..2521c54e 100644 --- a/oracle/src/events/processAMBAffirmationRequests/estimateGas.js +++ b/oracle/src/events/processAMBAffirmationRequests/estimateGas.js @@ -15,7 +15,7 @@ async function estimateGas({ web3, homeBridge, validatorContract, message, addre const gasEstimate = await homeBridge.methods.executeAffirmation(message).estimateGas({ from: address }) - const msgGasLimit = parseAMBHeader(message).gasLimit + const msgGasLimit = Math.ceil((parseAMBHeader(message).gasLimit * 64) / 63) // message length in bytes const len = strip0x(message).length / 2 - MIN_AMB_HEADER_LENGTH diff --git a/oracle/src/events/processAMBInformationRequests/estimateGas.js b/oracle/src/events/processAMBInformationRequests/estimateGas.js index b08668ed..055c0759 100644 --- a/oracle/src/events/processAMBInformationRequests/estimateGas.js +++ b/oracle/src/events/processAMBInformationRequests/estimateGas.js @@ -24,7 +24,8 @@ async function estimateGas({ // message length in bytes const len = strip0x(result).length / 2 - const callbackGasLimit = parseInt(await homeBridge.methods.maxGasPerTx().call(), 10) + let callbackGasLimit = parseInt(await homeBridge.methods.maxGasPerTx().call(), 10) + callbackGasLimit = Math.ceil((callbackGasLimit * 64) / 63) return gasEstimate + callbackGasLimit + estimateExtraGas(len) } catch (e) { diff --git a/oracle/src/utils/constants.js b/oracle/src/utils/constants.js index 10a6470b..bed0d136 100644 --- a/oracle/src/utils/constants.js +++ b/oracle/src/utils/constants.js @@ -1,6 +1,6 @@ module.exports = { EXTRA_GAS_PERCENTAGE: 4, - EXTRA_GAS_ABSOLUTE: 200000, + EXTRA_GAS_ABSOLUTE: 250000, AMB_AFFIRMATION_REQUEST_EXTRA_GAS_ESTIMATOR: len => Math.floor(0.0035 * len ** 2 + 40 * len), MIN_AMB_HEADER_LENGTH: 32 + 20 + 20 + 4 + 2 + 1 + 2, MAX_GAS_LIMIT: 10000000,