Fix remote shutdown sender behaviour (#550)
This commit is contained in:
parent
f65e8f9244
commit
9dfb0510c4
@ -13,6 +13,7 @@ const {
|
||||
privateKeyToAddress,
|
||||
syncForEach,
|
||||
waitForFunds,
|
||||
waitForUnsuspend,
|
||||
watchdog,
|
||||
nonceError
|
||||
} = require('./utils/utils')
|
||||
@ -45,6 +46,15 @@ async function initialize() {
|
||||
GasPrice.start(config.id)
|
||||
|
||||
chainId = await getChainId(web3Instance)
|
||||
|
||||
connectQueue()
|
||||
} catch (e) {
|
||||
logger.error(e.message)
|
||||
process.exit(EXIT_CODES.GENERAL_ERROR)
|
||||
}
|
||||
}
|
||||
|
||||
function connectQueue() {
|
||||
connectSenderToQueue({
|
||||
queueName: config.queue,
|
||||
oldQueueName: config.oldQueue,
|
||||
@ -60,15 +70,16 @@ async function initialize() {
|
||||
return main(options)
|
||||
}
|
||||
})
|
||||
} catch (e) {
|
||||
logger.error(e.message)
|
||||
process.exit(EXIT_CODES.GENERAL_ERROR)
|
||||
}
|
||||
}
|
||||
|
||||
function resume(newBalance) {
|
||||
logger.info(`Validator balance changed. New balance is ${newBalance}. Resume messages processing.`)
|
||||
initialize()
|
||||
connectQueue()
|
||||
}
|
||||
|
||||
function unsuspend() {
|
||||
logger.info(`Oracle sender was unsuspended.`)
|
||||
connectQueue()
|
||||
}
|
||||
|
||||
async function readNonce(forceUpdate) {
|
||||
@ -103,11 +114,10 @@ async function main({ msg, ackMsg, nackMsg, channel, scheduleForRetry, scheduleT
|
||||
return
|
||||
}
|
||||
|
||||
const wasShutdown = await getShutdownFlag(logger, config.shutdownKey, false)
|
||||
if (await getShutdownFlag(logger, config.shutdownKey, true)) {
|
||||
if (!wasShutdown) {
|
||||
logger.info('Oracle sender was suspended via the remote shutdown process')
|
||||
}
|
||||
channel.close()
|
||||
waitForUnsuspend(() => getShutdownFlag(logger, config.shutdownKey, true), unsuspend)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@ async function fetchShutdownFlag() {
|
||||
}
|
||||
|
||||
if (config.shutdownContractAddress) {
|
||||
const shutdownSelector = web3Side.eth.abi.encodeEventSignature(config.shutdownMethod)
|
||||
const shutdownSelector = web3Side.eth.abi.encodeFunctionSignature(config.shutdownMethod)
|
||||
logger.debug(
|
||||
{ contract: config.shutdownContractAddress, method: config.shutdownMethod, data: shutdownSelector },
|
||||
'Fetching shutdown status from contract'
|
||||
|
@ -29,9 +29,10 @@ function checkHTTPS(ORACLE_ALLOW_HTTP_FOR_RPC, logger) {
|
||||
}
|
||||
}
|
||||
|
||||
const promiseRetryForever = f => promiseRetry(f, { forever: true, factor: 1 })
|
||||
|
||||
async function waitForFunds(web3, address, minimumBalance, cb, logger) {
|
||||
promiseRetry(
|
||||
async retry => {
|
||||
promiseRetryForever(async retry => {
|
||||
logger.debug('Getting balance of validator account')
|
||||
const newBalance = web3.utils.toBN(await web3.eth.getBalance(address))
|
||||
if (newBalance.gte(web3.utils.toBN(minimumBalance.toString(10)))) {
|
||||
@ -41,12 +42,17 @@ async function waitForFunds(web3, address, minimumBalance, cb, logger) {
|
||||
logger.debug({ balance: newBalance, minimumBalance }, 'Balance of validator is still less than the minimum')
|
||||
retry()
|
||||
}
|
||||
},
|
||||
{
|
||||
forever: true,
|
||||
factor: 1
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
async function waitForUnsuspend(getSuspendFlag, cb) {
|
||||
promiseRetryForever(async retry => {
|
||||
if (await getSuspendFlag()) {
|
||||
retry()
|
||||
} else {
|
||||
cb()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function addExtraGas(gas, extraPercentage, maxGasLimit = Infinity) {
|
||||
@ -135,6 +141,7 @@ module.exports = {
|
||||
syncForEach,
|
||||
checkHTTPS,
|
||||
waitForFunds,
|
||||
waitForUnsuspend,
|
||||
addExtraGas,
|
||||
setIntervalAndRun,
|
||||
watchdog,
|
||||
|
@ -164,6 +164,8 @@ async function main({ sendToQueue, sendToWorker }) {
|
||||
logger.info('Oracle watcher was suspended via the remote shutdown process')
|
||||
}
|
||||
return
|
||||
} else if (wasShutdown) {
|
||||
logger.info(`Oracle watcher was unsuspended.`)
|
||||
}
|
||||
|
||||
await checkConditions()
|
||||
|
Loading…
Reference in New Issue
Block a user