Compare commits
1 Commits
master
...
amb-altern
Author | SHA1 | Date | |
---|---|---|---|
|
d229840830 |
@ -3,14 +3,18 @@ const { AlreadyProcessedError, AlreadySignedError, InvalidValidatorError } = req
|
|||||||
const logger = require('../../services/logger').child({
|
const logger = require('../../services/logger').child({
|
||||||
module: 'processAffirmationRequests:estimateGas'
|
module: 'processAffirmationRequests:estimateGas'
|
||||||
})
|
})
|
||||||
|
const { parseAMBHeader } = require('../../utils/message')
|
||||||
|
|
||||||
async function estimateGas({ web3, homeBridge, validatorContract, message, address }) {
|
async function estimateGas({ web3, homeBridge, validatorContract, message, address }) {
|
||||||
try {
|
try {
|
||||||
const gasEstimate = await homeBridge.methods.executeAffirmation(message).estimateGas({
|
const gasEstimate = await homeBridge.methods.executeAffirmation(message).estimateGas({
|
||||||
from: address
|
from: address
|
||||||
})
|
})
|
||||||
|
const msgGasLimit = parseAMBHeader(message).gasLimit
|
||||||
|
|
||||||
return gasEstimate
|
logger.info({ gasEstimate, msgGasLimit }, 'Gas consumption parameters')
|
||||||
|
|
||||||
|
return gasEstimate + msgGasLimit + ( message.length * 32 )
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof HttpListProviderError) {
|
if (e instanceof HttpListProviderError) {
|
||||||
throw e
|
throw e
|
||||||
|
@ -4,6 +4,7 @@ const { AlreadyProcessedError, IncompatibleContractError, InvalidValidatorError
|
|||||||
const logger = require('../../services/logger').child({
|
const logger = require('../../services/logger').child({
|
||||||
module: 'processCollectedSignatures:estimateGas'
|
module: 'processCollectedSignatures:estimateGas'
|
||||||
})
|
})
|
||||||
|
const { parseAMBHeader } = require('../../utils/message')
|
||||||
|
|
||||||
const web3 = new Web3()
|
const web3 = new Web3()
|
||||||
const { toBN } = Web3.utils
|
const { toBN } = Web3.utils
|
||||||
@ -24,7 +25,11 @@ async function estimateGas({
|
|||||||
const gasEstimate = await foreignBridge.methods.executeSignatures(message, signatures).estimateGas({
|
const gasEstimate = await foreignBridge.methods.executeSignatures(message, signatures).estimateGas({
|
||||||
from: address
|
from: address
|
||||||
})
|
})
|
||||||
return gasEstimate
|
const msgGasLimit = parseAMBHeader(message).gasLimit
|
||||||
|
|
||||||
|
logger.info({ gasEstimate, msgGasLimit }, 'Gas consumption parameters')
|
||||||
|
|
||||||
|
return gasEstimate + msgGasLimit + ( message.length * 32 )
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof HttpListProviderError) {
|
if (e instanceof HttpListProviderError) {
|
||||||
throw e
|
throw e
|
||||||
|
@ -16,7 +16,7 @@ const {
|
|||||||
watchdog,
|
watchdog,
|
||||||
nonceError
|
nonceError
|
||||||
} = require('./utils/utils')
|
} = require('./utils/utils')
|
||||||
const { EXIT_CODES, EXTRA_GAS_PERCENTAGE } = require('./utils/constants')
|
const { EXIT_CODES, EXTRA_GAS_ABSOLUTE } = require('./utils/constants')
|
||||||
|
|
||||||
const { ORACLE_VALIDATOR_ADDRESS_PRIVATE_KEY } = process.env
|
const { ORACLE_VALIDATOR_ADDRESS_PRIVATE_KEY } = process.env
|
||||||
|
|
||||||
@ -106,7 +106,7 @@ async function main({ msg, ackMsg, nackMsg, channel, scheduleForRetry }) {
|
|||||||
|
|
||||||
logger.debug(`Sending ${txArray.length} transactions`)
|
logger.debug(`Sending ${txArray.length} transactions`)
|
||||||
await syncForEach(txArray, async job => {
|
await syncForEach(txArray, async job => {
|
||||||
const gasLimit = addExtraGas(job.gasEstimate, EXTRA_GAS_PERCENTAGE)
|
const gasLimit = addExtraGas(job.gasEstimate, EXTRA_GAS_ABSOLUTE, logger)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
logger.info(`Sending transaction with nonce ${nonce}`)
|
logger.info(`Sending transaction with nonce ${nonce}`)
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
EXTRA_GAS_PERCENTAGE: 4,
|
EXTRA_GAS_PERCENTAGE: 2,
|
||||||
|
EXTRA_GAS_ABSOLUTE: 500000,
|
||||||
MAX_CONCURRENT_EVENTS: 50,
|
MAX_CONCURRENT_EVENTS: 50,
|
||||||
RETRY_CONFIG: {
|
RETRY_CONFIG: {
|
||||||
retries: 20,
|
retries: 20,
|
||||||
|
@ -73,9 +73,37 @@ function packSignatures(array) {
|
|||||||
return `0x${msgLength}${v}${r}${s}`
|
return `0x${msgLength}${v}${r}${s}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parseAMBHeader(message) {
|
||||||
|
message = strip0x(message)
|
||||||
|
|
||||||
|
const messageIdStart = 0
|
||||||
|
const messageIdLength = 32 * 2
|
||||||
|
const messageId = `0x${message.slice(messageIdStart, messageIdStart + messageIdLength)}`
|
||||||
|
|
||||||
|
const senderStart = messageIdStart + messageIdLength
|
||||||
|
const senderLength = 20 * 2
|
||||||
|
const sender = `0x${message.slice(senderStart, senderStart + senderLength)}`
|
||||||
|
|
||||||
|
const executorStart = senderStart + senderLength
|
||||||
|
const executorLength = 20 * 2
|
||||||
|
const executor = `0x${message.slice(executorStart, executorStart + executorLength)}`
|
||||||
|
|
||||||
|
const gasLimitStart = executorStart + executorLength
|
||||||
|
const gasLimitLength = 4 * 2
|
||||||
|
const gasLimit = parseInt(message.slice(gasLimitStart, gasLimitStart + gasLimitLength), 16)
|
||||||
|
|
||||||
|
return {
|
||||||
|
messageId,
|
||||||
|
sender,
|
||||||
|
executor,
|
||||||
|
gasLimit
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
createMessage,
|
createMessage,
|
||||||
parseMessage,
|
parseMessage,
|
||||||
signatureToVRS,
|
signatureToVRS,
|
||||||
packSignatures
|
packSignatures,
|
||||||
|
parseAMBHeader
|
||||||
}
|
}
|
||||||
|
@ -48,11 +48,11 @@ async function waitForFunds(web3, address, minimumBalance, cb, logger) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function addExtraGas(gas, extraPercentage) {
|
function addExtraGas(gas, extra, logger) {
|
||||||
gas = BigNumber(gas)
|
gas = BigNumber(gas)
|
||||||
extraPercentage = BigNumber(1 + extraPercentage)
|
const gasWithExtra = gas.plus(extra).toFixed(0)
|
||||||
|
|
||||||
const gasWithExtra = gas.multipliedBy(extraPercentage).toFixed(0)
|
logger.info({ gasEstimated: gasWithExtra }, 'Gas Limit used')
|
||||||
|
|
||||||
return BigNumber(gasWithExtra)
|
return BigNumber(gasWithExtra)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user