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 eventsInfo = require('./utils/events')
const { getBlockNumber } = require('./utils/contract')
const { processedMsgNotDelivered } = require('./utils/message')
const { BRIDGE_MODES } = require('../commons')
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)
async function main() {
const { foreignDeposits, homeDeposits, homeWithdrawals, foreignWithdrawals } = await eventsInfo()
const {
foreignDeposits,
homeDeposits,
homeWithdrawals,
foreignWithdrawals,
bridgeMode
} = await eventsInfo()
const xSignatures = foreignDeposits.filter(findDifferences(homeDeposits))
const xAffirmations = homeWithdrawals.filter(findDifferences(foreignWithdrawals))
let xSignatures
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')
const [homeBlockNumber, foreignBlockNumber] = await getBlockNumber(web3Home, web3Foreign)

@ -1,6 +1,7 @@
require('dotenv').config()
const logger = require('./logger')('eventsStats')
const eventsInfo = require('./utils/events')
const { processedMsgNotDelivered, deliveredMsgNotProcessed } = require('./utils/message')
const { BRIDGE_MODES } = require('../commons')
function compareDepositsHome(foreign) {
return homeDeposit => {
@ -62,9 +63,31 @@ async function main() {
homeDeposits,
homeWithdrawals,
foreignWithdrawals,
isExternalErc20
isExternalErc20,
bridgeMode
} = await eventsInfo()
if (bridgeMode === BRIDGE_MODES.ARBITRARY_MESSAGE) {
return {
home: {
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([])
@ -77,7 +100,6 @@ async function main() {
? foreignWithdrawals.filter(compareTransferForeign(homeWithdrawals))
: foreignWithdrawals.filter(compareDepositsHome(homeWithdrawals))
logger.debug('Done')
return {
onlyInHomeDeposits,
onlyInForeignDeposits,
@ -86,5 +108,6 @@ async function main() {
lastChecked: Math.floor(Date.now() / 1000)
}
}
}
module.exports = main

@ -96,7 +96,8 @@ async function main(mode) {
foreignDeposits,
homeWithdrawals,
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
}