From d17e9e0eeaf1df239dac535fbe2b7003646ee5b7 Mon Sep 17 00:00:00 2001 From: Kirill Fedoseev Date: Thu, 21 May 2020 23:29:56 +0300 Subject: [PATCH] Support of multiple AMB requests in one transaction (#315) --- commons/message.js | 4 ++-- commons/test/message.test.js | 8 ++++---- contracts | 2 +- e2e-commons/up.sh | 3 +++ monitor/utils/message.js | 18 ++++------------- .../processAMBAffirmationRequests/index.js | 20 +++++++------------ .../estimateGas.js | 4 ++-- .../processAMBCollectedSignatures/index.js | 5 +++-- .../processAMBSignatureRequests/index.js | 20 +++++++------------ 9 files changed, 33 insertions(+), 51 deletions(-) diff --git a/commons/message.js b/commons/message.js index 16d4e31d..efa5de30 100644 --- a/commons/message.js +++ b/commons/message.js @@ -9,14 +9,14 @@ function addTxHashToData({ encodedData, transactionHash }) { function parseAMBMessage(message) { message = strip0x(message) - const txHash = `0x${message.slice(0, 64)}` + const messageId = `0x${message.slice(0, 64)}` const sender = `0x${message.slice(64, 104)}` const executor = `0x${message.slice(104, 144)}` return { sender, executor, - txHash + messageId } } diff --git a/commons/test/message.test.js b/commons/test/message.test.js index 1eb3e2e6..1d446b9c 100644 --- a/commons/test/message.test.js +++ b/commons/test/message.test.js @@ -50,20 +50,20 @@ describe('parseAMBMessage', () => { it('should parse data type 00', () => { const msgSender = '0x003667154bb32e42bb9e1e6532f19d187fa0082e' const msgExecutor = '0xf4bef13f9f4f2b203faf0c3cbbaabe1afe056955' - const msgTxHash = '0xbdceda9d8c94838aca10c687da1411a07b1390e88239c0638cb9cc264219cc10' + const msgId = '0xbdceda9d8c94838aca10c687da1411a07b1390e88239c0638cb9cc264219cc10' const msgGasLimit = '000000000000000000000000000000000000000000000000000000005b877705' const msgDataType = '00' const msgData = '0xb1591967aed668a4b27645ff40c444892d91bf5951b382995d4d4f6ee3a2ce03' - const message = `0x${strip0x(msgTxHash)}${strip0x(msgSender)}${strip0x( + const message = `0x${strip0x(msgId)}${strip0x(msgSender)}${strip0x( msgExecutor )}${msgGasLimit}${msgDataType}${strip0x(msgData)}` // when - const { sender, executor, txHash } = parseAMBMessage(message) + const { sender, executor, messageId } = parseAMBMessage(message) // then expect(sender).to.be.equal(msgSender) expect(executor).to.be.equal(msgExecutor) - expect(txHash).to.be.equal(msgTxHash) + expect(messageId).to.be.equal(msgId) }) }) diff --git a/contracts b/contracts index e550067c..b5006787 160000 --- a/contracts +++ b/contracts @@ -1 +1 @@ -Subproject commit e550067c7680d416f40de95fc4c8e5b073279ee6 +Subproject commit b500678756f3fe43bf49ebda0898e0a881826ba5 diff --git a/e2e-commons/up.sh b/e2e-commons/up.sh index 78ba308e..836bc8b5 100755 --- a/e2e-commons/up.sh +++ b/e2e-commons/up.sh @@ -8,6 +8,9 @@ docker network create --driver bridge ultimate || true docker-compose up -d parity1 parity2 e2e startValidator () { + # make sure that old image tags are not cached + docker-compose $1 build + docker-compose $1 run -d --name $4 redis docker-compose $1 run -d --name $5 rabbit docker-compose $1 run $2 $3 -d oracle yarn watcher:signature-request diff --git a/monitor/utils/message.js b/monitor/utils/message.js index 5b3ccf2d..012d0e72 100644 --- a/monitor/utils/message.js +++ b/monitor/utils/message.js @@ -1,14 +1,9 @@ const web3Utils = require('web3').utils -const { addTxHashToData, parseAMBMessage } = require('../../commons') +const { parseAMBMessage } = require('../../commons') function deliveredMsgNotProcessed(processedList) { return deliveredMsg => { - const msg = parseAMBMessage( - addTxHashToData({ - encodedData: deliveredMsg.returnValues.encodedData, - transactionHash: deliveredMsg.transactionHash - }) - ) + const msg = parseAMBMessage(deliveredMsg.returnValues.encodedData) return ( processedList.filter(processedMsg => { return messageEqualsEvent(msg, processedMsg.returnValues) @@ -21,12 +16,7 @@ function processedMsgNotDelivered(deliveredList) { return processedMsg => { return ( deliveredList.filter(deliveredMsg => { - const msg = parseAMBMessage( - addTxHashToData({ - encodedData: deliveredMsg.returnValues.encodedData, - transactionHash: deliveredMsg.transactionHash - }) - ) + const msg = parseAMBMessage(deliveredMsg.returnValues.encodedData) return messageEqualsEvent(msg, processedMsg.returnValues) }).length === 0 ) @@ -37,7 +27,7 @@ function messageEqualsEvent(parsedMsg, event) { return ( web3Utils.toChecksumAddress(parsedMsg.sender) === event.sender && web3Utils.toChecksumAddress(parsedMsg.executor) === event.executor && - parsedMsg.txHash === event.transactionHash + parsedMsg.messageId === event.messageId ) } diff --git a/oracle/src/events/processAMBAffirmationRequests/index.js b/oracle/src/events/processAMBAffirmationRequests/index.js index 492e9773..19f7f0fd 100644 --- a/oracle/src/events/processAMBAffirmationRequests/index.js +++ b/oracle/src/events/processAMBAffirmationRequests/index.js @@ -6,7 +6,7 @@ const { web3Home } = require('../../services/web3') const bridgeValidatorsABI = require('../../../../contracts/build/contracts/BridgeValidators').abi const { EXIT_CODES, MAX_CONCURRENT_EVENTS } = require('../../utils/constants') const estimateGas = require('./estimateGas') -const { addTxHashToData, parseAMBMessage } = require('../../../../commons') +const { parseAMBMessage } = require('../../../../commons') const { AlreadyProcessedError, AlreadySignedError, InvalidValidatorError } = require('../../utils/errors') const limit = promiseLimit(MAX_CONCURRENT_EVENTS) @@ -30,20 +30,16 @@ function processAffirmationRequestsBuilder(config) { rootLogger.debug(`Processing ${affirmationRequests.length} AffirmationRequest events`) const callbacks = affirmationRequests .map(affirmationRequest => async () => { - const { encodedData } = affirmationRequest.returnValues + const { messageId, encodedData: message } = affirmationRequest.returnValues const logger = rootLogger.child({ - eventTransactionHash: affirmationRequest.transactionHash - }) - - const message = addTxHashToData({ - encodedData, - transactionHash: affirmationRequest.transactionHash + eventTransactionHash: affirmationRequest.transactionHash, + eventMessageId: messageId }) const { sender, executor } = parseAMBMessage(message) - logger.info({ sender, executor }, `Processing affirmationRequest ${affirmationRequest.transactionHash}`) + logger.info({ sender, executor }, `Processing affirmationRequest ${messageId}`) let gasEstimate try { @@ -63,12 +59,10 @@ function processAffirmationRequestsBuilder(config) { logger.fatal({ address: config.validatorAddress }, 'Invalid validator') process.exit(EXIT_CODES.INCOMPATIBILITY) } else if (e instanceof AlreadySignedError) { - logger.info(`Already signed affirmationRequest ${affirmationRequest.transactionHash}`) + logger.info(`Already signed affirmationRequest ${messageId}`) return } else if (e instanceof AlreadyProcessedError) { - logger.info( - `affirmationRequest ${affirmationRequest.transactionHash} was already processed by other validators` - ) + logger.info(`affirmationRequest ${messageId} was already processed by other validators`) return } else { logger.error(e, 'Unknown error while processing transaction') diff --git a/oracle/src/events/processAMBCollectedSignatures/estimateGas.js b/oracle/src/events/processAMBCollectedSignatures/estimateGas.js index 3fa31676..9ec943d1 100644 --- a/oracle/src/events/processAMBCollectedSignatures/estimateGas.js +++ b/oracle/src/events/processAMBCollectedSignatures/estimateGas.js @@ -17,7 +17,7 @@ async function estimateGas({ r, s, signatures, - txHash, + messageId, address }) { try { @@ -32,7 +32,7 @@ async function estimateGas({ // check if the message was already processed logger.debug('Check if the message was already processed') - const alreadyProcessed = await foreignBridge.methods.relayedMessages(txHash).call() + const alreadyProcessed = await foreignBridge.methods.relayedMessages(messageId).call() if (alreadyProcessed) { throw new AlreadyProcessedError() } diff --git a/oracle/src/events/processAMBCollectedSignatures/index.js b/oracle/src/events/processAMBCollectedSignatures/index.js index 7b973fb5..6f66ef5d 100644 --- a/oracle/src/events/processAMBCollectedSignatures/index.js +++ b/oracle/src/events/processAMBCollectedSignatures/index.js @@ -69,7 +69,8 @@ function processCollectedSignaturesBuilder(config) { await Promise.all(signaturePromises) const signatures = packSignatures(signaturesArray) - const { txHash } = parseAMBMessage(message) + const { messageId } = parseAMBMessage(message) + logger.info(`Processing messageId: ${messageId}`) let gasEstimate try { @@ -83,7 +84,7 @@ function processCollectedSignaturesBuilder(config) { signatures, message, numberOfCollectedSignatures: NumberOfCollectedSignatures, - txHash, + messageId, address: config.validatorAddress }) logger.debug({ gasEstimate }, 'Gas estimated') diff --git a/oracle/src/events/processAMBSignatureRequests/index.js b/oracle/src/events/processAMBSignatureRequests/index.js index 5d26f001..0efc3c03 100644 --- a/oracle/src/events/processAMBSignatureRequests/index.js +++ b/oracle/src/events/processAMBSignatureRequests/index.js @@ -4,7 +4,7 @@ const { HttpListProviderError } = require('http-list-provider') const bridgeValidatorsABI = require('../../../../contracts/build/contracts/BridgeValidators').abi const rootLogger = require('../../services/logger') const { web3Home } = require('../../services/web3') -const { addTxHashToData, parseAMBMessage } = require('../../../../commons') +const { parseAMBMessage } = require('../../../../commons') const estimateGas = require('../processSignatureRequests/estimateGas') const { AlreadyProcessedError, AlreadySignedError, InvalidValidatorError } = require('../../utils/errors') const { EXIT_CODES, MAX_CONCURRENT_EVENTS } = require('../../utils/constants') @@ -32,19 +32,15 @@ function processSignatureRequestsBuilder(config) { rootLogger.debug(`Processing ${signatureRequests.length} SignatureRequest events`) const callbacks = signatureRequests .map(signatureRequest => async () => { - const { encodedData } = signatureRequest.returnValues + const { messageId, encodedData: message } = signatureRequest.returnValues const logger = rootLogger.child({ - eventTransactionHash: signatureRequest.transactionHash - }) - - const message = addTxHashToData({ - encodedData, - transactionHash: signatureRequest.transactionHash + eventTransactionHash: signatureRequest.transactionHash, + eventMessageId: messageId }) const { sender, executor } = parseAMBMessage(message) - logger.info({ sender, executor }, `Processing signatureRequest ${signatureRequest.transactionHash}`) + logger.info({ sender, executor }, `Processing signatureRequest ${messageId}`) const signature = web3Home.eth.accounts.sign(message, `0x${ORACLE_VALIDATOR_ADDRESS_PRIVATE_KEY}`) @@ -67,12 +63,10 @@ function processSignatureRequestsBuilder(config) { logger.fatal({ address: config.validatorAddress }, 'Invalid validator') process.exit(EXIT_CODES.INCOMPATIBILITY) } else if (e instanceof AlreadySignedError) { - logger.info(`Already signed signatureRequest ${signatureRequest.transactionHash}`) + logger.info(`Already signed signatureRequest ${messageId}`) return } else if (e instanceof AlreadyProcessedError) { - logger.info( - `signatureRequest ${signatureRequest.transactionHash} was already processed by other validators` - ) + logger.info(`signatureRequest ${messageId} was already processed by other validators`) return } else { logger.error(e, 'Unknown error while processing transaction')