From ce29b95729ea76d2c5a6d31a79e3b7acf2479daa Mon Sep 17 00:00:00 2001 From: Kirill Fedoseev Date: Wed, 4 Nov 2020 22:16:43 +0300 Subject: [PATCH] Support AMB manual lane and allowance/block lists in the monitor (#484) --- e2e-commons/up.sh | 18 +++++++++++++++++- monitor-e2e/periodically-check-all.sh | 18 +++++++++++++----- monitor-e2e/run-tests.sh | 22 +++++++++++++++++++--- monitor-e2e/test/amb.js | 12 +++++++++++- monitor-e2e/test/ercToNative.js | 8 ++++---- monitor-e2e/utils.js | 8 ++++++-- monitor-e2e/wait-for-monitor.sh | 16 ++++++++++++---- monitor/getShortEventStats.js | 13 +++++++++++-- monitor/utils/message.js | 21 ++++++++++++++++++++- 9 files changed, 113 insertions(+), 23 deletions(-) diff --git a/e2e-commons/up.sh b/e2e-commons/up.sh index 7b3c7afe..0bdf21a2 100755 --- a/e2e-commons/up.sh +++ b/e2e-commons/up.sh @@ -100,7 +100,23 @@ while [ "$1" != "" ]; do fi if [ "$1" == "monitor" ]; then - docker-compose up -d monitor monitor-erc20 monitor-erc20-native monitor-amb + case "$MODE" in + amb) + docker-compose up -d monitor-amb + ;; + native-to-erc) + docker-compose up -d monitor + ;; + erc-to-erc) + docker-compose up -d monitor-erc20 + ;; + erc-to-native) + docker-compose up -d monitor-erc20-native + ;; + *) + docker-compose up -d monitor monitor-erc20 monitor-erc20-native monitor-amb + ;; + esac fi if [ "$1" == "alm-e2e" ]; then diff --git a/monitor-e2e/periodically-check-all.sh b/monitor-e2e/periodically-check-all.sh index dd5e0c98..1b01de9a 100755 --- a/monitor-e2e/periodically-check-all.sh +++ b/monitor-e2e/periodically-check-all.sh @@ -1,7 +1,15 @@ while true; do - sleep 5 - docker-compose -f ../e2e-commons/docker-compose.yml exec -d monitor yarn check-all - docker-compose -f ../e2e-commons/docker-compose.yml exec -d monitor-erc20 yarn check-all - docker-compose -f ../e2e-commons/docker-compose.yml exec -d monitor-erc20-native yarn check-all - docker-compose -f ../e2e-commons/docker-compose.yml exec -d monitor-amb yarn check-all + docker-compose -f ../e2e-commons/docker-compose.yml exec -T monitor yarn check-all + pid1=$! + docker-compose -f ../e2e-commons/docker-compose.yml exec -T monitor-erc20 yarn check-all + pid2=$! + docker-compose -f ../e2e-commons/docker-compose.yml exec -T monitor-erc20-native yarn check-all + pid3=$! + docker-compose -f ../e2e-commons/docker-compose.yml exec -T monitor-amb yarn check-all + pid4=$! + + wait $pid1 + wait $pid2 + wait $pid3 + wait $pid4 done diff --git a/monitor-e2e/run-tests.sh b/monitor-e2e/run-tests.sh index d54a504f..136a4c2b 100755 --- a/monitor-e2e/run-tests.sh +++ b/monitor-e2e/run-tests.sh @@ -1,12 +1,28 @@ cd $(dirname $0) -../e2e-commons/up.sh deploy blocks monitor +mode="$1" +case "$mode" in + amb) + script=./test/amb.js + ;; + native-to-erc) + script=./test/nativeToErc.js + ;; + erc-to-erc) + script=./test/ercToErc.js + ;; + erc-to-native) + script=./test/ercToNative.js + ;; +esac -./wait-for-monitor.sh +MODE="$mode" ../e2e-commons/up.sh deploy blocks monitor + +MODE="$mode" ./wait-for-monitor.sh nohup ./periodically-check-all.sh < /dev/null > /dev/null 2>&1 & checkPID=$! -docker-compose -f ../e2e-commons/docker-compose.yml run e2e yarn workspace monitor-e2e run start +docker-compose -f ../e2e-commons/docker-compose.yml run e2e yarn workspace monitor-e2e run start $script rc=$? ../e2e-commons/down.sh diff --git a/monitor-e2e/test/amb.js b/monitor-e2e/test/amb.js index 59b22fe5..5ed13641 100644 --- a/monitor-e2e/test/amb.js +++ b/monitor-e2e/test/amb.js @@ -25,6 +25,7 @@ describe('AMB', () => { describe('general', async () => { it('should contain fromHomeToForeignDiff', () => assert(data.fromHomeToForeignDiff === 0)) + it('should contain fromHomeToForeignPBUDiff', () => assert(data.fromHomeToForeignPBUDiff === 0)) it('should contain fromForeignToHomeDiff', () => assert(data.fromForeignToHomeDiff === 0)) it('should contain lastChecked', () => assert(data.lastChecked >= 0)) it('should contain timeDiff', () => assert(data.timeDiff >= 0)) @@ -114,7 +115,16 @@ describe('AMB', () => { await waitUntil(async () => { ;({ data } = await axios.get(`${baseUrl}`)) - return data.fromHomeToForeignDiff !== 0 + return data.fromHomeToForeignDiff === 1 && data.fromHomeToForeignPBUDiff === 0 + }) + }) + it('should change fromHomeToForeignPBUDiff', async () => { + // send message + await sendAMBMessage(homeRPC.URL, user, amb.homeBox, amb.home, amb.foreignBox, true) + + await waitUntil(async () => { + ;({ data } = await axios.get(`${baseUrl}`)) + return data.fromHomeToForeignDiff === 1 && data.fromHomeToForeignPBUDiff === 1 }) }) it('should change validatorsMatch', async () => { diff --git a/monitor-e2e/test/ercToNative.js b/monitor-e2e/test/ercToNative.js index 7810ed39..f8770453 100644 --- a/monitor-e2e/test/ercToNative.js +++ b/monitor-e2e/test/ercToNative.js @@ -54,16 +54,16 @@ describe('ERC TO NATIVE with changing state of contracts', () => { }) it('should consider chai token balance', async function() { - this.timeout(60000) + this.timeout(120000) await initializeChaiToken(foreignRPC.URL, ercToNativeBridge.foreign) await sendTokens(foreignRPC.URL, user, ercToNativeBridge.foreignToken, ercToNativeBridge.foreign) await waitUntil(async () => { ;({ data } = await axios.get(`${baseUrl}`)) - const { erc20Balance, investedErc20Balance, accumulatedInterest } = data.foreign if (!data.foreign) { return false } + const { erc20Balance, investedErc20Balance, accumulatedInterest } = data.foreign return ( data.balanceDiff === 0.02 && erc20Balance === '0.02' && @@ -77,10 +77,10 @@ describe('ERC TO NATIVE with changing state of contracts', () => { await waitUntil(async () => { ;({ data } = await axios.get(`${baseUrl}`)) - const { erc20Balance, investedErc20Balance, accumulatedInterest } = data.foreign if (!data.foreign) { return false } + const { erc20Balance, investedErc20Balance, accumulatedInterest } = data.foreign return ( data.balanceDiff === 0.02 && erc20Balance === '0.01' && @@ -94,10 +94,10 @@ describe('ERC TO NATIVE with changing state of contracts', () => { await waitUntil(async () => { ;({ data } = await axios.get(`${baseUrl}`)) - const { erc20Balance, investedErc20Balance, accumulatedInterest } = data.foreign if (!data.foreign) { return false } + const { erc20Balance, investedErc20Balance, accumulatedInterest } = data.foreign return ( data.balanceDiff === 0.02 && erc20Balance === '0.005' && diff --git a/monitor-e2e/utils.js b/monitor-e2e/utils.js index c7a9428a..52efbb53 100644 --- a/monitor-e2e/utils.js +++ b/monitor-e2e/utils.js @@ -44,12 +44,16 @@ const sendTokens = async (rpcUrl, account, tokenAddress, recipientAddress) => { }) } -const sendAMBMessage = async (rpcUrl, account, boxAddress, bridgeAddress, boxOtherSideAddress) => { +const sendAMBMessage = async (rpcUrl, account, boxAddress, bridgeAddress, boxOtherSideAddress, manualLane = false) => { const web3 = new Web3(new Web3.providers.HttpProvider(rpcUrl)) web3.eth.accounts.wallet.add(account.privateKey) const homeBox = new web3.eth.Contract(BOX_ABI, boxAddress) - await homeBox.methods.setValueOnOtherNetwork(3, bridgeAddress, boxOtherSideAddress).send({ + await homeBox.methods[manualLane ? 'setValueOnOtherNetworkUsingManualLane' : 'setValueOnOtherNetwork']( + 3, + bridgeAddress, + boxOtherSideAddress + ).send({ from: account.address, gas: '400000' }) diff --git a/monitor-e2e/wait-for-monitor.sh b/monitor-e2e/wait-for-monitor.sh index 2b33b215..b68e54de 100755 --- a/monitor-e2e/wait-for-monitor.sh +++ b/monitor-e2e/wait-for-monitor.sh @@ -6,10 +6,18 @@ check_files_exist() { rc=0 for f in "${FILES[@]}"; do command="test -f responses/bridge/$f" - (docker-compose -f ../e2e-commons/docker-compose.yml exec -T monitor /bin/bash -c "$command") || rc=1 - (docker-compose -f ../e2e-commons/docker-compose.yml exec -T monitor-erc20 /bin/bash -c "$command") || rc=1 - (docker-compose -f ../e2e-commons/docker-compose.yml exec -T monitor-erc20-native /bin/bash -c "$command") || rc=1 - (docker-compose -f ../e2e-commons/docker-compose.yml exec -T monitor-amb /bin/bash -c "$command") || rc=1 + if [[ -z "$MODE" || "$MODE" == native-to-erc ]]; then + (docker-compose -f ../e2e-commons/docker-compose.yml exec -T monitor /bin/bash -c "$command") || rc=1 + fi + if [[ -z "$MODE" || "$MODE" == erc-to-erc ]]; then + (docker-compose -f ../e2e-commons/docker-compose.yml exec -T monitor-erc20 /bin/bash -c "$command") || rc=1 + fi + if [[ -z "$MODE" || "$MODE" == erc-to-native ]]; then + (docker-compose -f ../e2e-commons/docker-compose.yml exec -T monitor-erc20-native /bin/bash -c "$command") || rc=1 + fi + if [[ -z "$MODE" || "$MODE" == amb ]]; then + (docker-compose -f ../e2e-commons/docker-compose.yml exec -T monitor-amb /bin/bash -c "$command") || rc=1 + fi done return $rc } diff --git a/monitor/getShortEventStats.js b/monitor/getShortEventStats.js index c9777285..1b6607ce 100644 --- a/monitor/getShortEventStats.js +++ b/monitor/getShortEventStats.js @@ -1,7 +1,12 @@ require('dotenv').config() const BN = require('bignumber.js') const Web3Utils = require('web3').utils -const { eventWithoutReference, unclaimedHomeToForeignRequests } = require('./utils/message') +const { + eventWithoutReference, + deliveredMsgNotProcessed, + unclaimedHomeToForeignRequests, + manuallyProcessedAMBHomeToForeignRequests +} = require('./utils/message') const { BRIDGE_MODES } = require('../commons') const { getHomeTxSender } = require('./utils/web3Cache') @@ -20,8 +25,12 @@ async function main(bridgeMode, eventsInfo) { } = eventsInfo if (bridgeMode === BRIDGE_MODES.ARBITRARY_MESSAGE) { + const onlyInHomeRequests = homeToForeignRequests.filter(deliveredMsgNotProcessed(homeToForeignConfirmations)) + const manuallyProcessedRequests = onlyInHomeRequests.filter(manuallyProcessedAMBHomeToForeignRequests()) return { - fromHomeToForeignDiff: homeToForeignRequests.length - homeToForeignConfirmations.length, + fromHomeToForeignDiff: + homeToForeignRequests.length - homeToForeignConfirmations.length - manuallyProcessedRequests.length, + fromHomeToForeignPBUDiff: manuallyProcessedRequests.length, fromForeignToHomeDiff: foreignToHomeConfirmations.length - foreignToHomeRequests.length, home: { toForeign: homeToForeignRequests.length, diff --git a/monitor/utils/message.js b/monitor/utils/message.js index 46282b1f..fe840628 100644 --- a/monitor/utils/message.js +++ b/monitor/utils/message.js @@ -66,10 +66,29 @@ const unclaimedHomeToForeignRequests = () => { } } +const manuallyProcessedAMBHomeToForeignRequests = () => { + if (MONITOR_HOME_TO_FOREIGN_ALLOWANCE_LIST) { + const allowanceList = readAccessListFile(MONITOR_HOME_TO_FOREIGN_ALLOWANCE_LIST) + return e => { + const { sender, executor, decodedDataType } = normalizeAMBMessage(e) + return (!allowanceList.includes(sender) && !allowanceList.includes(executor)) || decodedDataType.manualLane + } + } else if (MONITOR_HOME_TO_FOREIGN_BLOCK_LIST) { + const blockList = readAccessListFile(MONITOR_HOME_TO_FOREIGN_BLOCK_LIST) + return e => { + const { sender, executor, decodedDataType } = normalizeAMBMessage(e) + return blockList.includes(sender) || blockList.includes(executor) || decodedDataType.manualLane + } + } else { + return e => normalizeAMBMessage(e).decodedDataType.manualLane + } +} + module.exports = { deliveredMsgNotProcessed, processedMsgNotDelivered, normalizeEventInformation, eventWithoutReference, - unclaimedHomeToForeignRequests + unclaimedHomeToForeignRequests, + manuallyProcessedAMBHomeToForeignRequests }