From 40269d262ed9e86a06df63f4a7f5ba7d9f0ee31b Mon Sep 17 00:00:00 2001 From: Gerardo Nardelli Date: Mon, 30 Dec 2019 11:05:59 -0300 Subject: [PATCH 01/30] Add support to disable validator balance check in monitor --- monitor/index.js | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/monitor/index.js b/monitor/index.js index 50ff5426c..29147f5b5 100644 --- a/monitor/index.js +++ b/monitor/index.js @@ -5,6 +5,8 @@ const { isV1Bridge } = require('./utils/serverUtils') const app = express() +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 console.log('MONITOR_TX_NUMBER_THRESHOLD = ' + MONITOR_TX_NUMBER_THRESHOLD) @@ -52,18 +54,25 @@ app.get('/validators', async (req, res, next) => { const results = await readFile('./responses/validators.json') results.homeOk = true results.foreignOk = true - for (const hv in results.home.validators) { - if (results.home.validators[hv].leftTx < MONITOR_TX_NUMBER_THRESHOLD) { - results.homeOk = false - break + + if (MONITOR_VALIDATOR_HOME_TX_LIMIT) { + for (const hv in results.home.validators) { + if (results.home.validators[hv].leftTx < MONITOR_TX_NUMBER_THRESHOLD) { + results.homeOk = false + break + } } } - for (const hv in results.foreign.validators) { - if (results.foreign.validators[hv].leftTx < MONITOR_TX_NUMBER_THRESHOLD) { - results.foreignOk = false - break + + if (MONITOR_VALIDATOR_FOREIGN_TX_LIMIT) { + for (const hv in results.foreign.validators) { + if (results.foreign.validators[hv].leftTx < MONITOR_TX_NUMBER_THRESHOLD) { + results.foreignOk = false + break + } } } + results.ok = results.homeOk && results.foreignOk res.json(results) } catch (e) { From a4b049dfbc321232719779114097b3cce20b88f3 Mon Sep 17 00:00:00 2001 From: Gerardo Nardelli Date: Thu, 2 Jan 2020 10:08:06 -0300 Subject: [PATCH 02/30] Convert validator address to checksum address --- monitor/validators.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/monitor/validators.js b/monitor/validators.js index 80f353514..4acad7310 100644 --- a/monitor/validators.js +++ b/monitor/validators.js @@ -65,18 +65,18 @@ async function main(bridgeMode) { const foreignBridgeValidators = new web3Foreign.eth.Contract(BRIDGE_VALIDATORS_ABI, foreignValidatorsAddress) logger.debug('calling foreignBridgeValidators getValidatorList()') - const foreignValidators = await getValidatorList(foreignValidatorsAddress, web3Foreign.eth, { + const foreignValidators = (await getValidatorList(foreignValidatorsAddress, web3Foreign.eth, { from: MONITOR_FOREIGN_START_BLOCK, to: foreignBlockNumber, logger - }) + })).map(web3Foreign.utils.toChecksumAddress) logger.debug('calling homeBridgeValidators getValidatorList()') - const homeValidators = await getValidatorList(homeValidatorsAddress, web3Home.eth, { + const homeValidators = (await getValidatorList(homeValidatorsAddress, web3Home.eth, { from: MONITOR_HOME_START_BLOCK, to: homeBlockNumber, logger - }) + })).map(web3Home.utils.toChecksumAddress) const homeBalances = {} logger.debug('calling asyncForEach homeValidators homeBalances') From 441c944c4bc221b3550197d4eb3afb67e3692eae Mon Sep 17 00:00:00 2001 From: Gerardo Nardelli Date: Thu, 2 Jan 2020 11:36:05 -0300 Subject: [PATCH 03/30] Avoid extra calls if tx limit is zero in validators checks --- monitor/validators.js | 93 +++++++++++++++++++++++++++---------------- 1 file changed, 58 insertions(+), 35 deletions(-) diff --git a/monitor/validators.js b/monitor/validators.js index 4acad7310..f66ff4634 100644 --- a/monitor/validators.js +++ b/monitor/validators.js @@ -10,12 +10,10 @@ const { COMMON_FOREIGN_RPC_URL, COMMON_HOME_BRIDGE_ADDRESS, COMMON_FOREIGN_BRIDGE_ADDRESS, - MONITOR_VALIDATOR_HOME_TX_LIMIT, COMMON_HOME_GAS_PRICE_SUPPLIER_URL, COMMON_HOME_GAS_PRICE_SPEED_TYPE, COMMON_HOME_GAS_PRICE_FALLBACK, COMMON_HOME_GAS_PRICE_FACTOR, - MONITOR_VALIDATOR_FOREIGN_TX_LIMIT, COMMON_FOREIGN_GAS_PRICE_SUPPLIER_URL, COMMON_FOREIGN_GAS_PRICE_SPEED_TYPE, COMMON_FOREIGN_GAS_PRICE_FALLBACK, @@ -23,6 +21,8 @@ const { } = process.env const MONITOR_HOME_START_BLOCK = Number(process.env.MONITOR_HOME_START_BLOCK) || 0 const MONITOR_FOREIGN_START_BLOCK = Number(process.env.MONITOR_FOREIGN_START_BLOCK) || 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 Web3Utils = Web3.utils @@ -78,63 +78,86 @@ async function main(bridgeMode) { logger })).map(web3Home.utils.toChecksumAddress) - const homeBalances = {} - logger.debug('calling asyncForEach homeValidators homeBalances') - await asyncForEach(homeValidators, async v => { - homeBalances[v] = Web3Utils.fromWei(await web3Home.eth.getBalance(v)) - }) const foreignVBalances = {} const homeVBalances = {} - logger.debug('calling home getGasPrices') - const homeGasPrice = - (await gasPriceFromSupplier(() => fetch(COMMON_HOME_GAS_PRICE_SUPPLIER_URL), homeGasPriceSupplierOpts)) || - Web3Utils.toBN(COMMON_HOME_GAS_PRICE_FALLBACK) - const homeGasPriceGwei = Web3Utils.fromWei(homeGasPrice.toString(), 'gwei') - const homeTxCost = homeGasPrice.mul(Web3Utils.toBN(MONITOR_VALIDATOR_HOME_TX_LIMIT)) + let homeGasPrice + let homeGasPriceGwei + let homeTxCost + + if (MONITOR_VALIDATOR_HOME_TX_LIMIT) { + logger.debug('calling home getGasPrices') + homeGasPrice = + (await gasPriceFromSupplier(() => fetch(COMMON_HOME_GAS_PRICE_SUPPLIER_URL), homeGasPriceSupplierOpts)) || + Web3Utils.toBN(COMMON_HOME_GAS_PRICE_FALLBACK) + homeGasPriceGwei = Web3Utils.fromWei(homeGasPrice.toString(), 'gwei') + homeTxCost = homeGasPrice.mul(Web3Utils.toBN(MONITOR_VALIDATOR_HOME_TX_LIMIT)) + } - logger.debug('calling foreign getGasPrices') - const foreignGasPrice = - (await gasPriceFromSupplier(() => fetch(COMMON_FOREIGN_GAS_PRICE_SUPPLIER_URL), foreignGasPriceSupplierOpts)) || - Web3Utils.toBN(COMMON_FOREIGN_GAS_PRICE_FALLBACK) - const foreignGasPriceGwei = Web3Utils.fromWei(foreignGasPrice.toString(), 'gwei') - const foreignTxCost = foreignGasPrice.mul(Web3Utils.toBN(MONITOR_VALIDATOR_FOREIGN_TX_LIMIT)) + let foreignGasPrice + let foreignGasPriceGwei + let foreignTxCost + + if (MONITOR_VALIDATOR_FOREIGN_TX_LIMIT) { + logger.debug('calling foreign getGasPrices') + foreignGasPrice = + (await gasPriceFromSupplier(() => fetch(COMMON_FOREIGN_GAS_PRICE_SUPPLIER_URL), foreignGasPriceSupplierOpts)) || + Web3Utils.toBN(COMMON_FOREIGN_GAS_PRICE_FALLBACK) + foreignGasPriceGwei = Web3Utils.fromWei(foreignGasPrice.toString(), 'gwei') + foreignTxCost = foreignGasPrice.mul(Web3Utils.toBN(MONITOR_VALIDATOR_FOREIGN_TX_LIMIT)) + } let validatorsMatch = true logger.debug('calling asyncForEach foreignValidators foreignVBalances') await asyncForEach(foreignValidators, async v => { const balance = await web3Foreign.eth.getBalance(v) - const leftTx = Web3Utils.toBN(balance) - .div(foreignTxCost) - .toString(10) - foreignVBalances[v] = { - balance: Web3Utils.fromWei(balance), - leftTx: Number(leftTx), - gasPrice: Number(foreignGasPriceGwei) + if (MONITOR_VALIDATOR_FOREIGN_TX_LIMIT) { + const leftTx = Web3Utils.toBN(balance) + .div(foreignTxCost) + .toString(10) + foreignVBalances[v] = { + balance: Web3Utils.fromWei(balance), + leftTx: Number(leftTx), + gasPrice: Number(foreignGasPriceGwei) + } + } else { + foreignVBalances[v] = { + balance: Web3Utils.fromWei(balance) + } } + if (!homeValidators.includes(v)) { validatorsMatch = false foreignVBalances[v].onlyOnForeign = true } }) + logger.debug('calling asyncForEach homeValidators homeVBalances') await asyncForEach(homeValidators, async v => { const balance = await web3Home.eth.getBalance(v) - const leftTx = homeTxCost.isZero() - ? 999999 - : Web3Utils.toBN(balance) - .div(homeTxCost) - .toString(10) - homeVBalances[v] = { - balance: Web3Utils.fromWei(balance), - leftTx: Number(leftTx), - gasPrice: Number(homeGasPriceGwei) + if (MONITOR_VALIDATOR_HOME_TX_LIMIT) { + const leftTx = homeTxCost.isZero() + ? 999999 + : 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)) { validatorsMatch = false homeVBalances[v].onlyOnHome = true } }) + logger.debug('calling homeBridgeValidators.methods.requiredSignatures().call()') const reqSigHome = await homeBridgeValidators.methods.requiredSignatures().call() logger.debug('calling foreignBridgeValidators.methods.requiredSignatures().call()') From 4e3181e3d0e171ea6a54b1992b01e1473ea5d06b Mon Sep 17 00:00:00 2001 From: Gerardo Nardelli Date: Thu, 2 Jan 2020 16:37:28 -0300 Subject: [PATCH 04/30] Remove bridge specific logic from index.js in monitor --- monitor/checkWorker.js | 28 +++++++++++++++++++ monitor/checkWorker2.js | 7 +++++ monitor/checkWorker3.js | 1 + monitor/index.js | 59 ++++++----------------------------------- 4 files changed, 44 insertions(+), 51 deletions(-) diff --git a/monitor/checkWorker.js b/monitor/checkWorker.js index e0898fc14..85fc831da 100644 --- a/monitor/checkWorker.js +++ b/monitor/checkWorker.js @@ -8,6 +8,11 @@ const getShortEventStats = require('./getShortEventStats') const validators = require('./validators') const { COMMON_HOME_BRIDGE_ADDRESS, COMMON_HOME_RPC_URL } = 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 homeProvider = new Web3.providers.HttpProvider(COMMON_HOME_RPC_URL) const web3Home = new Web3(homeProvider) @@ -31,6 +36,29 @@ async function checkWorker() { logger.debug('calling validators()') const vBalances = await validators(bridgeMode) 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 fs.writeFileSync(path.join(__dirname, '/responses/validators.json'), JSON.stringify(vBalances, null, 4)) logger.debug('Done') } catch (e) { diff --git a/monitor/checkWorker2.js b/monitor/checkWorker2.js index 6375e47d7..b9a37b2cd 100644 --- a/monitor/checkWorker2.js +++ b/monitor/checkWorker2.js @@ -9,10 +9,17 @@ async function checkWorker2() { logger.debug('calling eventsStats()') const evStats = await eventsStats() if (!evStats) throw new Error('evStats is empty: ' + JSON.stringify(evStats)) + evStats.ok = + (evStats.onlyInHomeDeposits || evStats.home.deliveredMsgNotProcessedInForeign).length === 0 && + (evStats.onlyInForeignDeposits || evStats.home.processedMsgNotDeliveredInForeign).length === 0 && + (evStats.onlyInHomeWithdrawals || evStats.foreign.deliveredMsgNotProcessedInHome).length === 0 && + (evStats.onlyInForeignWithdrawals || evStats.foreign.processedMsgNotDeliveredInHome).length === 0 fs.writeFileSync(path.join(__dirname, '/responses/eventsStats.json'), JSON.stringify(evStats, null, 4)) + logger.debug('calling alerts()') const _alerts = await alerts() if (!_alerts) throw new Error('alerts is empty: ' + JSON.stringify(_alerts)) + _alerts.ok = !_alerts.executeAffirmations.mostRecentTxHash && !_alerts.executeSignatures.mostRecentTxHash fs.writeFileSync(path.join(__dirname, '/responses/alerts.json'), JSON.stringify(_alerts, null, 4)) logger.debug('Done x2') } catch (e) { diff --git a/monitor/checkWorker3.js b/monitor/checkWorker3.js index d6ec47145..25a5a26b9 100644 --- a/monitor/checkWorker3.js +++ b/monitor/checkWorker3.js @@ -9,6 +9,7 @@ async function checkWorker3() { const transfers = await stuckTransfers() // console.log(transfers) if (!transfers) throw new Error('transfers is empty: ' + JSON.stringify(transfers)) + transfers.ok = transfers.total.length === 0 fs.writeFileSync(path.join(__dirname, '/responses/stuckTransfers.json'), JSON.stringify(transfers, null, 4)) logger.debug('Done') } catch (e) { diff --git a/monitor/index.js b/monitor/index.js index 29147f5b5..72d5d1337 100644 --- a/monitor/index.js +++ b/monitor/index.js @@ -1,15 +1,9 @@ require('dotenv').config() const express = require('express') const fs = require('fs') -const { isV1Bridge } = require('./utils/serverUtils') const app = express() -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 -console.log('MONITOR_TX_NUMBER_THRESHOLD = ' + MONITOR_TX_NUMBER_THRESHOLD) - async function readFile(path) { try { const content = await fs.readFileSync(path) @@ -24,21 +18,6 @@ async function readFile(path) { } } -async function initV1routes(app) { - const exposeV1Routes = await isV1Bridge() - if (exposeV1Routes) { - app.get('/stuckTransfers', async (req, res, next) => { - try { - const results = await readFile('./responses/stuckTransfers.json') - results.ok = results.total.length === 0 - res.json(results) - } catch (e) { - next(e) - } - }) - } -} - app.get('/', async (req, res, next) => { try { const results = await readFile('./responses/getBalances.json') @@ -52,28 +31,6 @@ app.get('/', async (req, res, next) => { app.get('/validators', async (req, res, next) => { try { const results = await readFile('./responses/validators.json') - results.homeOk = true - results.foreignOk = true - - if (MONITOR_VALIDATOR_HOME_TX_LIMIT) { - for (const hv in results.home.validators) { - if (results.home.validators[hv].leftTx < MONITOR_TX_NUMBER_THRESHOLD) { - results.homeOk = false - break - } - } - } - - if (MONITOR_VALIDATOR_FOREIGN_TX_LIMIT) { - for (const hv in results.foreign.validators) { - if (results.foreign.validators[hv].leftTx < MONITOR_TX_NUMBER_THRESHOLD) { - results.foreignOk = false - break - } - } - } - - results.ok = results.homeOk && results.foreignOk res.json(results) } catch (e) { // this will eventually be handled by your error handling middleware @@ -81,15 +38,9 @@ app.get('/validators', async (req, res, next) => { } }) -// responses/eventsStats.json app.get('/eventsStats', async (req, res, next) => { try { const results = await readFile('./responses/eventsStats.json') - results.ok = - (results.onlyInHomeDeposits || results.home.deliveredMsgNotProcessedInForeign).length === 0 && - (results.onlyInForeignDeposits || results.home.processedMsgNotDeliveredInForeign).length === 0 && - (results.onlyInHomeWithdrawals || results.foreign.deliveredMsgNotProcessedInHome).length === 0 && - (results.onlyInForeignWithdrawals || results.foreign.processedMsgNotDeliveredInHome).length === 0 res.json(results) } catch (e) { // this will eventually be handled by your error handling middleware @@ -100,14 +51,20 @@ app.get('/eventsStats', async (req, res, next) => { app.get('/alerts', async (req, res, next) => { try { const results = await readFile('./responses/alerts.json') - results.ok = !results.executeAffirmations.mostRecentTxHash && !results.executeSignatures.mostRecentTxHash res.json(results) } catch (e) { next(e) } }) -initV1routes(app) +app.get('/stuckTransfers', async (req, res, next) => { + try { + const results = await readFile('./responses/stuckTransfers.json') + res.json(results) + } catch (e) { + next(e) + } +}) const port = process.env.MONITOR_PORT || 3003 app.set('port', port) From 5ce2b7befe5f20ccdd38304674e0ea22c38e13b2 Mon Sep 17 00:00:00 2001 From: Gerardo Nardelli Date: Fri, 3 Jan 2020 10:47:31 -0300 Subject: [PATCH 05/30] Store monitor results in responses/bridge_name --- monitor/checkWorker.js | 10 +++++----- monitor/checkWorker2.js | 10 ++++++---- monitor/checkWorker3.js | 8 +++++--- monitor/index.js | 37 +++++++++++++------------------------ monitor/utils/file.js | 30 ++++++++++++++++++++++++++++++ 5 files changed, 59 insertions(+), 36 deletions(-) create mode 100644 monitor/utils/file.js diff --git a/monitor/checkWorker.js b/monitor/checkWorker.js index 85fc831da..19ece92fc 100644 --- a/monitor/checkWorker.js +++ b/monitor/checkWorker.js @@ -1,13 +1,12 @@ -const fs = require('fs') -const path = require('path') const Web3 = require('web3') const logger = require('./logger')('checkWorker') const { getBridgeMode } = require('../commons') const getBalances = require('./getBalances') const getShortEventStats = require('./getShortEventStats') const validators = require('./validators') +const { writeFile, createDir } = require('./utils/file') -const { COMMON_HOME_BRIDGE_ADDRESS, COMMON_HOME_RPC_URL } = process.env +const { COMMON_HOME_BRIDGE_ADDRESS, COMMON_HOME_RPC_URL, 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 @@ -20,6 +19,7 @@ const { HOME_ERC_TO_ERC_ABI } = require('../commons') async function checkWorker() { try { + createDir(`/responses/${BRIDGE_NAME}`) const homeBridge = new web3Home.eth.Contract(HOME_ERC_TO_ERC_ABI, COMMON_HOME_BRIDGE_ADDRESS) const bridgeMode = await getBridgeMode(homeBridge) logger.debug('Bridge mode:', bridgeMode) @@ -31,7 +31,7 @@ async function checkWorker() { const foreign = Object.assign({}, balances.foreign, events.foreign) const status = Object.assign({}, balances, events, { home }, { foreign }) if (!status) throw new Error('status is empty: ' + JSON.stringify(status)) - fs.writeFileSync(path.join(__dirname, '/responses/getBalances.json'), JSON.stringify(status, null, 4)) + writeFile(`/responses/${BRIDGE_NAME}/getBalances.json`, status) logger.debug('calling validators()') const vBalances = await validators(bridgeMode) @@ -59,7 +59,7 @@ async function checkWorker() { } vBalances.ok = vBalances.homeOk && vBalances.foreignOk - fs.writeFileSync(path.join(__dirname, '/responses/validators.json'), JSON.stringify(vBalances, null, 4)) + writeFile(`/responses/${BRIDGE_NAME}/validators.json`, vBalances) logger.debug('Done') } catch (e) { logger.error(e) diff --git a/monitor/checkWorker2.js b/monitor/checkWorker2.js index b9a37b2cd..858445e9a 100644 --- a/monitor/checkWorker2.js +++ b/monitor/checkWorker2.js @@ -1,11 +1,13 @@ -const fs = require('fs') -const path = require('path') const logger = require('./logger')('checkWorker2') const eventsStats = require('./eventsStats') const alerts = require('./alerts') +const { writeFile, createDir } = require('./utils/file') + +const { BRIDGE_NAME } = process.env async function checkWorker2() { try { + createDir(`/responses/${BRIDGE_NAME}`) logger.debug('calling eventsStats()') const evStats = await eventsStats() if (!evStats) throw new Error('evStats is empty: ' + JSON.stringify(evStats)) @@ -14,13 +16,13 @@ async function checkWorker2() { (evStats.onlyInForeignDeposits || evStats.home.processedMsgNotDeliveredInForeign).length === 0 && (evStats.onlyInHomeWithdrawals || evStats.foreign.deliveredMsgNotProcessedInHome).length === 0 && (evStats.onlyInForeignWithdrawals || evStats.foreign.processedMsgNotDeliveredInHome).length === 0 - fs.writeFileSync(path.join(__dirname, '/responses/eventsStats.json'), JSON.stringify(evStats, null, 4)) + writeFile(`/responses/${BRIDGE_NAME}/eventsStats.json`, evStats) logger.debug('calling alerts()') const _alerts = await alerts() if (!_alerts) throw new Error('alerts is empty: ' + JSON.stringify(_alerts)) _alerts.ok = !_alerts.executeAffirmations.mostRecentTxHash && !_alerts.executeSignatures.mostRecentTxHash - fs.writeFileSync(path.join(__dirname, '/responses/alerts.json'), JSON.stringify(_alerts, null, 4)) + writeFile(`/responses/${BRIDGE_NAME}/alerts.json`, _alerts) logger.debug('Done x2') } catch (e) { logger.error(e) diff --git a/monitor/checkWorker3.js b/monitor/checkWorker3.js index 25a5a26b9..c67bfecff 100644 --- a/monitor/checkWorker3.js +++ b/monitor/checkWorker3.js @@ -1,16 +1,18 @@ -const fs = require('fs') -const path = require('path') const logger = require('./logger')('checkWorker3') const stuckTransfers = require('./stuckTransfers') +const { writeFile, createDir } = require('./utils/file') + +const { BRIDGE_NAME } = process.env async function checkWorker3() { try { + createDir(`/responses/${BRIDGE_NAME}`) logger.debug('calling stuckTransfers()') const transfers = await stuckTransfers() // console.log(transfers) if (!transfers) throw new Error('transfers is empty: ' + JSON.stringify(transfers)) transfers.ok = transfers.total.length === 0 - fs.writeFileSync(path.join(__dirname, '/responses/stuckTransfers.json'), JSON.stringify(transfers, null, 4)) + writeFile(`/responses/${BRIDGE_NAME}/stuckTransfers.json`, transfers) logger.debug('Done') } catch (e) { logger.error('checkWorker3.js', e) diff --git a/monitor/index.js b/monitor/index.js index 72d5d1337..076af6db6 100644 --- a/monitor/index.js +++ b/monitor/index.js @@ -1,26 +1,15 @@ require('dotenv').config() const express = require('express') -const fs = require('fs') +const { readFile } = require('./utils/file') const app = express() +const bridgeRouter = express.Router({ mergeParams: true }) -async function readFile(path) { - try { - const content = await fs.readFileSync(path) - const json = JSON.parse(content) - const timeDiff = Math.floor(Date.now() / 1000) - json.lastChecked - return Object.assign({}, json, { timeDiff }) - } catch (e) { - console.error(e) - return { - error: 'please check your worker' - } - } -} +app.use('/:bridgeName', bridgeRouter) -app.get('/', async (req, res, next) => { +bridgeRouter.get('/', async (req, res, next) => { try { - const results = await readFile('./responses/getBalances.json') + const results = await readFile(`./responses/${req.params.bridgeName}/getBalances.json`) res.json(results) } catch (e) { // this will eventually be handled by your error handling middleware @@ -28,9 +17,9 @@ app.get('/', async (req, res, next) => { } }) -app.get('/validators', async (req, res, next) => { +bridgeRouter.get('/validators', async (req, res, next) => { try { - const results = await readFile('./responses/validators.json') + const results = await readFile(`./responses/${req.params.bridgeName}/validators.json`) res.json(results) } catch (e) { // this will eventually be handled by your error handling middleware @@ -38,9 +27,9 @@ app.get('/validators', async (req, res, next) => { } }) -app.get('/eventsStats', async (req, res, next) => { +bridgeRouter.get('/eventsStats', async (req, res, next) => { try { - const results = await readFile('./responses/eventsStats.json') + const results = await readFile(`./responses/${req.params.bridgeName}/eventsStats.json`) res.json(results) } catch (e) { // this will eventually be handled by your error handling middleware @@ -48,18 +37,18 @@ app.get('/eventsStats', async (req, res, next) => { } }) -app.get('/alerts', async (req, res, next) => { +bridgeRouter.get('/alerts', async (req, res, next) => { try { - const results = await readFile('./responses/alerts.json') + const results = await readFile(`./responses/${req.params.bridgeName}/alerts.json`) res.json(results) } catch (e) { next(e) } }) -app.get('/stuckTransfers', async (req, res, next) => { +bridgeRouter.get('/stuckTransfers', async (req, res, next) => { try { - const results = await readFile('./responses/stuckTransfers.json') + const results = await readFile(`./responses/${req.params.bridgeName}/stuckTransfers.json`) res.json(results) } catch (e) { next(e) diff --git a/monitor/utils/file.js b/monitor/utils/file.js new file mode 100644 index 000000000..745bcfca5 --- /dev/null +++ b/monitor/utils/file.js @@ -0,0 +1,30 @@ +const fs = require('fs') +const path = require('path') + +async function readFile(filePath) { + try { + const content = await fs.readFileSync(filePath) + const json = JSON.parse(content) + const timeDiff = Math.floor(Date.now() / 1000) - json.lastChecked + return Object.assign({}, json, { timeDiff }) + } catch (e) { + console.error(e) + return { + error: 'please check your worker' + } + } +} + +function writeFile(filePath, object) { + fs.writeFileSync(path.join(process.cwd(), filePath), JSON.stringify(object, null, 4)) +} + +function createDir(dirPath) { + fs.mkdirSync(path.join(process.cwd(), dirPath), { recursive: true }) +} + +module.exports = { + readFile, + writeFile, + createDir +} From 639c31978a6af075b33c119242a44bb49947d783 Mon Sep 17 00:00:00 2001 From: Gerardo Nardelli Date: Fri, 3 Jan 2020 11:47:28 -0300 Subject: [PATCH 06/30] Add example configs for monitor --- CONFIGURATION.md | 1 + monitor/.env.example | 2 ++ monitor/README.md | 2 +- monitor/checkWorker.js | 8 ++++---- monitor/checkWorker2.js | 8 ++++---- monitor/checkWorker3.js | 6 +++--- monitor/configs/dai.env.example | 19 +++++++++++++++++++ monitor/configs/wetc.env.example | 24 ++++++++++++++++++++++++ monitor/docker-compose.yml | 2 +- 9 files changed, 59 insertions(+), 13 deletions(-) create mode 100644 monitor/configs/dai.env.example create mode 100644 monitor/configs/wetc.env.example diff --git a/CONFIGURATION.md b/CONFIGURATION.md index 579091aeb..cb995068a 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -69,3 +69,4 @@ MONITOR_VALIDATOR_HOME_TX_LIMIT | Average gas usage of a transaction sent by a v MONITOR_VALIDATOR_FOREIGN_TX_LIMIT | Average gas usage of a transaction sent by a validator, it is used to estimate the number of transaction that can be paid by the validator. | integer MONITOR_TX_NUMBER_THRESHOLD | If estimated number of transaction is equal to or below this value, the monitor will report that the validator has less funds than it is required. | integer MONITOR_PORT | The port for the Monitor. | integer +MONITOR_BRIDGE_NAME | The name to be used in the url path for the bridge | string diff --git a/monitor/.env.example b/monitor/.env.example index e5ca97729..02f49a860 100644 --- a/monitor/.env.example +++ b/monitor/.env.example @@ -1,3 +1,5 @@ +MONITOR_BRIDGE_NAME=bridge + COMMON_HOME_RPC_URL=https://sokol.poa.network COMMON_FOREIGN_RPC_URL=https://kovan.infura.io/mew COMMON_HOME_BRIDGE_ADDRESS=0xABb4C1399DcC28FBa3Beb76CAE2b50Be3e087353 diff --git a/monitor/README.md b/monitor/README.md index 0333f6f54..34df0febf 100644 --- a/monitor/README.md +++ b/monitor/README.md @@ -126,7 +126,7 @@ Using Docker: docker-compose up -d ``` -- The application will run on `http://localhost:PORT`, where `PORT` is specified in your `.env` file. +- The application will run on `http://localhost:PORT/BRIDGE_NAME`, where `PORT` and `BRIDGE_NAME` are specified in your `.env` file. - To enabled debug logging, set `DEBUG=1` variable in `.env`. ## Check balances of contracts and validators, get unprocessed events diff --git a/monitor/checkWorker.js b/monitor/checkWorker.js index 19ece92fc..98c10184b 100644 --- a/monitor/checkWorker.js +++ b/monitor/checkWorker.js @@ -6,7 +6,7 @@ const getShortEventStats = require('./getShortEventStats') const validators = require('./validators') const { writeFile, createDir } = require('./utils/file') -const { COMMON_HOME_BRIDGE_ADDRESS, COMMON_HOME_RPC_URL, BRIDGE_NAME } = process.env +const { COMMON_HOME_BRIDGE_ADDRESS, COMMON_HOME_RPC_URL, 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 @@ -19,7 +19,7 @@ const { HOME_ERC_TO_ERC_ABI } = require('../commons') async function checkWorker() { try { - createDir(`/responses/${BRIDGE_NAME}`) + createDir(`/responses/${MONITOR_BRIDGE_NAME}`) const homeBridge = new web3Home.eth.Contract(HOME_ERC_TO_ERC_ABI, COMMON_HOME_BRIDGE_ADDRESS) const bridgeMode = await getBridgeMode(homeBridge) logger.debug('Bridge mode:', bridgeMode) @@ -31,7 +31,7 @@ async function checkWorker() { const foreign = Object.assign({}, balances.foreign, events.foreign) const status = Object.assign({}, balances, events, { home }, { foreign }) if (!status) throw new Error('status is empty: ' + JSON.stringify(status)) - writeFile(`/responses/${BRIDGE_NAME}/getBalances.json`, status) + writeFile(`/responses/${MONITOR_BRIDGE_NAME}/getBalances.json`, status) logger.debug('calling validators()') const vBalances = await validators(bridgeMode) @@ -59,7 +59,7 @@ async function checkWorker() { } vBalances.ok = vBalances.homeOk && vBalances.foreignOk - writeFile(`/responses/${BRIDGE_NAME}/validators.json`, vBalances) + writeFile(`/responses/${MONITOR_BRIDGE_NAME}/validators.json`, vBalances) logger.debug('Done') } catch (e) { logger.error(e) diff --git a/monitor/checkWorker2.js b/monitor/checkWorker2.js index 858445e9a..c05bb1093 100644 --- a/monitor/checkWorker2.js +++ b/monitor/checkWorker2.js @@ -3,11 +3,11 @@ const eventsStats = require('./eventsStats') const alerts = require('./alerts') const { writeFile, createDir } = require('./utils/file') -const { BRIDGE_NAME } = process.env +const { MONITOR_BRIDGE_NAME } = process.env async function checkWorker2() { try { - createDir(`/responses/${BRIDGE_NAME}`) + createDir(`/responses/${MONITOR_BRIDGE_NAME}`) logger.debug('calling eventsStats()') const evStats = await eventsStats() if (!evStats) throw new Error('evStats is empty: ' + JSON.stringify(evStats)) @@ -16,13 +16,13 @@ async function checkWorker2() { (evStats.onlyInForeignDeposits || evStats.home.processedMsgNotDeliveredInForeign).length === 0 && (evStats.onlyInHomeWithdrawals || evStats.foreign.deliveredMsgNotProcessedInHome).length === 0 && (evStats.onlyInForeignWithdrawals || evStats.foreign.processedMsgNotDeliveredInHome).length === 0 - writeFile(`/responses/${BRIDGE_NAME}/eventsStats.json`, evStats) + writeFile(`/responses/${MONITOR_BRIDGE_NAME}/eventsStats.json`, evStats) logger.debug('calling alerts()') const _alerts = await alerts() if (!_alerts) throw new Error('alerts is empty: ' + JSON.stringify(_alerts)) _alerts.ok = !_alerts.executeAffirmations.mostRecentTxHash && !_alerts.executeSignatures.mostRecentTxHash - writeFile(`/responses/${BRIDGE_NAME}/alerts.json`, _alerts) + writeFile(`/responses/${MONITOR_BRIDGE_NAME}/alerts.json`, _alerts) logger.debug('Done x2') } catch (e) { logger.error(e) diff --git a/monitor/checkWorker3.js b/monitor/checkWorker3.js index c67bfecff..c86d96117 100644 --- a/monitor/checkWorker3.js +++ b/monitor/checkWorker3.js @@ -2,17 +2,17 @@ const logger = require('./logger')('checkWorker3') const stuckTransfers = require('./stuckTransfers') const { writeFile, createDir } = require('./utils/file') -const { BRIDGE_NAME } = process.env +const { MONITOR_BRIDGE_NAME } = process.env async function checkWorker3() { try { - createDir(`/responses/${BRIDGE_NAME}`) + createDir(`/responses/${MONITOR_BRIDGE_NAME}`) logger.debug('calling stuckTransfers()') const transfers = await stuckTransfers() // console.log(transfers) if (!transfers) throw new Error('transfers is empty: ' + JSON.stringify(transfers)) transfers.ok = transfers.total.length === 0 - writeFile(`/responses/${BRIDGE_NAME}/stuckTransfers.json`, transfers) + writeFile(`/responses/${MONITOR_BRIDGE_NAME}/stuckTransfers.json`, transfers) logger.debug('Done') } catch (e) { logger.error('checkWorker3.js', e) diff --git a/monitor/configs/dai.env.example b/monitor/configs/dai.env.example new file mode 100644 index 000000000..ee03f6d8d --- /dev/null +++ b/monitor/configs/dai.env.example @@ -0,0 +1,19 @@ +MONITOR_BRIDGE_NAME=xdai + +COMMON_HOME_RPC_URL=https://dai.poa.network +COMMON_HOME_BRIDGE_ADDRESS=0x7301CFA0e1756B71869E93d4e4Dca5c7d0eb0AA6 +COMMON_FOREIGN_RPC_URL=https://mainnet.infura.io/v3/ +COMMON_FOREIGN_BRIDGE_ADDRESS=0x4aa42145Aa6Ebf72e164C9bBC74fbD3788045016 + +COMMON_HOME_GAS_PRICE_FALLBACK= 0 +COMMON_FOREIGN_GAS_PRICE_SUPPLIER_URL=https://gasprice.poa.network/ +COMMON_FOREIGN_GAS_PRICE_SPEED_TYPE=standard +COMMON_FOREIGN_GAS_PRICE_FALLBACK=10000000000 +ORACLE_FOREIGN_GAS_PRICE_UPDATE_INTERVAL=600000 +COMMON_FOREIGN_GAS_PRICE_FACTOR=1 + +MONITOR_HOME_START_BLOCK=759 +MONITOR_FOREIGN_START_BLOCK=6478417 +MONITOR_VALIDATOR_HOME_TX_LIMIT=300000 +MONITOR_VALIDATOR_FOREIGN_TX_LIMIT=300000 +MONITOR_TX_NUMBER_THRESHOLD=100 diff --git a/monitor/configs/wetc.env.example b/monitor/configs/wetc.env.example new file mode 100644 index 000000000..32e6bef71 --- /dev/null +++ b/monitor/configs/wetc.env.example @@ -0,0 +1,24 @@ +MONITOR_BRIDGE_NAME=wetc + +COMMON_HOME_RPC_URL=https://ethereumclassic.network +COMMON_HOME_BRIDGE_ADDRESS=0x073081832B4Ecdce79d4D6753565c85Ba4b3BeA9 +COMMON_FOREIGN_RPC_URL=https://mainnet.infura.io/v3/ +COMMON_FOREIGN_BRIDGE_ADDRESS=0x0cB781EE62F815bdD9CD4c2210aE8600d43e7040 + +COMMON_HOME_GAS_PRICE_SUPPLIER_URL=https://gasprice-etc.poa.network/ +COMMON_HOME_GAS_PRICE_SPEED_TYPE=standard +COMMON_HOME_GAS_PRICE_FALLBACK=15000000000 +ORACLE_HOME_GAS_PRICE_UPDATE_INTERVAL=600000 +COMMON_HOME_GAS_PRICE_FACTOR=1 + +COMMON_FOREIGN_GAS_PRICE_SUPPLIER_URL=https://gasprice.poa.network/ +COMMON_FOREIGN_GAS_PRICE_SPEED_TYPE=standard +COMMON_FOREIGN_GAS_PRICE_FALLBACK=10000000000 +ORACLE_FOREIGN_GAS_PRICE_UPDATE_INTERVAL=600000 +COMMON_FOREIGN_GAS_PRICE_FACTOR=1 + +MONITOR_HOME_START_BLOCK=7703292 +MONITOR_FOREIGN_START_BLOCK=7412459 +MONITOR_VALIDATOR_HOME_TX_LIMIT=300000 +MONITOR_VALIDATOR_FOREIGN_TX_LIMIT=300000 +MONITOR_TX_NUMBER_THRESHOLD=100 diff --git a/monitor/docker-compose.yml b/monitor/docker-compose.yml index 8ab1060c3..fc2b75d95 100644 --- a/monitor/docker-compose.yml +++ b/monitor/docker-compose.yml @@ -11,4 +11,4 @@ services: environment: - NODE_ENV=production restart: unless-stopped - entrypoint: "yarn check-and-start" + entrypoint: "yarn start" From ad643f506f1551313eb1e62ae3826506b35d0fee Mon Sep 17 00:00:00 2001 From: Gerardo Nardelli Date: Fri, 3 Jan 2020 11:48:33 -0300 Subject: [PATCH 07/30] Rename checkDocker.sh to getBridgeStats.sh --- deployment/roles/monitor/tasks/cron.yml | 2 +- monitor/scripts/{checkDocker.sh => getBridgeStats.sh} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename monitor/scripts/{checkDocker.sh => getBridgeStats.sh} (100%) diff --git a/deployment/roles/monitor/tasks/cron.yml b/deployment/roles/monitor/tasks/cron.yml index 13322ae8b..6adcafa43 100644 --- a/deployment/roles/monitor/tasks/cron.yml +++ b/deployment/roles/monitor/tasks/cron.yml @@ -6,7 +6,7 @@ day: "{{ monitor_cron_schedule.split(' ')[2] }}" month: "{{ monitor_cron_schedule.split(' ')[3] }}" weekday: "{{ monitor_cron_schedule.split(' ')[4] }}" - job: "/bin/bash -c 'cd {{ bridge_path }}/monitor/scripts; ./checkDocker.sh >cronWorker.out 2>cronWorker.err'" + job: "/bin/bash -c 'cd {{ bridge_path }}/monitor/scripts; ./getBridgeStats.sh >cronWorker.out 2>cronWorker.err'" - name: Add cron entry cron: name: "RUN_MONITOR_CHECKS" diff --git a/monitor/scripts/checkDocker.sh b/monitor/scripts/getBridgeStats.sh similarity index 100% rename from monitor/scripts/checkDocker.sh rename to monitor/scripts/getBridgeStats.sh From dc4aefcf9216c6fa4299229a05b246a68b3fcbcf Mon Sep 17 00:00:00 2001 From: Gerardo Nardelli Date: Fri, 3 Jan 2020 15:22:57 -0300 Subject: [PATCH 08/30] Run monitor check-all for every env file --- monitor/docker-compose.yml | 2 ++ monitor/scripts/getBridgeStats.sh | 6 ++++-- monitor/utils/file.js | 8 +++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/monitor/docker-compose.yml b/monitor/docker-compose.yml index fc2b75d95..993c0903e 100644 --- a/monitor/docker-compose.yml +++ b/monitor/docker-compose.yml @@ -10,5 +10,7 @@ services: env_file: ./.env environment: - NODE_ENV=production + volumes: + - ./responses:/mono/monitor/responses restart: unless-stopped entrypoint: "yarn start" diff --git a/monitor/scripts/getBridgeStats.sh b/monitor/scripts/getBridgeStats.sh index f44c072e5..556c3b631 100755 --- a/monitor/scripts/getBridgeStats.sh +++ b/monitor/scripts/getBridgeStats.sh @@ -2,8 +2,10 @@ cd $(dirname $0)/.. if /usr/local/bin/docker-compose ps | grep -q -i 'monitor'; then - # https://github.com/docker/compose/issues/3352 - COMPOSE_INTERACTIVE_NO_CLI=1 /usr/local/bin/docker-compose exec -T monitor /bin/bash -c 'yarn check-all' + for file in configs/*.env + do + docker run --rm --env-file $file -v $(pwd)/responses:/mono/monitor/responses monitor_monitor /bin/bash -c 'yarn check-all' + done else echo "Monitor is not running, skipping checks." fi diff --git a/monitor/utils/file.js b/monitor/utils/file.js index 745bcfca5..5650a6c8c 100644 --- a/monitor/utils/file.js +++ b/monitor/utils/file.js @@ -20,7 +20,13 @@ function writeFile(filePath, object) { } function createDir(dirPath) { - fs.mkdirSync(path.join(process.cwd(), dirPath), { recursive: true }) + try { + fs.mkdirSync(path.join(process.cwd(), dirPath), { recursive: true }) + } catch (e) { + if (!e.message.includes('exists')) { + throw e + } + } } module.exports = { From 392af8bc2e956622a9246e058444bba3bd69cbe7 Mon Sep 17 00:00:00 2001 From: Gerardo Nardelli Date: Fri, 3 Jan 2020 15:52:24 -0300 Subject: [PATCH 09/30] Update monitor deployment env file --- deployment/roles/monitor/templates/.env.j2 | 23 ---------------------- 1 file changed, 23 deletions(-) diff --git a/deployment/roles/monitor/templates/.env.j2 b/deployment/roles/monitor/templates/.env.j2 index cbc258d96..3a2324284 100644 --- a/deployment/roles/monitor/templates/.env.j2 +++ b/deployment/roles/monitor/templates/.env.j2 @@ -1,24 +1 @@ -COMMON_HOME_RPC_URL={{ COMMON_HOME_RPC_URL }} -COMMON_FOREIGN_RPC_URL={{ COMMON_FOREIGN_RPC_URL }} -COMMON_HOME_BRIDGE_ADDRESS={{ COMMON_HOME_BRIDGE_ADDRESS }} -COMMON_FOREIGN_BRIDGE_ADDRESS={{ COMMON_FOREIGN_BRIDGE_ADDRESS }} -MONITOR_HOME_START_BLOCK={{ MONITOR_HOME_START_BLOCK }} -MONITOR_FOREIGN_START_BLOCK={{ MONITOR_FOREIGN_START_BLOCK }} -MONITOR_VALIDATOR_HOME_TX_LIMIT={{ MONITOR_VALIDATOR_HOME_TX_LIMIT }} -{% if COMMON_HOME_GAS_PRICE_SUPPLIER_URL | default('') != '' %} -COMMON_HOME_GAS_PRICE_SUPPLIER_URL={{ COMMON_HOME_GAS_PRICE_SUPPLIER_URL }} -{% endif %} -{% if COMMON_HOME_GAS_PRICE_SPEED_TYPE | default('') != '' %} -COMMON_HOME_GAS_PRICE_SPEED_TYPE={{ COMMON_HOME_GAS_PRICE_SPEED_TYPE }} -{% endif %} -COMMON_HOME_GAS_PRICE_FALLBACK={{ COMMON_HOME_GAS_PRICE_FALLBACK }} -{% if COMMON_HOME_GAS_PRICE_FACTOR | default('') != '' %} -COMMON_HOME_GAS_PRICE_FACTOR={{ COMMON_HOME_GAS_PRICE_FACTOR }} -{% endif %} -MONITOR_VALIDATOR_FOREIGN_TX_LIMIT={{ MONITOR_VALIDATOR_FOREIGN_TX_LIMIT }} -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_LEFT_TX_THRESHOLD={{ MONITOR_LEFT_TX_THRESHOLD }} MONITOR_PORT={{ MONITOR_PORT }} From ffeee5612574be03b28e672872fceaef6221043a Mon Sep 17 00:00:00 2001 From: Gerardo Nardelli Date: Fri, 3 Jan 2020 16:45:48 -0300 Subject: [PATCH 10/30] Copy monitor bridge config files in deployment script --- deployment/roles/monitor/tasks/pre_config.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/deployment/roles/monitor/tasks/pre_config.yml b/deployment/roles/monitor/tasks/pre_config.yml index 8fa9dc999..bc91a58de 100644 --- a/deployment/roles/monitor/tasks/pre_config.yml +++ b/deployment/roles/monitor/tasks/pre_config.yml @@ -3,3 +3,8 @@ template: src: .env.j2 dest: "{{ bridge_path }}/monitor/.env" + +- name: Copy bridge config files names + copy: + src: ../../../../monitor/configs/ + dest: "{{ bridge_path }}/monitor/configs" From 34f6fa3d2f2f2d23b3f635e59ccb7bb581abb877 Mon Sep 17 00:00:00 2001 From: Gerardo Nardelli Date: Fri, 3 Jan 2020 17:14:17 -0300 Subject: [PATCH 11/30] fix monitor deployment e2e test --- deployment-e2e/molecule/monitor/molecule.yml | 1 + deployment-e2e/molecule/monitor/tests/test_monitor.py | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/deployment-e2e/molecule/monitor/molecule.yml b/deployment-e2e/molecule/monitor/molecule.yml index 5bce0e8cb..a90fb9739 100644 --- a/deployment-e2e/molecule/monitor/molecule.yml +++ b/deployment-e2e/molecule/monitor/molecule.yml @@ -33,6 +33,7 @@ provisioner: inventory: host_vars: monitor-host: + MONITOR_BRIDGE_NAME: bridge syslog_server_port: "udp://127.0.0.1:514" verifier: name: testinfra diff --git a/deployment-e2e/molecule/monitor/tests/test_monitor.py b/deployment-e2e/molecule/monitor/tests/test_monitor.py index a3cee13dc..3dec3d21f 100644 --- a/deployment-e2e/molecule/monitor/tests/test_monitor.py +++ b/deployment-e2e/molecule/monitor/tests/test_monitor.py @@ -34,14 +34,14 @@ def test_logging(host, filename): def test_home_exists(host): assert host.run_test( - 'curl -s http://localhost:3003 | ' + 'curl -s http://localhost:3003/bridge | ' 'grep -q -i "home"' ) def test_foreign_exists(host): assert host.run_test( - 'curl -s http://localhost:3003 | ' + 'curl -s http://localhost:3003/bridge | ' 'grep -q -i "foreign"' ) @@ -49,6 +49,6 @@ def test_foreign_exists(host): def test_no_error(host): assert host.run_expect( [1], - 'curl -s http://localhost:3003 | ' + 'curl -s http://localhost:3003/bridge | ' 'grep -i -q "error"' ) From c9d6c4523a2eceaaba35cf6722c4a053ae07cda0 Mon Sep 17 00:00:00 2001 From: Gerardo Nardelli Date: Fri, 3 Jan 2020 17:18:13 -0300 Subject: [PATCH 12/30] Update env vars for monitor e2e tests --- e2e-commons/components-envs/monitor-amb.env | 1 + e2e-commons/components-envs/monitor-erc20-native.env | 1 + e2e-commons/components-envs/monitor-erc20.env | 1 + e2e-commons/components-envs/monitor.env | 1 + monitor-e2e/wait-for-monitor.sh | 2 +- 5 files changed, 5 insertions(+), 1 deletion(-) diff --git a/e2e-commons/components-envs/monitor-amb.env b/e2e-commons/components-envs/monitor-amb.env index c866ec926..52e9d6dcb 100644 --- a/e2e-commons/components-envs/monitor-amb.env +++ b/e2e-commons/components-envs/monitor-amb.env @@ -16,3 +16,4 @@ COMMON_FOREIGN_GAS_PRICE_FALLBACK=1000000000 COMMON_FOREIGN_GAS_PRICE_FACTOR=1 MONITOR_TX_NUMBER_THRESHOLD=100 MONITOR_PORT=3013 +MONITOR_BRIDGE_NAME=bridge diff --git a/e2e-commons/components-envs/monitor-erc20-native.env b/e2e-commons/components-envs/monitor-erc20-native.env index 6b5f2a2fa..1818d686a 100644 --- a/e2e-commons/components-envs/monitor-erc20-native.env +++ b/e2e-commons/components-envs/monitor-erc20-native.env @@ -16,3 +16,4 @@ COMMON_FOREIGN_GAS_PRICE_FALLBACK=1000000000 COMMON_FOREIGN_GAS_PRICE_FACTOR=1 MONITOR_TX_NUMBER_THRESHOLD=100 MONITOR_PORT=3012 +MONITOR_BRIDGE_NAME=bridge diff --git a/e2e-commons/components-envs/monitor-erc20.env b/e2e-commons/components-envs/monitor-erc20.env index 08c2c03d1..c70806882 100644 --- a/e2e-commons/components-envs/monitor-erc20.env +++ b/e2e-commons/components-envs/monitor-erc20.env @@ -16,3 +16,4 @@ COMMON_FOREIGN_GAS_PRICE_FALLBACK=1000000000 COMMON_FOREIGN_GAS_PRICE_FACTOR=1 MONITOR_TX_NUMBER_THRESHOLD=100 MONITOR_PORT=3011 +MONITOR_BRIDGE_NAME=bridge diff --git a/e2e-commons/components-envs/monitor.env b/e2e-commons/components-envs/monitor.env index 7fe412501..4974ccf5d 100644 --- a/e2e-commons/components-envs/monitor.env +++ b/e2e-commons/components-envs/monitor.env @@ -16,3 +16,4 @@ COMMON_FOREIGN_GAS_PRICE_FALLBACK=1000000000 COMMON_FOREIGN_GAS_PRICE_FACTOR=1 MONITOR_TX_NUMBER_THRESHOLD=100 MONITOR_PORT=3010 +MONITOR_BRIDGE_NAME=bridge diff --git a/monitor-e2e/wait-for-monitor.sh b/monitor-e2e/wait-for-monitor.sh index 4fd2ef7e4..bd0a775f4 100755 --- a/monitor-e2e/wait-for-monitor.sh +++ b/monitor-e2e/wait-for-monitor.sh @@ -3,7 +3,7 @@ FILES=(getBalances.json validators.json eventsStats.json alerts.json) check_files_exist() { rc=0 for f in "${FILES[@]}"; do - command="test -f responses/$f" + command="test -f responses/bridge/$f" (docker-compose -f ../e2e-commons/docker-compose.yml exec monitor /bin/bash -c "$command") || rc=1 (docker-compose -f ../e2e-commons/docker-compose.yml exec monitor-erc20 /bin/bash -c "$command") || rc=1 (docker-compose -f ../e2e-commons/docker-compose.yml exec monitor-erc20-native /bin/bash -c "$command") || rc=1 From ce72dd6b61f8b01bd54d0f0bd59720b08fce0cd0 Mon Sep 17 00:00:00 2001 From: Gerardo Nardelli Date: Mon, 6 Jan 2020 10:17:49 -0300 Subject: [PATCH 13/30] Fix monitor e2e base urls --- e2e-commons/constants.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/e2e-commons/constants.json b/e2e-commons/constants.json index 8929f4523..ae28c3397 100644 --- a/e2e-commons/constants.json +++ b/e2e-commons/constants.json @@ -20,7 +20,7 @@ "foreign": "0x2B6871b9B02F73fa24F4864322CdC78604207769", "foreignToken": "0xdbeE25CbE97e4A5CC6c499875774dc7067E9426B", "ui": "http://localhost:3000", - "monitor": "http://monitor:3010" + "monitor": "http://monitor:3010/bridge" }, "ercToErcBridge": { "home": "0x1feB40aD9420b186F019A717c37f5546165d411E", @@ -28,7 +28,7 @@ "homeToken": "0x792455a6bCb62Ed4C4362D323E0590654CA4765c", "foreignToken": "0x3C665A31199694Bf723fD08844AD290207B5797f", "ui": "http://localhost:3001", - "monitor": "http://monitor-erc20:3011" + "monitor": "http://monitor-erc20:3011/bridge" }, "ercToNativeBridge": { "home": "0x488Af810997eD1730cB3a3918cD83b3216E6eAda", @@ -37,14 +37,14 @@ "halfDuplexToken": "0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359", "saiTop": "0x9b0ccf7C8994E19F39b2B4CF708e0A7DF65fA8a3", "ui": "http://localhost:3002", - "monitor": "http://monitor-erc20-native:3012" + "monitor": "http://monitor-erc20-native:3012/bridge" }, "amb": { "home": "0x0AEe1FCD12dDFab6265F7f8956e6E012A9Fe4Aa0", "foreign": "0x0AEe1FCD12dDFab6265F7f8956e6E012A9Fe4Aa0", "homeBox": "0x6C4EaAb8756d53Bf599FFe2347FAFF1123D6C8A1", "foreignBox": "0x6C4EaAb8756d53Bf599FFe2347FAFF1123D6C8A1", - "monitor": "http://monitor-amb:3013" + "monitor": "http://monitor-amb:3013/bridge" }, "homeRPC": { "URL": "http://parity1:8545", From 5ed21f439df1f7d4cdbee5966c21cdf9ccb717e7 Mon Sep 17 00:00:00 2001 From: Gerardo Nardelli Date: Mon, 6 Jan 2020 11:29:54 -0300 Subject: [PATCH 14/30] Run monitor check job after deployment --- deployment/roles/monitor/tasks/cron.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/deployment/roles/monitor/tasks/cron.yml b/deployment/roles/monitor/tasks/cron.yml index 6adcafa43..79bc8b647 100644 --- a/deployment/roles/monitor/tasks/cron.yml +++ b/deployment/roles/monitor/tasks/cron.yml @@ -16,3 +16,6 @@ month: "{{ month }}" weekday: "{{ weekday }}" job: "{{ job }}" + +- name: Run the job to generate initial data + shell: "{{ job }}" From a205fbe87daf8b161d69b15f55a955d05b2d149b Mon Sep 17 00:00:00 2001 From: Gerardo Nardelli Date: Mon, 6 Jan 2020 12:36:38 -0300 Subject: [PATCH 15/30] Add example env for deployment-monitor e2e tests --- deployment-e2e/molecule/monitor/converge.yml | 3 +++ .../molecule/monitor/copy-bridge-env.yml | 6 +++++ deployment-e2e/molecule/monitor/molecule.yml | 4 ++-- monitor/configs/example.env.example | 24 +++++++++++++++++++ 4 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 deployment-e2e/molecule/monitor/converge.yml create mode 100644 deployment-e2e/molecule/monitor/copy-bridge-env.yml create mode 100644 monitor/configs/example.env.example diff --git a/deployment-e2e/molecule/monitor/converge.yml b/deployment-e2e/molecule/monitor/converge.yml new file mode 100644 index 000000000..5a41e3db4 --- /dev/null +++ b/deployment-e2e/molecule/monitor/converge.yml @@ -0,0 +1,3 @@ +--- +- import_playbook: ./copy-bridge-env.yml +- import_playbook: ../../../deployment/site.yml diff --git a/deployment-e2e/molecule/monitor/copy-bridge-env.yml b/deployment-e2e/molecule/monitor/copy-bridge-env.yml new file mode 100644 index 000000000..ec2ae49a3 --- /dev/null +++ b/deployment-e2e/molecule/monitor/copy-bridge-env.yml @@ -0,0 +1,6 @@ +--- +- name: Generate example env locally + copy: + src: ../../../monitor/configs/example.env.example + dest: ../../../monitor/configs/example.env + delegate_to: 127.0.0.1 diff --git a/deployment-e2e/molecule/monitor/molecule.yml b/deployment-e2e/molecule/monitor/molecule.yml index a90fb9739..8b8542d0f 100644 --- a/deployment-e2e/molecule/monitor/molecule.yml +++ b/deployment-e2e/molecule/monitor/molecule.yml @@ -29,11 +29,11 @@ provisioner: r: ["bug"] playbooks: prepare: ../prepare.yml - converge: ../../../deployment/site.yml + converge: ./converge.yml inventory: host_vars: monitor-host: - MONITOR_BRIDGE_NAME: bridge + MONITOR_PORT: 3003 syslog_server_port: "udp://127.0.0.1:514" verifier: name: testinfra diff --git a/monitor/configs/example.env.example b/monitor/configs/example.env.example new file mode 100644 index 000000000..ea5b4c631 --- /dev/null +++ b/monitor/configs/example.env.example @@ -0,0 +1,24 @@ +MONITOR_BRIDGE_NAME=bridge + +COMMON_HOME_RPC_URL=https://sokol.poa.network +COMMON_HOME_BRIDGE_ADDRESS=0x98aFdE294f1C46aA0a27Cc4049ED337F879d8976 +COMMON_FOREIGN_RPC_URL=https://sokol.poa.network +COMMON_FOREIGN_BRIDGE_ADDRESS=0x5a584f4C30B36f282848dAc9a2b20E7BEF481981 + +COMMON_HOME_GAS_PRICE_SUPPLIER_URL=https://gasprice-etc.poa.network/ +COMMON_HOME_GAS_PRICE_SPEED_TYPE=standard +COMMON_HOME_GAS_PRICE_FALLBACK=15000000000 +ORACLE_HOME_GAS_PRICE_UPDATE_INTERVAL=600000 +COMMON_HOME_GAS_PRICE_FACTOR=1 + +COMMON_FOREIGN_GAS_PRICE_SUPPLIER_URL=https://gasprice.poa.network/ +COMMON_FOREIGN_GAS_PRICE_SPEED_TYPE=standard +COMMON_FOREIGN_GAS_PRICE_FALLBACK=10000000000 +ORACLE_FOREIGN_GAS_PRICE_UPDATE_INTERVAL=600000 +COMMON_FOREIGN_GAS_PRICE_FACTOR=1 + +MONITOR_HOME_START_BLOCK=0 +MONITOR_FOREIGN_START_BLOCK=0 +MONITOR_VALIDATOR_HOME_TX_LIMIT=300000 +MONITOR_VALIDATOR_FOREIGN_TX_LIMIT=300000 +MONITOR_TX_NUMBER_THRESHOLD=100 From fe0baee39c260f0663e824d1cf93c4c2afc6ea31 Mon Sep 17 00:00:00 2001 From: Gerardo Nardelli Date: Mon, 6 Jan 2020 13:26:00 -0300 Subject: [PATCH 16/30] fix copy example env for monitor deployment e2e --- deployment-e2e/molecule/monitor/copy-bridge-env.yml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/deployment-e2e/molecule/monitor/copy-bridge-env.yml b/deployment-e2e/molecule/monitor/copy-bridge-env.yml index ec2ae49a3..79cc7ba09 100644 --- a/deployment-e2e/molecule/monitor/copy-bridge-env.yml +++ b/deployment-e2e/molecule/monitor/copy-bridge-env.yml @@ -1,6 +1,10 @@ --- - name: Generate example env locally - copy: - src: ../../../monitor/configs/example.env.example - dest: ../../../monitor/configs/example.env + hosts: monitor + become: true + tasks: + - name: copy example env + copy: + src: ../../../monitor/configs/example.env.example + dest: ../../../monitor/configs/example.env delegate_to: 127.0.0.1 From 34128a51f588da0f167965ba8b636dfd3f86b1d5 Mon Sep 17 00:00:00 2001 From: Gerardo Nardelli Date: Mon, 6 Jan 2020 15:58:39 -0300 Subject: [PATCH 17/30] Only copy env files if monitor already deployed --- deployment/roles/common/tasks/main.yml | 23 ++++++++++++++++--- deployment/roles/monitor/meta/main.yml | 2 +- deployment/roles/monitor/tasks/main.yml | 20 ++++++++++++---- deployment/roles/monitor/tasks/pre_config.yml | 1 + 4 files changed, 38 insertions(+), 8 deletions(-) diff --git a/deployment/roles/common/tasks/main.yml b/deployment/roles/common/tasks/main.yml index c3c72e96e..d78b1509c 100644 --- a/deployment/roles/common/tasks/main.yml +++ b/deployment/roles/common/tasks/main.yml @@ -1,4 +1,21 @@ --- -- include_tasks: dependencies.yml -- include_tasks: repo.yml -- include_tasks: logging.yml +- name: Check if component is already deployed + shell: "test -f {{ bridge_path }}/{{ component }}/docker-compose.yml && echo 'true'" + ignore_errors: True + register: already_deployed + when: check_deployed is defined + +- name: Set if tasks should be skipped + set_fact: skip_task="{{ already_deployed.stdout | default('false') }}" + +- name: Include dependencies tasks + include_tasks: dependencies.yml + when: skip_task != true + +- name: Include repo tasks + include_tasks: repo.yml + when: skip_task != true + +- name: Include logging tasks + include_tasks: logging.yml + when: skip_task != true diff --git a/deployment/roles/monitor/meta/main.yml b/deployment/roles/monitor/meta/main.yml index fdda41bb3..c981746d7 100644 --- a/deployment/roles/monitor/meta/main.yml +++ b/deployment/roles/monitor/meta/main.yml @@ -1,3 +1,3 @@ --- dependencies: - - role: common + - { role: common, check_deployed: true, component: 'monitor' } diff --git a/deployment/roles/monitor/tasks/main.yml b/deployment/roles/monitor/tasks/main.yml index 1b074a7dd..d34654bbb 100644 --- a/deployment/roles/monitor/tasks/main.yml +++ b/deployment/roles/monitor/tasks/main.yml @@ -1,6 +1,18 @@ --- - include_tasks: pre_config.yml -- include_tasks: logging.yml -- include_tasks: jumpbox.yml -- include_tasks: servinstall.yml -- include_tasks: cron.yml + +- name: Include logging tasks + include_tasks: logging.yml + when: skip_task != true + +- name: Include jumpbox tasks + include_tasks: jumpbox.yml + when: skip_task != true + +- name: Include servinstall tasks + include_tasks: servinstall.yml + when: skip_task != true + +- name: Include cron tasks + include_tasks: cron.yml + when: skip_task != true diff --git a/deployment/roles/monitor/tasks/pre_config.yml b/deployment/roles/monitor/tasks/pre_config.yml index bc91a58de..d632bf56e 100644 --- a/deployment/roles/monitor/tasks/pre_config.yml +++ b/deployment/roles/monitor/tasks/pre_config.yml @@ -3,6 +3,7 @@ template: src: .env.j2 dest: "{{ bridge_path }}/monitor/.env" + when: skip_task != true - name: Copy bridge config files names copy: From c473d467894f2a8872d53b6fc510f7fc9ac23599 Mon Sep 17 00:00:00 2001 From: Gerardo Nardelli Date: Mon, 6 Jan 2020 17:37:00 -0300 Subject: [PATCH 18/30] Add monitor deployment configuration docs --- deployment/CONFIGURATION.md | 12 ++++++++++ deployment/MONITOR.md | 47 +++++++++++++++++++++++++++++++++++++ monitor/README.md | 2 +- 3 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 deployment/MONITOR.md diff --git a/deployment/CONFIGURATION.md b/deployment/CONFIGURATION.md index 3239f710f..e5a0d1697 100644 --- a/deployment/CONFIGURATION.md +++ b/deployment/CONFIGURATION.md @@ -79,6 +79,18 @@ Example config for installing only UI: `cd group_vars` 2. Note the and add it to the hosts.yml configuration. For example, if a bridge file is named sokol-kovan.yml, you would change the value in hosts.yml to sokol-kovan. +## Monitor Configuration +To deploy the monitor component there are two configuration steps required: +1. Create the ansible configuration file `group_vars/.yml` with the `MONITOR_PORT` variable. + +2. Create a configuration file `*.env` in `../monitor/configs` with the rest of the environmental variables detailed in the [monitor .env example](../monitor/.env.example). The monitor supports watching several bridges at the same time by creating one `.env` files for each bridge. + +In case the monitor component is already deployed in a host, and you want to add new bridges to watch, a new `.env` file should be added in `../monitor/configs` and run the ansible playbooks again. The playbook will detect that the monitor is already deployed and will only update the `config` directory. + +## Examples + +[Deploy a monitor for multiple bridges](./MONITOR.md) + ## Administrator Configurations 1. The `group_vars/.yml` file contains the public bridge parameters. This file is prepared by administrators for each bridge. The validator only needs to add the required bridge name in the hosts.yml file to tell Ansible which file to use. diff --git a/deployment/MONITOR.md b/deployment/MONITOR.md new file mode 100644 index 000000000..ee65c0dfe --- /dev/null +++ b/deployment/MONITOR.md @@ -0,0 +1,47 @@ +## Deploy multiple bridge monitor on the same host + +If you want to deploy a monitor for different bridges, the following variable should be configured in `group_vars/.yml`: +``` +MONITOR_PORT +``` + +For example, let's say we are going to deploy a monitor for xDai bridge and for WETC bridge. + +#### Setup ansible configuration for monitor + +First we create `hosts.yml` file +```yaml +--- +new-monitor: + children: + monitor: + hosts: + : + ansible_user: ubuntu +``` +In `group_vars/new-monitor.yml` +``` +MONITOR_PORT: 3003 +``` + +Then we create a configuration file for xDai Bridge `xdai.env` in `monitor/configs`. +```bash +cp dai.env.example xdai.env +``` + +And also create a configuration file for WETC Bridge `wetc.env` in `monitor/configs`. +```bash +cp wetc.env.example wetc.env +``` + +Run the playbook to deploy the monitor +``` +ansible-playbook -i hosts.yml site.yml +``` + +##### Get Monitor results +The monitor output will be available at `http://host_ip_A:MONITOR_PORT/MONITOR_BRIDGE_NAME`. + +Given that in `xdai.env` the variable `MONITOR_BRIDGE_NAME` is set to `xdai`, the results are in the url `http://host_ip_A:3003/xdai/`. + +Similar to the xdai case, in `wetc.env` the variable `MONITOR_BRIDGE_NAME` is set to `wetc`, so the results are in the url `http://host_ip_A:3003/wetc/`. diff --git a/monitor/README.md b/monitor/README.md index 34df0febf..84410dc5c 100644 --- a/monitor/README.md +++ b/monitor/README.md @@ -126,7 +126,7 @@ Using Docker: docker-compose up -d ``` -- The application will run on `http://localhost:PORT/BRIDGE_NAME`, where `PORT` and `BRIDGE_NAME` are specified in your `.env` file. +- The application will run on `http://localhost:MONITOR_PORT/MONITOR_BRIDGE_NAME`, where `MONITOR_PORT` and `MONITOR_BRIDGE_NAME` are specified in your `.env` file. - To enabled debug logging, set `DEBUG=1` variable in `.env`. ## Check balances of contracts and validators, get unprocessed events From 551b81af5fdcdbfc53fceafefa227b5f5f0ad535 Mon Sep 17 00:00:00 2001 From: Gerardo Nardelli Date: Mon, 6 Jan 2020 17:37:26 -0300 Subject: [PATCH 19/30] remove unused variables --- deployment/group_vars/example.yml | 5 ----- deployment/group_vars/ultimate.yml | 7 ------- 2 files changed, 12 deletions(-) diff --git a/deployment/group_vars/example.yml b/deployment/group_vars/example.yml index 7f7c5a288..c66ee1ed1 100644 --- a/deployment/group_vars/example.yml +++ b/deployment/group_vars/example.yml @@ -45,8 +45,3 @@ UI_FOREIGN_GAS_PRICE_UPDATE_INTERVAL: 600000 ## Monitor MONITOR_PORT: 3003 -MONITOR_HOME_START_BLOCK: 0 -MONITOR_FOREIGN_START_BLOCK: 0 -MONITOR_VALIDATOR_HOME_TX_LIMIT: 300000 -MONITOR_VALIDATOR_FOREIGN_TX_LIMIT: 300000 -MONITOR_LEFT_TX_THRESHOLD: 100 diff --git a/deployment/group_vars/ultimate.yml b/deployment/group_vars/ultimate.yml index babb32916..50dc88ec7 100644 --- a/deployment/group_vars/ultimate.yml +++ b/deployment/group_vars/ultimate.yml @@ -40,10 +40,3 @@ UI_HOME_EXPLORER_ADDRESS_TEMPLATE: https://blockscout.com/poa/sokol/address/%s UI_FOREIGN_EXPLORER_ADDRESS_TEMPLATE: https://blockscout.com/eth/kovan/address/%s UI_HOME_GAS_PRICE_UPDATE_INTERVAL: 600000 UI_FOREIGN_GAS_PRICE_UPDATE_INTERVAL: 600000 - -#montior -MONITOR_HOME_START_BLOCK: 0 -MONITOR_FOREIGN_START_BLOCK: 0 -MONITOR_VALIDATOR_HOME_TX_LIMIT: 300000 -MONITOR_VALIDATOR_FOREIGN_TX_LIMIT: 300000 -MONITOR_LEFT_TX_THRESHOLD: 100 From 8f1b80dcd591847326fc743b45f18f44327a0cb3 Mon Sep 17 00:00:00 2001 From: Gerardo Nardelli Date: Tue, 7 Jan 2020 16:23:48 -0300 Subject: [PATCH 20/30] Update deployment/CONFIGURATION.md Co-Authored-By: Alexander Kolotov --- deployment/CONFIGURATION.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployment/CONFIGURATION.md b/deployment/CONFIGURATION.md index e5a0d1697..4870080b2 100644 --- a/deployment/CONFIGURATION.md +++ b/deployment/CONFIGURATION.md @@ -83,7 +83,7 @@ Example config for installing only UI: To deploy the monitor component there are two configuration steps required: 1. Create the ansible configuration file `group_vars/.yml` with the `MONITOR_PORT` variable. -2. Create a configuration file `*.env` in `../monitor/configs` with the rest of the environmental variables detailed in the [monitor .env example](../monitor/.env.example). The monitor supports watching several bridges at the same time by creating one `.env` files for each bridge. +2. Create a configuration file `.env` in `../monitor/configs` with the rest of the environmental variables detailed in the [monitor .env example](../monitor/.env.example). The monitor supports watching several bridges at the same time by creating one `env`-ended files for each bridge. In case the monitor component is already deployed in a host, and you want to add new bridges to watch, a new `.env` file should be added in `../monitor/configs` and run the ansible playbooks again. The playbook will detect that the monitor is already deployed and will only update the `config` directory. From bd2fd384f8e8e5e21bcdd3e5c66dc0a7a3c96be2 Mon Sep 17 00:00:00 2001 From: Gerardo Nardelli Date: Tue, 7 Jan 2020 16:24:04 -0300 Subject: [PATCH 21/30] Update deployment/CONFIGURATION.md Co-Authored-By: Alexander Kolotov --- deployment/CONFIGURATION.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployment/CONFIGURATION.md b/deployment/CONFIGURATION.md index 4870080b2..cdc66ebed 100644 --- a/deployment/CONFIGURATION.md +++ b/deployment/CONFIGURATION.md @@ -85,7 +85,7 @@ To deploy the monitor component there are two configuration steps required: 2. Create a configuration file `.env` in `../monitor/configs` with the rest of the environmental variables detailed in the [monitor .env example](../monitor/.env.example). The monitor supports watching several bridges at the same time by creating one `env`-ended files for each bridge. -In case the monitor component is already deployed in a host, and you want to add new bridges to watch, a new `.env` file should be added in `../monitor/configs` and run the ansible playbooks again. The playbook will detect that the monitor is already deployed and will only update the `config` directory. +In case the monitor component is already deployed in a host, and you want to add new bridges to watch, a new `.env` file should be added in `../monitor/configs` and run the ansible playbooks again. The playbook will detect that the monitor is already deployed and will only update the `config` directory. ## Examples From b8b351943b9ce3a578585e9395736de6f7e4e4c9 Mon Sep 17 00:00:00 2001 From: Gerardo Nardelli Date: Wed, 8 Jan 2020 10:08:23 -0300 Subject: [PATCH 22/30] Remove unused variable in monitor config examples --- monitor/configs/dai.env.example | 3 +-- monitor/configs/example.env.example | 2 -- monitor/configs/wetc.env.example | 2 -- 3 files changed, 1 insertion(+), 6 deletions(-) diff --git a/monitor/configs/dai.env.example b/monitor/configs/dai.env.example index ee03f6d8d..d6f202c69 100644 --- a/monitor/configs/dai.env.example +++ b/monitor/configs/dai.env.example @@ -9,11 +9,10 @@ COMMON_HOME_GAS_PRICE_FALLBACK= 0 COMMON_FOREIGN_GAS_PRICE_SUPPLIER_URL=https://gasprice.poa.network/ COMMON_FOREIGN_GAS_PRICE_SPEED_TYPE=standard COMMON_FOREIGN_GAS_PRICE_FALLBACK=10000000000 -ORACLE_FOREIGN_GAS_PRICE_UPDATE_INTERVAL=600000 COMMON_FOREIGN_GAS_PRICE_FACTOR=1 MONITOR_HOME_START_BLOCK=759 MONITOR_FOREIGN_START_BLOCK=6478417 -MONITOR_VALIDATOR_HOME_TX_LIMIT=300000 +MONITOR_VALIDATOR_HOME_TX_LIMIT=0 MONITOR_VALIDATOR_FOREIGN_TX_LIMIT=300000 MONITOR_TX_NUMBER_THRESHOLD=100 diff --git a/monitor/configs/example.env.example b/monitor/configs/example.env.example index ea5b4c631..3c3e06ba4 100644 --- a/monitor/configs/example.env.example +++ b/monitor/configs/example.env.example @@ -8,13 +8,11 @@ COMMON_FOREIGN_BRIDGE_ADDRESS=0x5a584f4C30B36f282848dAc9a2b20E7BEF481981 COMMON_HOME_GAS_PRICE_SUPPLIER_URL=https://gasprice-etc.poa.network/ COMMON_HOME_GAS_PRICE_SPEED_TYPE=standard COMMON_HOME_GAS_PRICE_FALLBACK=15000000000 -ORACLE_HOME_GAS_PRICE_UPDATE_INTERVAL=600000 COMMON_HOME_GAS_PRICE_FACTOR=1 COMMON_FOREIGN_GAS_PRICE_SUPPLIER_URL=https://gasprice.poa.network/ COMMON_FOREIGN_GAS_PRICE_SPEED_TYPE=standard COMMON_FOREIGN_GAS_PRICE_FALLBACK=10000000000 -ORACLE_FOREIGN_GAS_PRICE_UPDATE_INTERVAL=600000 COMMON_FOREIGN_GAS_PRICE_FACTOR=1 MONITOR_HOME_START_BLOCK=0 diff --git a/monitor/configs/wetc.env.example b/monitor/configs/wetc.env.example index 32e6bef71..3379dd8c6 100644 --- a/monitor/configs/wetc.env.example +++ b/monitor/configs/wetc.env.example @@ -8,13 +8,11 @@ COMMON_FOREIGN_BRIDGE_ADDRESS=0x0cB781EE62F815bdD9CD4c2210aE8600d43e7040 COMMON_HOME_GAS_PRICE_SUPPLIER_URL=https://gasprice-etc.poa.network/ COMMON_HOME_GAS_PRICE_SPEED_TYPE=standard COMMON_HOME_GAS_PRICE_FALLBACK=15000000000 -ORACLE_HOME_GAS_PRICE_UPDATE_INTERVAL=600000 COMMON_HOME_GAS_PRICE_FACTOR=1 COMMON_FOREIGN_GAS_PRICE_SUPPLIER_URL=https://gasprice.poa.network/ COMMON_FOREIGN_GAS_PRICE_SPEED_TYPE=standard COMMON_FOREIGN_GAS_PRICE_FALLBACK=10000000000 -ORACLE_FOREIGN_GAS_PRICE_UPDATE_INTERVAL=600000 COMMON_FOREIGN_GAS_PRICE_FACTOR=1 MONITOR_HOME_START_BLOCK=7703292 From bd004878e4e59b5ede27fe62b4beae696f4eafac Mon Sep 17 00:00:00 2001 From: Gerardo Nardelli Date: Wed, 8 Jan 2020 11:00:23 -0300 Subject: [PATCH 23/30] Increase timeout monitor e2e tests checks --- monitor-e2e/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monitor-e2e/utils.js b/monitor-e2e/utils.js index 0b26fc8d1..14361c6d8 100644 --- a/monitor-e2e/utils.js +++ b/monitor-e2e/utils.js @@ -1,7 +1,7 @@ const Web3 = require('web3') const { ERC677_BRIDGE_TOKEN_ABI, BRIDGE_VALIDATORS_ABI, FOREIGN_NATIVE_TO_ERC_ABI, BOX_ABI } = require('../commons') -const waitUntil = async (predicate, step = 100, timeout = 10000) => { +const waitUntil = async (predicate, step = 100, timeout = 20000) => { const stopTime = Date.now() + timeout while (Date.now() <= stopTime) { const result = await predicate() From d7fb9bc63e0374836e4cba13ef2887aaf1eca140 Mon Sep 17 00:00:00 2001 From: Gerardo Nardelli Date: Wed, 8 Jan 2020 11:01:09 -0300 Subject: [PATCH 24/30] Move initial data generation to monitor service --- deployment/roles/monitor/tasks/cron.yml | 3 --- deployment/roles/monitor/templates/tokenbridge-monitor.j2 | 1 + 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/deployment/roles/monitor/tasks/cron.yml b/deployment/roles/monitor/tasks/cron.yml index 79bc8b647..6adcafa43 100644 --- a/deployment/roles/monitor/tasks/cron.yml +++ b/deployment/roles/monitor/tasks/cron.yml @@ -16,6 +16,3 @@ month: "{{ month }}" weekday: "{{ weekday }}" job: "{{ job }}" - -- name: Run the job to generate initial data - shell: "{{ job }}" diff --git a/deployment/roles/monitor/templates/tokenbridge-monitor.j2 b/deployment/roles/monitor/templates/tokenbridge-monitor.j2 index 8f3fe8b25..7ff4b6889 100644 --- a/deployment/roles/monitor/templates/tokenbridge-monitor.j2 +++ b/deployment/roles/monitor/templates/tokenbridge-monitor.j2 @@ -18,6 +18,7 @@ start(){ sudo -u "{{ compose_service_user }}" /usr/local/bin/docker-compose down -v sudo -u "{{ compose_service_user }}" /usr/local/bin/docker-compose rm -fv sudo -u "{{ compose_service_user }}" /usr/local/bin/docker-compose up --detach + sudo -u "{{ compose_service_user }}" /bin/bash -c 'cd scripts; ./getBridgeStats.sh >cronWorker.out 2>cronWorker.err' } stop(){ From 033201dc9cdb0ffadee9787ceaf02495b932323e Mon Sep 17 00:00:00 2001 From: Gerardo Nardelli Date: Wed, 8 Jan 2020 11:35:34 -0300 Subject: [PATCH 25/30] Run checks in monitor deployment e2e test --- deployment-e2e/molecule/monitor/converge.yml | 1 + deployment-e2e/molecule/monitor/run-checks.yml | 7 +++++++ 2 files changed, 8 insertions(+) create mode 100644 deployment-e2e/molecule/monitor/run-checks.yml diff --git a/deployment-e2e/molecule/monitor/converge.yml b/deployment-e2e/molecule/monitor/converge.yml index 5a41e3db4..89bd5e2ea 100644 --- a/deployment-e2e/molecule/monitor/converge.yml +++ b/deployment-e2e/molecule/monitor/converge.yml @@ -1,3 +1,4 @@ --- - import_playbook: ./copy-bridge-env.yml - import_playbook: ../../../deployment/site.yml +- import_playbook: ./run-checks.yml diff --git a/deployment-e2e/molecule/monitor/run-checks.yml b/deployment-e2e/molecule/monitor/run-checks.yml new file mode 100644 index 000000000..f1519ba73 --- /dev/null +++ b/deployment-e2e/molecule/monitor/run-checks.yml @@ -0,0 +1,7 @@ +--- +- name: Generate initial data for monitor + hosts: monitor + become: true + tasks: + - name: Run monitor checks + shell: /bin/bash -c 'cd {{ bridge_path }}/monitor/scripts; ./getBridgeStats.sh >cronWorker.out 2>cronWorker.err' From 1c7883750a23d966394b0a87c2f21285f57a06b8 Mon Sep 17 00:00:00 2001 From: Gerardo Nardelli Date: Wed, 8 Jan 2020 11:43:54 -0300 Subject: [PATCH 26/30] fix path --- deployment-e2e/molecule/monitor/run-checks.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployment-e2e/molecule/monitor/run-checks.yml b/deployment-e2e/molecule/monitor/run-checks.yml index f1519ba73..5fd197b8f 100644 --- a/deployment-e2e/molecule/monitor/run-checks.yml +++ b/deployment-e2e/molecule/monitor/run-checks.yml @@ -4,4 +4,4 @@ become: true tasks: - name: Run monitor checks - shell: /bin/bash -c 'cd {{ bridge_path }}/monitor/scripts; ./getBridgeStats.sh >cronWorker.out 2>cronWorker.err' + shell: /bin/bash -c 'cd /home/poadocker/bridge/monitor/scripts; ./getBridgeStats.sh >cronWorker.out 2>cronWorker.err' From 67132fd866fb9f941590bac675ace3938fc1fd21 Mon Sep 17 00:00:00 2001 From: Gerardo Nardelli Date: Wed, 8 Jan 2020 12:02:25 -0300 Subject: [PATCH 27/30] Update monitor error message --- monitor/utils/file.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monitor/utils/file.js b/monitor/utils/file.js index 5650a6c8c..a3e5c9946 100644 --- a/monitor/utils/file.js +++ b/monitor/utils/file.js @@ -10,7 +10,7 @@ async function readFile(filePath) { } catch (e) { console.error(e) return { - error: 'please check your worker' + error: 'the bridge statistics are not available' } } } From cab446162a99d2774241b1acf81b2358d1a9ceac Mon Sep 17 00:00:00 2001 From: Gerardo Nardelli Date: Thu, 9 Jan 2020 14:33:42 -0300 Subject: [PATCH 28/30] Create monitor config from group_vars variables in deployment playbooks --- deployment-e2e/molecule/monitor/converge.yml | 1 - .../molecule/monitor/copy-bridge-env.yml | 10 ------ deployment/group_vars/dai.yml | 1 + deployment/group_vars/example.yml | 6 ++++ deployment/group_vars/ultimate.yml | 8 +++++ deployment/group_vars/wetc.yml | 1 + deployment/roles/monitor/tasks/pre_config.yml | 8 ++--- .../roles/monitor/templates/config.env.j2 | 34 +++++++++++++++++++ monitor/configs/.gitkeep | 0 monitor/configs/dai.env.example | 18 ---------- monitor/configs/example.env.example | 22 ------------ monitor/configs/wetc.env.example | 22 ------------ 12 files changed, 54 insertions(+), 77 deletions(-) delete mode 100644 deployment-e2e/molecule/monitor/copy-bridge-env.yml create mode 100644 deployment/roles/monitor/templates/config.env.j2 create mode 100644 monitor/configs/.gitkeep delete mode 100644 monitor/configs/dai.env.example delete mode 100644 monitor/configs/example.env.example delete mode 100644 monitor/configs/wetc.env.example diff --git a/deployment-e2e/molecule/monitor/converge.yml b/deployment-e2e/molecule/monitor/converge.yml index 89bd5e2ea..5e78c8b3b 100644 --- a/deployment-e2e/molecule/monitor/converge.yml +++ b/deployment-e2e/molecule/monitor/converge.yml @@ -1,4 +1,3 @@ --- -- import_playbook: ./copy-bridge-env.yml - import_playbook: ../../../deployment/site.yml - import_playbook: ./run-checks.yml diff --git a/deployment-e2e/molecule/monitor/copy-bridge-env.yml b/deployment-e2e/molecule/monitor/copy-bridge-env.yml deleted file mode 100644 index 79cc7ba09..000000000 --- a/deployment-e2e/molecule/monitor/copy-bridge-env.yml +++ /dev/null @@ -1,10 +0,0 @@ ---- -- name: Generate example env locally - hosts: monitor - become: true - tasks: - - name: copy example env - copy: - src: ../../../monitor/configs/example.env.example - dest: ../../../monitor/configs/example.env - delegate_to: 127.0.0.1 diff --git a/deployment/group_vars/dai.yml b/deployment/group_vars/dai.yml index 7c0d4167d..7ad19673e 100644 --- a/deployment/group_vars/dai.yml +++ b/deployment/group_vars/dai.yml @@ -42,6 +42,7 @@ UI_HOME_GAS_PRICE_UPDATE_INTERVAL: 600000 UI_FOREIGN_GAS_PRICE_UPDATE_INTERVAL: 600000 ## Monitor +MONITOR_BRIDGE_NAME: "xdai" MONITOR_PORT: 3003 MONITOR_HOME_START_BLOCK: 759 MONITOR_FOREIGN_START_BLOCK: 6478417 diff --git a/deployment/group_vars/example.yml b/deployment/group_vars/example.yml index c66ee1ed1..cff9e687b 100644 --- a/deployment/group_vars/example.yml +++ b/deployment/group_vars/example.yml @@ -44,4 +44,10 @@ UI_HOME_GAS_PRICE_UPDATE_INTERVAL: 600000 UI_FOREIGN_GAS_PRICE_UPDATE_INTERVAL: 600000 ## Monitor +MONITOR_BRIDGE_NAME: "bridge" MONITOR_PORT: 3003 +MONITOR_HOME_START_BLOCK: 0 +MONITOR_FOREIGN_START_BLOCK: 0 +MONITOR_VALIDATOR_HOME_TX_LIMIT: 300000 +MONITOR_VALIDATOR_FOREIGN_TX_LIMIT: 300000 +MONITOR_LEFT_TX_THRESHOLD: 100 diff --git a/deployment/group_vars/ultimate.yml b/deployment/group_vars/ultimate.yml index 50dc88ec7..6ec3909c8 100644 --- a/deployment/group_vars/ultimate.yml +++ b/deployment/group_vars/ultimate.yml @@ -40,3 +40,11 @@ UI_HOME_EXPLORER_ADDRESS_TEMPLATE: https://blockscout.com/poa/sokol/address/%s UI_FOREIGN_EXPLORER_ADDRESS_TEMPLATE: https://blockscout.com/eth/kovan/address/%s UI_HOME_GAS_PRICE_UPDATE_INTERVAL: 600000 UI_FOREIGN_GAS_PRICE_UPDATE_INTERVAL: 600000 + +#monitor +MONITOR_BRIDGE_NAME: "bridge" +MONITOR_HOME_START_BLOCK: 0 +MONITOR_FOREIGN_START_BLOCK: 0 +MONITOR_VALIDATOR_HOME_TX_LIMIT: 300000 +MONITOR_VALIDATOR_FOREIGN_TX_LIMIT: 300000 +MONITOR_LEFT_TX_THRESHOLD: 100 diff --git a/deployment/group_vars/wetc.yml b/deployment/group_vars/wetc.yml index 1ef29d826..5e457ace1 100644 --- a/deployment/group_vars/wetc.yml +++ b/deployment/group_vars/wetc.yml @@ -43,6 +43,7 @@ UI_HOME_GAS_PRICE_UPDATE_INTERVAL: 600000 UI_FOREIGN_GAS_PRICE_UPDATE_INTERVAL: 600000 ## Monitor +MONITOR_BRIDGE_NAME: "wetc" MONITOR_PORT: 3003 MONITOR_HOME_START_BLOCK: 7703292 MONITOR_FOREIGN_START_BLOCK: 7412459 diff --git a/deployment/roles/monitor/tasks/pre_config.yml b/deployment/roles/monitor/tasks/pre_config.yml index d632bf56e..cc76e62bd 100644 --- a/deployment/roles/monitor/tasks/pre_config.yml +++ b/deployment/roles/monitor/tasks/pre_config.yml @@ -5,7 +5,7 @@ dest: "{{ bridge_path }}/monitor/.env" when: skip_task != true -- name: Copy bridge config files names - copy: - src: ../../../../monitor/configs/ - dest: "{{ bridge_path }}/monitor/configs" +- name: Install bridge config env + template: + src: config.env.j2 + dest: "{{ bridge_path }}/monitor/configs/{{ MONITOR_BRIDGE_NAME }}.env" diff --git a/deployment/roles/monitor/templates/config.env.j2 b/deployment/roles/monitor/templates/config.env.j2 new file mode 100644 index 000000000..b6c4e43c6 --- /dev/null +++ b/deployment/roles/monitor/templates/config.env.j2 @@ -0,0 +1,34 @@ +MONITOR_BRIDGE_NAME={{ MONITOR_BRIDGE_NAME }} + +COMMON_HOME_RPC_URL={{ COMMON_HOME_RPC_URL }} +COMMON_HOME_BRIDGE_ADDRESS={{ COMMON_HOME_BRIDGE_ADDRESS }} +COMMON_FOREIGN_RPC_URL={{ COMMON_FOREIGN_RPC_URL }} +COMMON_FOREIGN_BRIDGE_ADDRESS={{ COMMON_FOREIGN_BRIDGE_ADDRESS }} + +{% if COMMON_HOME_GAS_PRICE_SUPPLIER_URL | default('') != '' %} +COMMON_HOME_GAS_PRICE_SUPPLIER_URL={{ COMMON_HOME_GAS_PRICE_SUPPLIER_URL }} +{% endif %} +{% if COMMON_HOME_GAS_PRICE_SPEED_TYPE | default('') != '' %} +COMMON_HOME_GAS_PRICE_SPEED_TYPE={{ COMMON_HOME_GAS_PRICE_SPEED_TYPE }} +{% endif %} +COMMON_HOME_GAS_PRICE_FALLBACK={{ COMMON_HOME_GAS_PRICE_FALLBACK }} +{% if COMMON_HOME_GAS_PRICE_FACTOR | default('') != '' %} +COMMON_HOME_GAS_PRICE_FACTOR={{ COMMON_HOME_GAS_PRICE_FACTOR }} +{% endif %} + +{% if COMMON_FOREIGN_GAS_PRICE_SUPPLIER_URL | default('') != '' %} +COMMON_FOREIGN_GAS_PRICE_SUPPLIER_URL={{ COMMON_FOREIGN_GAS_PRICE_SUPPLIER_URL }} +{% endif %} +{% if COMMON_FOREIGN_GAS_PRICE_SPEED_TYPE | default('') != '' %} +COMMON_FOREIGN_GAS_PRICE_SPEED_TYPE={{ COMMON_FOREIGN_GAS_PRICE_SPEED_TYPE }} +{% endif %} +COMMON_FOREIGN_GAS_PRICE_FALLBACK={{ COMMON_FOREIGN_GAS_PRICE_FALLBACK }} +{% if COMMON_FOREIGN_GAS_PRICE_FACTOR | default('') != '' %} +COMMON_FOREIGN_GAS_PRICE_FACTOR={{ COMMON_FOREIGN_GAS_PRICE_FACTOR }} +{% endif %} + +MONITOR_HOME_START_BLOCK={{ MONITOR_HOME_START_BLOCK }} +MONITOR_FOREIGN_START_BLOCK={{ MONITOR_FOREIGN_START_BLOCK }} +MONITOR_VALIDATOR_HOME_TX_LIMIT={{ MONITOR_VALIDATOR_HOME_TX_LIMIT }} +MONITOR_VALIDATOR_FOREIGN_TX_LIMIT={{ MONITOR_VALIDATOR_FOREIGN_TX_LIMIT }} +MONITOR_TX_NUMBER_THRESHOLD={{ MONITOR_TX_NUMBER_THRESHOLD }} diff --git a/monitor/configs/.gitkeep b/monitor/configs/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/monitor/configs/dai.env.example b/monitor/configs/dai.env.example deleted file mode 100644 index d6f202c69..000000000 --- a/monitor/configs/dai.env.example +++ /dev/null @@ -1,18 +0,0 @@ -MONITOR_BRIDGE_NAME=xdai - -COMMON_HOME_RPC_URL=https://dai.poa.network -COMMON_HOME_BRIDGE_ADDRESS=0x7301CFA0e1756B71869E93d4e4Dca5c7d0eb0AA6 -COMMON_FOREIGN_RPC_URL=https://mainnet.infura.io/v3/ -COMMON_FOREIGN_BRIDGE_ADDRESS=0x4aa42145Aa6Ebf72e164C9bBC74fbD3788045016 - -COMMON_HOME_GAS_PRICE_FALLBACK= 0 -COMMON_FOREIGN_GAS_PRICE_SUPPLIER_URL=https://gasprice.poa.network/ -COMMON_FOREIGN_GAS_PRICE_SPEED_TYPE=standard -COMMON_FOREIGN_GAS_PRICE_FALLBACK=10000000000 -COMMON_FOREIGN_GAS_PRICE_FACTOR=1 - -MONITOR_HOME_START_BLOCK=759 -MONITOR_FOREIGN_START_BLOCK=6478417 -MONITOR_VALIDATOR_HOME_TX_LIMIT=0 -MONITOR_VALIDATOR_FOREIGN_TX_LIMIT=300000 -MONITOR_TX_NUMBER_THRESHOLD=100 diff --git a/monitor/configs/example.env.example b/monitor/configs/example.env.example deleted file mode 100644 index 3c3e06ba4..000000000 --- a/monitor/configs/example.env.example +++ /dev/null @@ -1,22 +0,0 @@ -MONITOR_BRIDGE_NAME=bridge - -COMMON_HOME_RPC_URL=https://sokol.poa.network -COMMON_HOME_BRIDGE_ADDRESS=0x98aFdE294f1C46aA0a27Cc4049ED337F879d8976 -COMMON_FOREIGN_RPC_URL=https://sokol.poa.network -COMMON_FOREIGN_BRIDGE_ADDRESS=0x5a584f4C30B36f282848dAc9a2b20E7BEF481981 - -COMMON_HOME_GAS_PRICE_SUPPLIER_URL=https://gasprice-etc.poa.network/ -COMMON_HOME_GAS_PRICE_SPEED_TYPE=standard -COMMON_HOME_GAS_PRICE_FALLBACK=15000000000 -COMMON_HOME_GAS_PRICE_FACTOR=1 - -COMMON_FOREIGN_GAS_PRICE_SUPPLIER_URL=https://gasprice.poa.network/ -COMMON_FOREIGN_GAS_PRICE_SPEED_TYPE=standard -COMMON_FOREIGN_GAS_PRICE_FALLBACK=10000000000 -COMMON_FOREIGN_GAS_PRICE_FACTOR=1 - -MONITOR_HOME_START_BLOCK=0 -MONITOR_FOREIGN_START_BLOCK=0 -MONITOR_VALIDATOR_HOME_TX_LIMIT=300000 -MONITOR_VALIDATOR_FOREIGN_TX_LIMIT=300000 -MONITOR_TX_NUMBER_THRESHOLD=100 diff --git a/monitor/configs/wetc.env.example b/monitor/configs/wetc.env.example deleted file mode 100644 index 3379dd8c6..000000000 --- a/monitor/configs/wetc.env.example +++ /dev/null @@ -1,22 +0,0 @@ -MONITOR_BRIDGE_NAME=wetc - -COMMON_HOME_RPC_URL=https://ethereumclassic.network -COMMON_HOME_BRIDGE_ADDRESS=0x073081832B4Ecdce79d4D6753565c85Ba4b3BeA9 -COMMON_FOREIGN_RPC_URL=https://mainnet.infura.io/v3/ -COMMON_FOREIGN_BRIDGE_ADDRESS=0x0cB781EE62F815bdD9CD4c2210aE8600d43e7040 - -COMMON_HOME_GAS_PRICE_SUPPLIER_URL=https://gasprice-etc.poa.network/ -COMMON_HOME_GAS_PRICE_SPEED_TYPE=standard -COMMON_HOME_GAS_PRICE_FALLBACK=15000000000 -COMMON_HOME_GAS_PRICE_FACTOR=1 - -COMMON_FOREIGN_GAS_PRICE_SUPPLIER_URL=https://gasprice.poa.network/ -COMMON_FOREIGN_GAS_PRICE_SPEED_TYPE=standard -COMMON_FOREIGN_GAS_PRICE_FALLBACK=10000000000 -COMMON_FOREIGN_GAS_PRICE_FACTOR=1 - -MONITOR_HOME_START_BLOCK=7703292 -MONITOR_FOREIGN_START_BLOCK=7412459 -MONITOR_VALIDATOR_HOME_TX_LIMIT=300000 -MONITOR_VALIDATOR_FOREIGN_TX_LIMIT=300000 -MONITOR_TX_NUMBER_THRESHOLD=100 From d865fd35e40b90816492a805dbd782e979838f25 Mon Sep 17 00:00:00 2001 From: Gerardo Nardelli Date: Thu, 9 Jan 2020 14:44:29 -0300 Subject: [PATCH 29/30] Update monitor deployment docs --- deployment/CONFIGURATION.md | 8 ---- deployment/MONITOR.md | 87 ++++++++++++++++++++++++++++++------- 2 files changed, 72 insertions(+), 23 deletions(-) diff --git a/deployment/CONFIGURATION.md b/deployment/CONFIGURATION.md index cdc66ebed..583bdef18 100644 --- a/deployment/CONFIGURATION.md +++ b/deployment/CONFIGURATION.md @@ -78,14 +78,6 @@ Example config for installing only UI: 1. Go to the group_vars folder. `cd group_vars` 2. Note the and add it to the hosts.yml configuration. For example, if a bridge file is named sokol-kovan.yml, you would change the value in hosts.yml to sokol-kovan. - -## Monitor Configuration -To deploy the monitor component there are two configuration steps required: -1. Create the ansible configuration file `group_vars/.yml` with the `MONITOR_PORT` variable. - -2. Create a configuration file `.env` in `../monitor/configs` with the rest of the environmental variables detailed in the [monitor .env example](../monitor/.env.example). The monitor supports watching several bridges at the same time by creating one `env`-ended files for each bridge. - -In case the monitor component is already deployed in a host, and you want to add new bridges to watch, a new `.env` file should be added in `../monitor/configs` and run the ansible playbooks again. The playbook will detect that the monitor is already deployed and will only update the `config` directory. ## Examples diff --git a/deployment/MONITOR.md b/deployment/MONITOR.md index ee65c0dfe..c5fd78247 100644 --- a/deployment/MONITOR.md +++ b/deployment/MONITOR.md @@ -1,44 +1,101 @@ ## Deploy multiple bridge monitor on the same host -If you want to deploy a monitor for different bridges, the following variable should be configured in `group_vars/.yml`: -``` -MONITOR_PORT -``` +If you want to deploy a monitor for different bridges, the [monitor variables](../monitor/.env.example) should be configured in `group_vars/.yml` for each bridge. For example, let's say we are going to deploy a monitor for xDai bridge and for WETC bridge. -#### Setup ansible configuration for monitor +#### Setup ansible configuration for xDai Bridge -First we create `hosts.yml` file +First we create `hosts.yml` file to deploy the monitor for xdai bridge ```yaml --- -new-monitor: +xdai: children: monitor: hosts: : ansible_user: ubuntu ``` -In `group_vars/new-monitor.yml` +In `group_vars/xdai.yml` ``` +--- +MONITOR_BRIDGE_NAME: "xdai" MONITOR_PORT: 3003 + +COMMON_HOME_RPC_URL: "https://dai.poa.network" +COMMON_HOME_BRIDGE_ADDRESS: "0x7301CFA0e1756B71869E93d4e4Dca5c7d0eb0AA6" +COMMON_FOREIGN_RPC_URL: "https://mainnet.infura.io/v3/INFURA_KEY" +COMMON_FOREIGN_BRIDGE_ADDRESS: "0x4aa42145Aa6Ebf72e164C9bBC74fbD3788045016" + +COMMON_HOME_GAS_PRICE_FALLBACK: 0 +COMMON_FOREIGN_GAS_PRICE_SUPPLIER_URL: "https://gasprice.poa.network/" +COMMON_FOREIGN_GAS_PRICE_SPEED_TYPE: "standard" +COMMON_FOREIGN_GAS_PRICE_FALLBACK: 10000000000 +COMMON_FOREIGN_GAS_PRICE_FACTOR: 1 + +MONITOR_HOME_START_BLOCK: 759 +MONITOR_FOREIGN_START_BLOCK: 6478417 +MONITOR_VALIDATOR_HOME_TX_LIMIT: 0 +MONITOR_VALIDATOR_FOREIGN_TX_LIMIT: 300000 +MONITOR_TX_NUMBER_THRESHOLD: 100 +``` + +Run the playbook to deploy the monitor for xdai bridge +``` +ansible-playbook -i hosts.yml site.yml +``` + +This command will deploy the monitor component and enable statistics for xdai bridge. + +#### Setup ansible configuration for WETC Bridge + +Update `hosts.yml` file to deploy the monitor for WETC Bridge +```yaml +--- +wetc: + children: + monitor: + hosts: + : + ansible_user: ubuntu ``` -Then we create a configuration file for xDai Bridge `xdai.env` in `monitor/configs`. -```bash -cp dai.env.example xdai.env +In `group_vars/wetc.yml` ``` +--- +MONITOR_BRIDGE_NAME: "wetc" + +COMMON_HOME_RPC_URL: "https://ethereumclassic.network" +COMMON_HOME_BRIDGE_ADDRESS: "0x073081832B4Ecdce79d4D6753565c85Ba4b3BeA9" +COMMON_FOREIGN_RPC_URL: "https://mainnet.infura.io/v3/32e8e252699a4ac1b5dd5c1ef53cc301" +COMMON_FOREIGN_BRIDGE_ADDRESS: "0x0cB781EE62F815bdD9CD4c2210aE8600d43e7040" -And also create a configuration file for WETC Bridge `wetc.env` in `monitor/configs`. -```bash -cp wetc.env.example wetc.env +COMMON_HOME_GAS_PRICE_SUPPLIER_URL: "https://gasprice-etc.poa.network/" +COMMON_HOME_GAS_PRICE_SPEED_TYPE: "standard" +COMMON_HOME_GAS_PRICE_FALLBACK: 15000000000 +COMMON_HOME_GAS_PRICE_FACTOR: 1 + +COMMON_FOREIGN_GAS_PRICE_SUPPLIER_URL: "https://gasprice.poa.network/" +COMMON_FOREIGN_GAS_PRICE_SPEED_TYPE: "standard" +COMMON_FOREIGN_GAS_PRICE_FALLBACK: 10000000000 +ORACLE_FOREIGN_GAS_PRICE_UPDATE_INTERVAL: 600000 +COMMON_FOREIGN_GAS_PRICE_FACTOR: 1 + +MONITOR_HOME_START_BLOCK: 7703292 +MONITOR_FOREIGN_START_BLOCK: 7412459 +MONITOR_VALIDATOR_HOME_TX_LIMIT: 300000 +MONITOR_VALIDATOR_FOREIGN_TX_LIMIT: 300000 +MONITOR_TX_NUMBER_THRESHOLD: 100 ``` +Given that there is a monitor component deployed in the system, the `MONITOR_PORT` variable is not needed. -Run the playbook to deploy the monitor +Run the playbook to deploy the monitor for WETC Bridge ``` ansible-playbook -i hosts.yml site.yml ``` +They playbook will detect that the monitor component is already deployed in the system, so it will only generate the configuration needed to enable the WETC Bridge statistics. + ##### Get Monitor results The monitor output will be available at `http://host_ip_A:MONITOR_PORT/MONITOR_BRIDGE_NAME`. From 3e103293796c187a4abc4060c96cd3db3e8178a0 Mon Sep 17 00:00:00 2001 From: Gerardo Nardelli Date: Thu, 9 Jan 2020 14:50:07 -0300 Subject: [PATCH 30/30] Fix env var names --- deployment/group_vars/example.yml | 2 +- deployment/group_vars/ultimate.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/deployment/group_vars/example.yml b/deployment/group_vars/example.yml index cff9e687b..4787e8934 100644 --- a/deployment/group_vars/example.yml +++ b/deployment/group_vars/example.yml @@ -50,4 +50,4 @@ MONITOR_HOME_START_BLOCK: 0 MONITOR_FOREIGN_START_BLOCK: 0 MONITOR_VALIDATOR_HOME_TX_LIMIT: 300000 MONITOR_VALIDATOR_FOREIGN_TX_LIMIT: 300000 -MONITOR_LEFT_TX_THRESHOLD: 100 +MONITOR_TX_NUMBER_THRESHOLD: 100 diff --git a/deployment/group_vars/ultimate.yml b/deployment/group_vars/ultimate.yml index 6ec3909c8..4bc94056a 100644 --- a/deployment/group_vars/ultimate.yml +++ b/deployment/group_vars/ultimate.yml @@ -47,4 +47,4 @@ MONITOR_HOME_START_BLOCK: 0 MONITOR_FOREIGN_START_BLOCK: 0 MONITOR_VALIDATOR_HOME_TX_LIMIT: 300000 MONITOR_VALIDATOR_FOREIGN_TX_LIMIT: 300000 -MONITOR_LEFT_TX_THRESHOLD: 100 +MONITOR_TX_NUMBER_THRESHOLD: 100