Support of multiple AMB requests in one transaction (#315)

This commit is contained in:
Kirill Fedoseev 2020-05-21 23:29:56 +03:00 committed by GitHub
parent a2c678d0a2
commit d17e9e0eea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 33 additions and 51 deletions

@ -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
}
}

@ -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)
})
})

@ -1 +1 @@
Subproject commit e550067c7680d416f40de95fc4c8e5b073279ee6
Subproject commit b500678756f3fe43bf49ebda0898e0a881826ba5

@ -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

@ -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
)
}

@ -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')

@ -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()
}

@ -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')

@ -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')