Add env variables for selective validator balance checks (#507)
This commit is contained in:
parent
5fc52f42d7
commit
409044b8a5
@ -82,3 +82,5 @@ MONITOR_CACHE_EVENTS | If set to true, monitor will cache obtained events for ot
|
|||||||
MONITOR_HOME_TO_FOREIGN_ALLOWANCE_LIST | File with a list of addresses, separated by newlines. If set, determines the privileged set of accounts whose requests should be automatically processed by the CollectedSignatures watcher. | string
|
MONITOR_HOME_TO_FOREIGN_ALLOWANCE_LIST | File with a list of addresses, separated by newlines. If set, determines the privileged set of accounts whose requests should be automatically processed by the CollectedSignatures watcher. | string
|
||||||
MONITOR_HOME_TO_FOREIGN_BLOCK_LIST | File with a list of addresses, separated by newlines. If set, determines the set of accounts whose requests should be marked as unclaimed. Has a lower priority than the `MONITOR_HOME_TO_FOREIGN_ALLOWANCE_LIST`. | string
|
MONITOR_HOME_TO_FOREIGN_BLOCK_LIST | File with a list of addresses, separated by newlines. If set, determines the set of accounts whose requests should be marked as unclaimed. Has a lower priority than the `MONITOR_HOME_TO_FOREIGN_ALLOWANCE_LIST`. | string
|
||||||
MONITOR_HOME_TO_FOREIGN_CHECK_SENDER | If set to `true`, instructs the oracle to do an extra check for transaction origin in the block/allowance list. `false` by default. | `true` / `false`
|
MONITOR_HOME_TO_FOREIGN_CHECK_SENDER | If set to `true`, instructs the oracle to do an extra check for transaction origin in the block/allowance list. `false` by default. | `true` / `false`
|
||||||
|
MONITOR_HOME_VALIDATORS_BALANCE_ENABLE | If set, defines the list of home validator addresses for which balance should be checked. | `string`
|
||||||
|
MONITOR_FOREIGN_VALIDATORS_BALANCE_ENABLE | If set, defines the list of foreign validator addresses for which balance should be checked. | `string`
|
||||||
|
@ -25,3 +25,6 @@ MONITOR_CACHE_EVENTS=true
|
|||||||
|
|
||||||
MONITOR_HOME_TO_FOREIGN_ALLOWANCE_LIST=
|
MONITOR_HOME_TO_FOREIGN_ALLOWANCE_LIST=
|
||||||
MONITOR_HOME_TO_FOREIGN_BLOCK_LIST=
|
MONITOR_HOME_TO_FOREIGN_BLOCK_LIST=
|
||||||
|
|
||||||
|
# MONITOR_HOME_VALIDATORS_BALANCE_ENABLE=0x... 0x... 0x...
|
||||||
|
# MONITOR_FOREIGN_VALIDATORS_BALANCE_ENABLE=0x... 0x... 0x...
|
||||||
|
@ -12,10 +12,6 @@ const { web3Home } = require('./utils/web3')
|
|||||||
|
|
||||||
const { COMMON_HOME_BRIDGE_ADDRESS, MONITOR_BRIDGE_NAME } = process.env
|
const { COMMON_HOME_BRIDGE_ADDRESS, MONITOR_BRIDGE_NAME } = process.env
|
||||||
|
|
||||||
const MONITOR_VALIDATOR_HOME_TX_LIMIT = Number(process.env.MONITOR_VALIDATOR_HOME_TX_LIMIT) || 0
|
|
||||||
const MONITOR_VALIDATOR_FOREIGN_TX_LIMIT = Number(process.env.MONITOR_VALIDATOR_FOREIGN_TX_LIMIT) || 0
|
|
||||||
const MONITOR_TX_NUMBER_THRESHOLD = Number(process.env.MONITOR_TX_NUMBER_THRESHOLD) || 100
|
|
||||||
|
|
||||||
const { HOME_ERC_TO_ERC_ABI } = require('../commons')
|
const { HOME_ERC_TO_ERC_ABI } = require('../commons')
|
||||||
|
|
||||||
async function checkWorker() {
|
async function checkWorker() {
|
||||||
@ -45,27 +41,6 @@ async function checkWorker() {
|
|||||||
const vBalances = await validators(bridgeMode)
|
const vBalances = await validators(bridgeMode)
|
||||||
if (!vBalances) throw new Error('vBalances is empty: ' + JSON.stringify(vBalances))
|
if (!vBalances) throw new Error('vBalances is empty: ' + JSON.stringify(vBalances))
|
||||||
|
|
||||||
vBalances.homeOk = true
|
|
||||||
vBalances.foreignOk = true
|
|
||||||
|
|
||||||
if (MONITOR_VALIDATOR_HOME_TX_LIMIT) {
|
|
||||||
for (const hv in vBalances.home.validators) {
|
|
||||||
if (vBalances.home.validators[hv].leftTx < MONITOR_TX_NUMBER_THRESHOLD) {
|
|
||||||
vBalances.homeOk = false
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (MONITOR_VALIDATOR_FOREIGN_TX_LIMIT) {
|
|
||||||
for (const hv in vBalances.foreign.validators) {
|
|
||||||
if (vBalances.foreign.validators[hv].leftTx < MONITOR_TX_NUMBER_THRESHOLD) {
|
|
||||||
vBalances.foreignOk = false
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
vBalances.ok = vBalances.homeOk && vBalances.foreignOk
|
vBalances.ok = vBalances.homeOk && vBalances.foreignOk
|
||||||
vBalances.health = true
|
vBalances.health = true
|
||||||
writeFile(`/responses/${MONITOR_BRIDGE_NAME}/validators.json`, vBalances)
|
writeFile(`/responses/${MONITOR_BRIDGE_NAME}/validators.json`, vBalances)
|
||||||
|
@ -16,10 +16,13 @@ const {
|
|||||||
COMMON_FOREIGN_GAS_PRICE_SUPPLIER_URL,
|
COMMON_FOREIGN_GAS_PRICE_SUPPLIER_URL,
|
||||||
COMMON_FOREIGN_GAS_PRICE_SPEED_TYPE,
|
COMMON_FOREIGN_GAS_PRICE_SPEED_TYPE,
|
||||||
COMMON_FOREIGN_GAS_PRICE_FALLBACK,
|
COMMON_FOREIGN_GAS_PRICE_FALLBACK,
|
||||||
COMMON_FOREIGN_GAS_PRICE_FACTOR
|
COMMON_FOREIGN_GAS_PRICE_FACTOR,
|
||||||
|
MONITOR_FOREIGN_VALIDATORS_BALANCE_ENABLE,
|
||||||
|
MONITOR_HOME_VALIDATORS_BALANCE_ENABLE
|
||||||
} = process.env
|
} = process.env
|
||||||
const MONITOR_VALIDATOR_HOME_TX_LIMIT = Number(process.env.MONITOR_VALIDATOR_HOME_TX_LIMIT) || 0
|
const MONITOR_VALIDATOR_HOME_TX_LIMIT = Number(process.env.MONITOR_VALIDATOR_HOME_TX_LIMIT) || 0
|
||||||
const MONITOR_VALIDATOR_FOREIGN_TX_LIMIT = Number(process.env.MONITOR_VALIDATOR_FOREIGN_TX_LIMIT) || 0
|
const MONITOR_VALIDATOR_FOREIGN_TX_LIMIT = Number(process.env.MONITOR_VALIDATOR_FOREIGN_TX_LIMIT) || 0
|
||||||
|
const MONITOR_TX_NUMBER_THRESHOLD = Number(process.env.MONITOR_TX_NUMBER_THRESHOLD) || 100
|
||||||
|
|
||||||
const homeGasPriceSupplierOpts = {
|
const homeGasPriceSupplierOpts = {
|
||||||
speedType: COMMON_HOME_GAS_PRICE_SPEED_TYPE,
|
speedType: COMMON_HOME_GAS_PRICE_SPEED_TYPE,
|
||||||
@ -33,12 +36,6 @@ const foreignGasPriceSupplierOpts = {
|
|||||||
logger
|
logger
|
||||||
}
|
}
|
||||||
|
|
||||||
const asyncForEach = async (array, callback) => {
|
|
||||||
for (let index = 0; index < array.length; index++) {
|
|
||||||
await callback(array[index], index, array)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function main(bridgeMode) {
|
async function main(bridgeMode) {
|
||||||
const { HOME_ABI, FOREIGN_ABI } = getBridgeABIs(bridgeMode)
|
const { HOME_ABI, FOREIGN_ABI } = getBridgeABIs(bridgeMode)
|
||||||
const homeBridge = new web3Home.eth.Contract(HOME_ABI, COMMON_HOME_BRIDGE_ADDRESS)
|
const homeBridge = new web3Home.eth.Contract(HOME_ABI, COMMON_HOME_BRIDGE_ADDRESS)
|
||||||
@ -109,53 +106,61 @@ async function main(bridgeMode) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let validatorsMatch = true
|
let validatorsMatch = true
|
||||||
logger.debug('calling asyncForEach foreignValidators foreignVBalances')
|
const foreignValidatorsWithBalanceCheck =
|
||||||
await asyncForEach(foreignValidators, async v => {
|
typeof MONITOR_FOREIGN_VALIDATORS_BALANCE_ENABLE === 'string'
|
||||||
const balance = await web3Foreign.eth.getBalance(v)
|
? MONITOR_FOREIGN_VALIDATORS_BALANCE_ENABLE.split(' ')
|
||||||
if (MONITOR_VALIDATOR_FOREIGN_TX_LIMIT) {
|
: foreignValidators
|
||||||
const leftTx = Web3Utils.toBN(balance)
|
logger.debug('getting foreignValidators balances')
|
||||||
.div(foreignTxCost)
|
await Promise.all(
|
||||||
.toString(10)
|
foreignValidators.map(async v => {
|
||||||
foreignVBalances[v] = {
|
foreignVBalances[v] = {}
|
||||||
balance: Web3Utils.fromWei(balance),
|
if (foreignValidatorsWithBalanceCheck.includes(v)) {
|
||||||
leftTx: Number(leftTx),
|
const balance = await web3Foreign.eth.getBalance(v)
|
||||||
gasPrice: Number(foreignGasPriceGwei)
|
foreignVBalances[v].balance = Web3Utils.fromWei(balance)
|
||||||
|
if (MONITOR_VALIDATOR_FOREIGN_TX_LIMIT) {
|
||||||
|
foreignVBalances[v].leftTx = Number(
|
||||||
|
Web3Utils.toBN(balance)
|
||||||
|
.div(foreignTxCost)
|
||||||
|
.toString(10)
|
||||||
|
)
|
||||||
|
foreignVBalances[v].gasPrice = parseFloat(foreignGasPriceGwei)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
foreignVBalances[v] = {
|
|
||||||
balance: Web3Utils.fromWei(balance)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!homeValidators.includes(v)) {
|
if (!homeValidators.includes(v)) {
|
||||||
validatorsMatch = false
|
validatorsMatch = false
|
||||||
foreignVBalances[v].onlyOnForeign = true
|
foreignVBalances[v].onlyOnForeign = true
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
logger.debug('calling asyncForEach homeValidators homeVBalances')
|
|
||||||
await asyncForEach(homeValidators, async v => {
|
|
||||||
const balance = await web3Home.eth.getBalance(v)
|
|
||||||
if (MONITOR_VALIDATOR_HOME_TX_LIMIT) {
|
|
||||||
const leftTx = Web3Utils.toBN(balance)
|
|
||||||
.div(homeTxCost)
|
|
||||||
.toString(10)
|
|
||||||
homeVBalances[v] = {
|
|
||||||
balance: Web3Utils.fromWei(balance),
|
|
||||||
leftTx: Number(leftTx),
|
|
||||||
gasPrice: Number(homeGasPriceGwei)
|
|
||||||
}
|
}
|
||||||
} else {
|
})
|
||||||
homeVBalances[v] = {
|
)
|
||||||
balance: Web3Utils.fromWei(balance)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!foreignValidators.includes(v)) {
|
const homeValidatorsWithBalanceCheck =
|
||||||
validatorsMatch = false
|
typeof MONITOR_HOME_VALIDATORS_BALANCE_ENABLE === 'string'
|
||||||
homeVBalances[v].onlyOnHome = true
|
? MONITOR_HOME_VALIDATORS_BALANCE_ENABLE.split(' ')
|
||||||
}
|
: homeValidators
|
||||||
})
|
logger.debug('calling homeValidators balances')
|
||||||
|
await Promise.all(
|
||||||
|
homeValidators.map(async v => {
|
||||||
|
homeVBalances[v] = {}
|
||||||
|
if (homeValidatorsWithBalanceCheck.includes(v)) {
|
||||||
|
const balance = await web3Home.eth.getBalance(v)
|
||||||
|
homeVBalances[v].balance = Web3Utils.fromWei(balance)
|
||||||
|
if (MONITOR_VALIDATOR_HOME_TX_LIMIT) {
|
||||||
|
homeVBalances[v].leftTx = Number(
|
||||||
|
Web3Utils.toBN(balance)
|
||||||
|
.div(homeTxCost)
|
||||||
|
.toString(10)
|
||||||
|
)
|
||||||
|
homeVBalances[v].gasPrice = parseFloat(homeGasPriceGwei)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!foreignValidators.includes(v)) {
|
||||||
|
validatorsMatch = false
|
||||||
|
homeVBalances[v].onlyOnHome = true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
logger.debug('calling homeBridgeValidators.methods.requiredSignatures().call()')
|
logger.debug('calling homeBridgeValidators.methods.requiredSignatures().call()')
|
||||||
const reqSigHome = await homeBridgeValidators.methods.requiredSignatures().call()
|
const reqSigHome = await homeBridgeValidators.methods.requiredSignatures().call()
|
||||||
@ -164,20 +169,22 @@ async function main(bridgeMode) {
|
|||||||
logger.debug('Done')
|
logger.debug('Done')
|
||||||
return {
|
return {
|
||||||
home: {
|
home: {
|
||||||
validators: {
|
validators: homeVBalances,
|
||||||
...homeVBalances
|
|
||||||
},
|
|
||||||
requiredSignatures: Number(reqSigHome)
|
requiredSignatures: Number(reqSigHome)
|
||||||
},
|
},
|
||||||
foreign: {
|
foreign: {
|
||||||
validators: {
|
validators: foreignVBalances,
|
||||||
...foreignVBalances
|
|
||||||
},
|
|
||||||
requiredSignatures: Number(reqSigForeign)
|
requiredSignatures: Number(reqSigForeign)
|
||||||
},
|
},
|
||||||
requiredSignaturesMatch: reqSigHome === reqSigForeign,
|
requiredSignaturesMatch: reqSigHome === reqSigForeign,
|
||||||
validatorsMatch,
|
validatorsMatch,
|
||||||
lastChecked: Math.floor(Date.now() / 1000)
|
lastChecked: Math.floor(Date.now() / 1000),
|
||||||
|
homeOk: Object.values(homeVBalances)
|
||||||
|
.filter(vb => typeof vb.leftTx === 'number')
|
||||||
|
.every(vb => vb.leftTx >= MONITOR_TX_NUMBER_THRESHOLD),
|
||||||
|
foreignOk: Object.values(foreignVBalances)
|
||||||
|
.filter(vb => typeof vb.leftTx === 'number')
|
||||||
|
.every(vb => vb.leftTx >= MONITOR_TX_NUMBER_THRESHOLD)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user