Add old events processing in AMB monitor (#354)

This commit is contained in:
Kirill Fedoseev 2020-06-10 16:22:01 +03:00 committed by GitHub
parent 8e10a5d609
commit d512b9850f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 92 additions and 8 deletions

@ -53,6 +53,36 @@ const ERC20_BYTES32_ABI = [
} }
] ]
const OLD_AMB_USER_REQUEST_FOR_SIGNATURE_ABI = [
{
anonymous: false,
inputs: [
{
indexed: false,
name: 'encodedData',
type: 'bytes'
}
],
name: 'UserRequestForSignature',
type: 'event'
}
]
const OLD_AMB_USER_REQUEST_FOR_AFFIRMATION_ABI = [
{
anonymous: false,
inputs: [
{
indexed: false,
name: 'encodedData',
type: 'bytes'
}
],
name: 'UserRequestForAffirmation',
type: 'event'
}
]
function getBridgeABIs(bridgeMode) { function getBridgeABIs(bridgeMode) {
let HOME_ABI = null let HOME_ABI = null
let FOREIGN_ABI = null let FOREIGN_ABI = null
@ -103,6 +133,8 @@ module.exports = {
ERC20_BYTES32_ABI, ERC20_BYTES32_ABI,
HOME_AMB_ABI, HOME_AMB_ABI,
FOREIGN_AMB_ABI, FOREIGN_AMB_ABI,
OLD_AMB_USER_REQUEST_FOR_AFFIRMATION_ABI,
OLD_AMB_USER_REQUEST_FOR_SIGNATURE_ABI,
BOX_ABI, BOX_ABI,
SAI_TOP, SAI_TOP,
HOME_STAKE_ERC_TO_ERC_ABI, HOME_STAKE_ERC_TO_ERC_ABI,

@ -1,3 +1,4 @@
require('dotenv').config()
const Web3 = require('web3') const Web3 = require('web3')
const logger = require('./logger')('checkWorker') const logger = require('./logger')('checkWorker')
const { getBridgeMode } = require('../commons') const { getBridgeMode } = require('../commons')

@ -1,3 +1,4 @@
require('dotenv').config()
const logger = require('./logger')('checkWorker2') const logger = require('./logger')('checkWorker2')
const eventsStats = require('./eventsStats') const eventsStats = require('./eventsStats')
const alerts = require('./alerts') const alerts = require('./alerts')

@ -1,3 +1,4 @@
require('dotenv').config()
const Web3 = require('web3') const Web3 = require('web3')
const logger = require('./logger')('checkWorker3') const logger = require('./logger')('checkWorker3')
const stuckTransfers = require('./stuckTransfers') const stuckTransfers = require('./stuckTransfers')

@ -12,7 +12,9 @@ const {
ERC677_BRIDGE_TOKEN_ABI, ERC677_BRIDGE_TOKEN_ABI,
getTokenType, getTokenType,
getPastEvents, getPastEvents,
ZERO_ADDRESS ZERO_ADDRESS,
OLD_AMB_USER_REQUEST_FOR_SIGNATURE_ABI,
OLD_AMB_USER_REQUEST_FOR_AFFIRMATION_ABI
} = require('../../commons') } = require('../../commons')
const { normalizeEventInformation } = require('./message') const { normalizeEventInformation } = require('./message')
const { filterTransferBeforeES } = require('./tokenUtils') const { filterTransferBeforeES } = require('./tokenUtils')
@ -72,13 +74,48 @@ async function main(mode) {
logger.debug('getting last block numbers') logger.debug('getting last block numbers')
const [homeBlockNumber, foreignBlockNumber] = await getBlockNumber(web3Home, web3Foreign) const [homeBlockNumber, foreignBlockNumber] = await getBlockNumber(web3Home, web3Foreign)
let homeToForeignRequests = []
let foreignToHomeRequests = []
let homeMigrationBlock = MONITOR_HOME_START_BLOCK
let foreignMigrationBlock = MONITOR_FOREIGN_START_BLOCK
logger.debug("calling homeBridge.getPastEvents('UserRequestForSignature')") if (bridgeMode === BRIDGE_MODES.ARBITRARY_MESSAGE) {
const homeToForeignRequests = (await getPastEvents(homeBridge, { const oldHomeBridge = new web3Home.eth.Contract(OLD_AMB_USER_REQUEST_FOR_SIGNATURE_ABI, COMMON_HOME_BRIDGE_ADDRESS)
event: v1Bridge ? 'Deposit' : 'UserRequestForSignature', const oldForeignBridge = new web3Foreign.eth.Contract(
OLD_AMB_USER_REQUEST_FOR_AFFIRMATION_ABI,
COMMON_FOREIGN_BRIDGE_ADDRESS
)
logger.debug("calling oldHomeBridge.getPastEvents('UserRequestForSignature(bytes)')")
homeToForeignRequests = (await getPastEvents(oldHomeBridge, {
event: 'UserRequestForSignature',
fromBlock: MONITOR_HOME_START_BLOCK, fromBlock: MONITOR_HOME_START_BLOCK,
toBlock: homeBlockNumber toBlock: homeBlockNumber
})).map(normalizeEvent) })).map(normalizeEvent)
logger.debug(`found ${homeToForeignRequests.length} events`)
if (homeToForeignRequests.length > 0) {
homeMigrationBlock = toBN(Math.max(...homeToForeignRequests.map(x => x.blockNumber)))
}
logger.debug("calling oldForeignBridge.getPastEvents('UserRequestForAffirmation(bytes)')")
foreignToHomeRequests = (await getPastEvents(oldForeignBridge, {
event: 'UserRequestForAffirmation',
fromBlock: MONITOR_FOREIGN_START_BLOCK,
toBlock: foreignBlockNumber
})).map(normalizeEvent)
logger.debug(`found ${foreignToHomeRequests.length} events`)
if (foreignToHomeRequests.length > 0) {
foreignMigrationBlock = toBN(Math.max(...foreignToHomeRequests.map(x => x.blockNumber)))
}
}
logger.debug("calling homeBridge.getPastEvents('UserRequestForSignature')")
const homeToForeignRequestsNew = (await getPastEvents(homeBridge, {
event: v1Bridge ? 'Deposit' : 'UserRequestForSignature',
fromBlock: homeMigrationBlock,
toBlock: homeBlockNumber
})).map(normalizeEvent)
homeToForeignRequests = [...homeToForeignRequests, ...homeToForeignRequestsNew]
logger.debug("calling foreignBridge.getPastEvents('RelayedMessage')") logger.debug("calling foreignBridge.getPastEvents('RelayedMessage')")
const homeToForeignConfirmations = (await getPastEvents(foreignBridge, { const homeToForeignConfirmations = (await getPastEvents(foreignBridge, {
@ -95,11 +132,13 @@ async function main(mode) {
})).map(normalizeEvent) })).map(normalizeEvent)
logger.debug("calling foreignBridge.getPastEvents('UserRequestForAffirmation')") logger.debug("calling foreignBridge.getPastEvents('UserRequestForAffirmation')")
let foreignToHomeRequests = (await getPastEvents(foreignBridge, { const foreignToHomeRequestsNew = (await getPastEvents(foreignBridge, {
event: v1Bridge ? 'Withdraw' : 'UserRequestForAffirmation', event: v1Bridge ? 'Withdraw' : 'UserRequestForAffirmation',
fromBlock: MONITOR_FOREIGN_START_BLOCK, fromBlock: foreignMigrationBlock,
toBlock: foreignBlockNumber toBlock: foreignBlockNumber
})).map(normalizeEvent) })).map(normalizeEvent)
foreignToHomeRequests = [...foreignToHomeRequests, ...foreignToHomeRequestsNew]
if (isExternalErc20) { if (isExternalErc20) {
logger.debug("calling erc20Contract.getPastEvents('Transfer')") logger.debug("calling erc20Contract.getPastEvents('Transfer')")
let transferEvents = (await getPastEvents(erc20Contract, { let transferEvents = (await getPastEvents(erc20Contract, {

@ -3,7 +3,12 @@ const { parseAMBMessage } = require('../../commons')
function deliveredMsgNotProcessed(processedList) { function deliveredMsgNotProcessed(processedList) {
return deliveredMsg => { return deliveredMsg => {
const msg = parseAMBMessage(deliveredMsg.returnValues.encodedData) let msgData = deliveredMsg.returnValues.encodedData
if (!deliveredMsg.returnValues.messageId) {
// append tx hash to an old message, where message id was not used
msgData = deliveredMsg.transactionHash + msgData.slice(2)
}
const msg = parseAMBMessage(msgData)
return ( return (
processedList.filter(processedMsg => { processedList.filter(processedMsg => {
return messageEqualsEvent(msg, processedMsg.returnValues) return messageEqualsEvent(msg, processedMsg.returnValues)
@ -16,7 +21,12 @@ function processedMsgNotDelivered(deliveredList) {
return processedMsg => { return processedMsg => {
return ( return (
deliveredList.filter(deliveredMsg => { deliveredList.filter(deliveredMsg => {
const msg = parseAMBMessage(deliveredMsg.returnValues.encodedData) let msgData = deliveredMsg.returnValues.encodedData
if (!deliveredMsg.returnValues.messageId) {
// append tx hash to an old message, where message id was not used
msgData = deliveredMsg.transactionHash + msgData.slice(2)
}
const msg = parseAMBMessage(msgData)
return messageEqualsEvent(msg, processedMsg.returnValues) return messageEqualsEvent(msg, processedMsg.returnValues)
}).length === 0 }).length === 0
) )
@ -27,7 +37,7 @@ function messageEqualsEvent(parsedMsg, event) {
return ( return (
web3Utils.toChecksumAddress(parsedMsg.sender) === event.sender && web3Utils.toChecksumAddress(parsedMsg.sender) === event.sender &&
web3Utils.toChecksumAddress(parsedMsg.executor) === event.executor && web3Utils.toChecksumAddress(parsedMsg.executor) === event.executor &&
parsedMsg.messageId === event.messageId parsedMsg.messageId === event.messageId // for an old messages, event.messageId is actually a transactionHash
) )
} }