Skip to content

Commit

Permalink
Merge the develop branch to the master branch, preparation to v2.6.0-rc1
Browse files Browse the repository at this point in the history
  • Loading branch information
akolotov authored Oct 14, 2020
2 parents 44ca0d7 + 621b20d commit fbce0fc
Show file tree
Hide file tree
Showing 10 changed files with 251 additions and 45 deletions.
2 changes: 1 addition & 1 deletion CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ MONITOR_VALIDATOR_FOREIGN_TX_LIMIT | Average gas usage of a transaction sent by
MONITOR_TX_NUMBER_THRESHOLD | If estimated number of transaction is equal to or below this value, the monitor will report that the validator has less funds than it is required. | integer
MONITOR_PORT | The port for the Monitor. | integer
MONITOR_BRIDGE_NAME | The name to be used in the url path for the bridge | string
MONITOR_CACHE_EVENTS | If set to true, monitor will cache obtained events for other workers runs
MONITOR_CACHE_EVENTS | If set to true, monitor will cache obtained events for other workers runs | `true` / `false`
173 changes: 173 additions & 0 deletions burner-wallet-plugin/yarn.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions commons/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,13 @@ const getPastEvents = async (
const middlePlusOne = middle.add(toBN(1))

const firstHalfEvents = await getPastEvents(contract, {
...options,
options,
event,
fromBlock,
toBlock: middle
})
const secondHalfEvents = await getPastEvents(contract, {
...options,
options,
event,
fromBlock: middlePlusOne,
toBlock
Expand Down
28 changes: 28 additions & 0 deletions commons/v1Abis.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,20 @@ const homeV1Abi = [
payable: false,
stateMutability: 'view',
type: 'function'
},
{
constant: true,
inputs: [],
name: 'requiredBlockConfirmations',
outputs: [
{
name: '',
type: 'uint256'
}
],
payable: false,
stateMutability: 'view',
type: 'function'
}
]

Expand Down Expand Up @@ -154,6 +168,20 @@ const foreignViAbi = [
payable: false,
stateMutability: 'view',
type: 'function'
},
{
constant: true,
inputs: [],
name: 'requiredBlockConfirmations',
outputs: [
{
name: '',
type: 'uint256'
}
],
payable: false,
stateMutability: 'view',
type: 'function'
}
]

Expand Down
3 changes: 3 additions & 0 deletions monitor/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
require('dotenv').config()
const express = require('express')
const cors = require('cors')
const { readFile } = require('./utils/file')

const app = express()
const bridgeRouter = express.Router({ mergeParams: true })

app.use(cors())

app.get('/favicon.ico', (req, res) => res.sendStatus(204))
app.use('/:bridgeName', bridgeRouter)

Expand Down
1 change: 1 addition & 0 deletions monitor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"license": "ISC",
"dependencies": {
"bignumber.js": "^6.0.0",
"cors": "^2.8.5",
"dotenv": "^5.0.1",
"express": "^4.16.3",
"node-fetch": "^2.1.2",
Expand Down
17 changes: 11 additions & 6 deletions monitor/utils/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ async function main(mode) {

logger.debug('getting last block numbers')
const [homeBlockNumber, foreignBlockNumber] = await getBlockNumber(web3Home, web3Foreign)
const homeConfirmations = toBN(await homeBridge.methods.requiredBlockConfirmations().call())
const foreignConfirmations = toBN(await foreignBridge.methods.requiredBlockConfirmations().call())
const homeDelayedBlockNumber = homeBlockNumber.sub(homeConfirmations)
const foreignDelayedBlockNumber = foreignBlockNumber.sub(foreignConfirmations)

let homeToForeignRequests = []
let foreignToHomeRequests = []
let homeMigrationBlock = MONITOR_HOME_START_BLOCK
Expand All @@ -90,7 +95,7 @@ async function main(mode) {
homeToForeignRequests = (await getPastEvents(oldHomeBridge, {
event: 'UserRequestForSignature',
fromBlock: MONITOR_HOME_START_BLOCK,
toBlock: homeBlockNumber
toBlock: homeDelayedBlockNumber
})).map(normalizeEvent)
logger.debug(`found ${homeToForeignRequests.length} events`)
if (homeToForeignRequests.length > 0) {
Expand All @@ -101,7 +106,7 @@ async function main(mode) {
foreignToHomeRequests = (await getPastEvents(oldForeignBridge, {
event: 'UserRequestForAffirmation',
fromBlock: MONITOR_FOREIGN_START_BLOCK,
toBlock: foreignBlockNumber
toBlock: foreignDelayedBlockNumber
})).map(normalizeEvent)
logger.debug(`found ${foreignToHomeRequests.length} events`)
if (foreignToHomeRequests.length > 0) {
Expand All @@ -113,7 +118,7 @@ async function main(mode) {
const homeToForeignRequestsNew = (await getPastEvents(homeBridge, {
event: v1Bridge ? 'Deposit' : 'UserRequestForSignature',
fromBlock: homeMigrationBlock,
toBlock: homeBlockNumber
toBlock: homeDelayedBlockNumber
})).map(normalizeEvent)
homeToForeignRequests = [...homeToForeignRequests, ...homeToForeignRequestsNew]

Expand All @@ -135,7 +140,7 @@ async function main(mode) {
const foreignToHomeRequestsNew = (await getPastEvents(foreignBridge, {
event: v1Bridge ? 'Withdraw' : 'UserRequestForAffirmation',
fromBlock: foreignMigrationBlock,
toBlock: foreignBlockNumber
toBlock: foreignDelayedBlockNumber
})).map(normalizeEvent)
foreignToHomeRequests = [...foreignToHomeRequests, ...foreignToHomeRequestsNew]

Expand All @@ -144,7 +149,7 @@ async function main(mode) {
let transferEvents = (await getPastEvents(erc20Contract, {
event: 'Transfer',
fromBlock: MONITOR_FOREIGN_START_BLOCK,
toBlock: foreignBlockNumber,
toBlock: foreignDelayedBlockNumber,
options: {
filter: { to: COMMON_FOREIGN_BRIDGE_ADDRESS }
}
Expand Down Expand Up @@ -194,7 +199,7 @@ async function main(mode) {
const halfDuplexTransferEvents = (await getPastEvents(halfDuplexTokenContract, {
event: 'Transfer',
fromBlock: MONITOR_FOREIGN_START_BLOCK,
toBlock: foreignBlockNumber,
toBlock: foreignDelayedBlockNumber,
options: {
filter: { to: COMMON_FOREIGN_BRIDGE_ADDRESS }
}
Expand Down
16 changes: 0 additions & 16 deletions monitor/utils/serverUtils.js

This file was deleted.

50 changes: 31 additions & 19 deletions oracle/src/sender.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,17 @@ async function readNonce(forceUpdate) {
logger.debug({ nonce }, 'Nonce found in the DB')
return Number(nonce)
} else {
logger.debug("Nonce wasn't found in the DB")
logger.warn("Nonce wasn't found in the DB")
return getNonce(web3Instance, ORACLE_VALIDATOR_ADDRESS)
}
}

function updateNonce(nonce) {
return redis.set(nonceKey, nonce)
if (typeof nonce !== 'number') {
logger.warn('Given nonce value is not a valid number. Nothing will be updated in the DB.')
} else {
redis.set(nonceKey, nonce)
}
}

async function main({ msg, ackMsg, nackMsg, channel, scheduleForRetry, scheduleTransactionResend }) {
Expand All @@ -98,13 +102,13 @@ async function main({ msg, ackMsg, nackMsg, channel, scheduleForRetry, scheduleT

const txArray = JSON.parse(msg.content)
logger.debug(`Msg received with ${txArray.length} Tx to send`)
const gasPrice = GasPrice.getPrice()
const gasPrice = GasPrice.getPrice().toString(10)

let nonce
let insufficientFunds = false
let minimumBalance = null
const failedTx = []
const sentTx = []
const resendJobs = []

const isResend = txArray.length > 0 && !!txArray[0].txHash

Expand Down Expand Up @@ -136,30 +140,32 @@ async function main({ msg, ackMsg, nackMsg, channel, scheduleForRetry, scheduleT
nonce = await readNonce(true)
}

logger.info(
`Transaction ${job.txHash} was not mined, updating gasPrice: ${job.gasPrice} -> ${gasPrice.toString(10)}`
)
logger.info(`Transaction ${job.txHash} was not mined, updating gasPrice: ${job.gasPrice} -> ${gasPrice}`)
}
logger.info(`Sending transaction with nonce ${nonce}`)
job.gasPrice = gasPrice.toString(10)
job.txHash = await sendTx({
const txHash = await sendTx({
chain: config.id,
data: job.data,
nonce,
gasPrice: job.gasPrice,
gasPrice,
amount: '0',
gasLimit,
privateKey: ORACLE_VALIDATOR_ADDRESS_PRIVATE_KEY,
to: job.to,
chainId,
web3: web3Instance
})
sentTx.push(job)
const resendJob = {
...job,
txHash,
gasPrice
}
resendJobs.push(resendJob)

nonce++
logger.info(
{ eventTransactionHash: job.transactionReference, generatedTransactionHash: job.txHash },
`Tx generated ${job.txHash} for event Tx ${job.transactionReference}`
{ eventTransactionHash: job.transactionReference, generatedTransactionHash: txHash },
`Tx generated ${txHash} for event Tx ${job.transactionReference}`
)
} catch (e) {
logger.error(
Expand All @@ -168,7 +174,11 @@ async function main({ msg, ackMsg, nackMsg, channel, scheduleForRetry, scheduleT
e.message
)
if (!e.message.toLowerCase().includes('transaction with the same hash was already imported')) {
failedTx.push(job)
if (isResend) {
resendJobs.push(job)
} else {
failedTx.push(job)
}
}

if (e.message.toLowerCase().includes('insufficient funds')) {
Expand All @@ -184,16 +194,18 @@ async function main({ msg, ackMsg, nackMsg, channel, scheduleForRetry, scheduleT
}
})

logger.debug('Updating nonce')
await updateNonce(nonce)
if (typeof nonce === 'number') {
logger.debug('Updating nonce')
await updateNonce(nonce)
}

if (failedTx.length) {
logger.info(`Sending ${failedTx.length} Failed Tx to Queue`)
await scheduleForRetry(failedTx, msg.properties.headers['x-retries'])
}
if (sentTx.length) {
logger.info(`Sending ${sentTx.length} Tx Delayed Resend Requests to Queue`)
await scheduleTransactionResend(sentTx)
if (resendJobs.length) {
logger.info(`Sending ${resendJobs.length} Tx Delayed Resend Requests to Queue`)
await scheduleTransactionResend(resendJobs)
}
ackMsg(msg)
logger.debug(`Finished processing msg`)
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6518,7 +6518,7 @@ core-util-is@1.0.2, core-util-is@~1.0.0:
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
integrity sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=

cors@^2.8.1:
cors@^2.8.1, cors@^2.8.5:
version "2.8.5"
resolved "https://registry.yarnpkg.com/cors/-/cors-2.8.5.tgz#eac11da51592dd86b9f06f6e7ac293b3df875d29"
integrity sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==
Expand Down

0 comments on commit fbce0fc

Please sign in to comment.