Support amb events info in monitor

This commit is contained in:
Gerardo Nardelli 2019-07-25 11:30:59 -03:00
parent 3d0f68fad9
commit 751b885f73
4 changed files with 113 additions and 23 deletions

@ -3,6 +3,8 @@ const Web3 = require('web3')
const logger = require('./logger')('alerts') const logger = require('./logger')('alerts')
const eventsInfo = require('./utils/events') const eventsInfo = require('./utils/events')
const { getBlockNumber } = require('./utils/contract') const { getBlockNumber } = require('./utils/contract')
const { processedMsgNotDelivered } = require('./utils/message')
const { BRIDGE_MODES } = require('../commons')
const { HOME_RPC_URL, FOREIGN_RPC_URL } = process.env const { HOME_RPC_URL, FOREIGN_RPC_URL } = process.env
@ -13,10 +15,23 @@ const foreignProvider = new Web3.providers.HttpProvider(FOREIGN_RPC_URL)
const web3Foreign = new Web3(foreignProvider) const web3Foreign = new Web3(foreignProvider)
async function main() { async function main() {
const { foreignDeposits, homeDeposits, homeWithdrawals, foreignWithdrawals } = await eventsInfo() const {
foreignDeposits,
homeDeposits,
homeWithdrawals,
foreignWithdrawals,
bridgeMode
} = await eventsInfo()
const xSignatures = foreignDeposits.filter(findDifferences(homeDeposits)) let xSignatures
const xAffirmations = homeWithdrawals.filter(findDifferences(foreignWithdrawals)) let xAffirmations
if (bridgeMode === BRIDGE_MODES.ARBITRARY_MESSAGE) {
xSignatures = foreignDeposits.filter(processedMsgNotDelivered(homeDeposits))
xAffirmations = homeWithdrawals.filter(processedMsgNotDelivered(foreignWithdrawals))
} else {
xSignatures = foreignDeposits.filter(findDifferences(homeDeposits))
xAffirmations = homeWithdrawals.filter(findDifferences(foreignWithdrawals))
}
logger.debug('building misbehavior blocks') logger.debug('building misbehavior blocks')
const [homeBlockNumber, foreignBlockNumber] = await getBlockNumber(web3Home, web3Foreign) const [homeBlockNumber, foreignBlockNumber] = await getBlockNumber(web3Home, web3Foreign)

@ -1,6 +1,7 @@
require('dotenv').config() require('dotenv').config()
const logger = require('./logger')('eventsStats')
const eventsInfo = require('./utils/events') const eventsInfo = require('./utils/events')
const { processedMsgNotDelivered, deliveredMsgNotProcessed } = require('./utils/message')
const { BRIDGE_MODES } = require('../commons')
function compareDepositsHome(foreign) { function compareDepositsHome(foreign) {
return homeDeposit => { return homeDeposit => {
@ -62,28 +63,50 @@ async function main() {
homeDeposits, homeDeposits,
homeWithdrawals, homeWithdrawals,
foreignWithdrawals, foreignWithdrawals,
isExternalErc20 isExternalErc20,
bridgeMode
} = await eventsInfo() } = await eventsInfo()
const onlyInHomeDeposits = homeDeposits.filter(compareDepositsHome(foreignDeposits)) if (bridgeMode === BRIDGE_MODES.ARBITRARY_MESSAGE) {
const onlyInForeignDeposits = foreignDeposits return {
.concat([]) home: {
.filter(compareDepositsForeign(homeDeposits)) deliveredMsgNotProcessedInForeign: homeDeposits.filter(
deliveredMsgNotProcessed(foreignDeposits)
),
processedMsgNotDeliveredInForeign: homeWithdrawals.filter(
processedMsgNotDelivered(foreignWithdrawals)
)
},
foreign: {
deliveredMsgNotProcessedInHome: foreignWithdrawals.filter(
deliveredMsgNotProcessed(homeWithdrawals)
),
processedMsgNotDeliveredInHome: foreignDeposits.filter(
processedMsgNotDelivered(homeDeposits)
)
},
lastChecked: Math.floor(Date.now() / 1000)
}
} else {
const onlyInHomeDeposits = homeDeposits.filter(compareDepositsHome(foreignDeposits))
const onlyInForeignDeposits = foreignDeposits
.concat([])
.filter(compareDepositsForeign(homeDeposits))
const onlyInHomeWithdrawals = isExternalErc20 const onlyInHomeWithdrawals = isExternalErc20
? homeWithdrawals.filter(compareTransferHome(foreignWithdrawals)) ? homeWithdrawals.filter(compareTransferHome(foreignWithdrawals))
: homeWithdrawals.filter(compareDepositsForeign(foreignWithdrawals)) : homeWithdrawals.filter(compareDepositsForeign(foreignWithdrawals))
const onlyInForeignWithdrawals = isExternalErc20 const onlyInForeignWithdrawals = isExternalErc20
? foreignWithdrawals.filter(compareTransferForeign(homeWithdrawals)) ? foreignWithdrawals.filter(compareTransferForeign(homeWithdrawals))
: foreignWithdrawals.filter(compareDepositsHome(homeWithdrawals)) : foreignWithdrawals.filter(compareDepositsHome(homeWithdrawals))
logger.debug('Done') return {
return { onlyInHomeDeposits,
onlyInHomeDeposits, onlyInForeignDeposits,
onlyInForeignDeposits, onlyInHomeWithdrawals,
onlyInHomeWithdrawals, onlyInForeignWithdrawals,
onlyInForeignWithdrawals, lastChecked: Math.floor(Date.now() / 1000)
lastChecked: Math.floor(Date.now() / 1000) }
} }
} }

@ -96,7 +96,8 @@ async function main(mode) {
foreignDeposits, foreignDeposits,
homeWithdrawals, homeWithdrawals,
foreignWithdrawals, foreignWithdrawals,
isExternalErc20 isExternalErc20,
bridgeMode
} }
} }

51
monitor/utils/message.js Normal file

@ -0,0 +1,51 @@
const web3Utils = require('web3').utils
const { addTxHashToData, parseAMBMessage } = require('../../oracle/src/utils/message')
function deliveredMsgNotProcessed(processedList) {
return deliveredMsg => {
const msg = parseAMBMessage(
addTxHashToData({
encodedData: deliveredMsg.returnValues.encodedData,
transactionHash: deliveredMsg.transactionHash
})
)
return (
processedList.filter(processedMsg => {
processedMsg.returnValues.txHash =
processedMsg.returnValues.transactionHash || processedMsg.returnValues.txHash
return messagesEquals(msg, processedMsg.returnValues)
}).length === 0
)
}
}
function processedMsgNotDelivered(deliveredList) {
return processedMsg => {
processedMsg.returnValues.txHash =
processedMsg.returnValues.transactionHash || processedMsg.returnValues.txHash
return (
deliveredList.filter(deliveredMsg => {
const msg = parseAMBMessage(
addTxHashToData({
encodedData: deliveredMsg.returnValues.encodedData,
transactionHash: deliveredMsg.transactionHash
})
)
return messagesEquals(msg, processedMsg.returnValues)
}).length === 0
)
}
}
function messagesEquals(a, b) {
return (
web3Utils.toChecksumAddress(a.sender) === b.sender &&
web3Utils.toChecksumAddress(a.executor) === b.executor &&
a.txHash === b.txHash
)
}
module.exports = {
deliveredMsgNotProcessed,
processedMsgNotDelivered
}