Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend line width to 120 #174

Merged
merged 2 commits into from
Aug 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"semi": false,
"singleQuote": true,
"printWidth": 100,
"printWidth": 120,
"bracketSpacing": true
}
9 changes: 3 additions & 6 deletions commons/abis.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
const HOME_NATIVE_TO_ERC_ABI = require('../contracts/build/contracts/HomeBridgeNativeToErc').abi
const FOREIGN_NATIVE_TO_ERC_ABI = require('../contracts/build/contracts/ForeignBridgeNativeToErc')
.abi
const FOREIGN_NATIVE_TO_ERC_ABI = require('../contracts/build/contracts/ForeignBridgeNativeToErc').abi
const HOME_ERC_TO_ERC_ABI = require('../contracts/build/contracts/HomeBridgeErcToErc').abi
const FOREIGN_ERC_TO_ERC_ABI = require('../contracts/build/contracts/ForeignBridgeErc677ToErc677')
.abi
const FOREIGN_ERC_TO_ERC_ABI = require('../contracts/build/contracts/ForeignBridgeErc677ToErc677').abi
const HOME_ERC_TO_NATIVE_ABI = require('../contracts/build/contracts/HomeBridgeErcToNative').abi
const FOREIGN_ERC_TO_NATIVE_ABI = require('../contracts/build/contracts/ForeignBridgeErcToNative')
.abi
const FOREIGN_ERC_TO_NATIVE_ABI = require('../contracts/build/contracts/ForeignBridgeErcToNative').abi
const ERC20_ABI = require('../contracts/build/contracts/ERC20').abi
const ERC677_ABI = require('../contracts/build/contracts/ERC677').abi
const ERC677_BRIDGE_TOKEN_ABI = require('../contracts/build/contracts/ERC677BridgeToken').abi
Expand Down
26 changes: 7 additions & 19 deletions monitor/alerts.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,15 @@ async function main() {
)

logger.debug('extracting most recent transactionHash')
const { transactionHash: xSignaturesMostRecentTxHash = '' } =
xSignatures.sort(sortEvents).reverse()[0] || {}
const { transactionHash: xAffirmationsMostRecentTxHash = '' } =
xAffirmations.sort(sortEvents).reverse()[0] || {}
const { transactionHash: xSignaturesMostRecentTxHash = '' } = xSignatures.sort(sortEvents).reverse()[0] || {}
const { transactionHash: xAffirmationsMostRecentTxHash = '' } = xAffirmations.sort(sortEvents).reverse()[0] || {}

logger.debug('building transaction objects')
const foreignValidators = await Promise.all(
xSignatures.map(event => findTxSender(web3Foreign)(event))
)
const homeValidators = await Promise.all(
xAffirmations.map(event => findTxSender(web3Home)(event))
)
const foreignValidators = await Promise.all(xSignatures.map(event => findTxSender(web3Foreign)(event)))
const homeValidators = await Promise.all(xAffirmations.map(event => findTxSender(web3Home)(event)))

const xSignaturesTxs = xSignatures
.map(normalizeEventInformation)
.reduce(buildTxList(foreignValidators), {})
const xAffirmationsTxs = xAffirmations
.map(normalizeEventInformation)
.reduce(buildTxList(homeValidators), {})
const xSignaturesTxs = xSignatures.map(normalizeEventInformation).reduce(buildTxList(foreignValidators), {})
const xAffirmationsTxs = xAffirmations.map(normalizeEventInformation).reduce(buildTxList(homeValidators), {})

logger.debug('Done')

Expand Down Expand Up @@ -166,9 +156,7 @@ const findDifferences = src => dest => {
return (
src
.map(normalizeEventInformation)
.filter(
a => a.referenceTx === b.referenceTx && a.recipient === b.recipient && a.value === b.value
).length === 0
.filter(a => a.referenceTx === b.referenceTx && a.recipient === b.recipient && a.value === b.value).length === 0
)
}

Expand Down
10 changes: 2 additions & 8 deletions monitor/checkWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,12 @@ async function checkWorker() {
const foreign = Object.assign({}, balances.foreign, events.foreign)
const status = Object.assign({}, balances, events, { home }, { foreign })
if (!status) throw new Error('status is empty: ' + JSON.stringify(status))
fs.writeFileSync(
path.join(__dirname, '/responses/getBalances.json'),
JSON.stringify(status, null, 4)
)
fs.writeFileSync(path.join(__dirname, '/responses/getBalances.json'), JSON.stringify(status, null, 4))

logger.debug('calling validators()')
const vBalances = await validators(bridgeMode)
if (!vBalances) throw new Error('vBalances is empty: ' + JSON.stringify(vBalances))
fs.writeFileSync(
path.join(__dirname, '/responses/validators.json'),
JSON.stringify(vBalances, null, 4)
)
fs.writeFileSync(path.join(__dirname, '/responses/validators.json'), JSON.stringify(vBalances, null, 4))
logger.debug('Done')
} catch (e) {
logger.error(e)
Expand Down
10 changes: 2 additions & 8 deletions monitor/checkWorker2.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,11 @@ async function checkWorker2() {
logger.debug('calling eventsStats()')
const evStats = await eventsStats()
if (!evStats) throw new Error('evStats is empty: ' + JSON.stringify(evStats))
fs.writeFileSync(
path.join(__dirname, '/responses/eventsStats.json'),
JSON.stringify(evStats, null, 4)
)
fs.writeFileSync(path.join(__dirname, '/responses/eventsStats.json'), JSON.stringify(evStats, null, 4))
logger.debug('calling alerts()')
const _alerts = await alerts()
if (!_alerts) throw new Error('alerts is empty: ' + JSON.stringify(_alerts))
fs.writeFileSync(
path.join(__dirname, '/responses/alerts.json'),
JSON.stringify(_alerts, null, 4)
)
fs.writeFileSync(path.join(__dirname, '/responses/alerts.json'), JSON.stringify(_alerts, null, 4))
logger.debug('Done x2')
} catch (e) {
logger.error(e)
Expand Down
5 changes: 1 addition & 4 deletions monitor/checkWorker3.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ async function checkWorker3() {
const transfers = await stuckTransfers()
// console.log(transfers)
if (!transfers) throw new Error('transfers is empty: ' + JSON.stringify(transfers))
fs.writeFileSync(
path.join(__dirname, '/responses/stuckTransfers.json'),
JSON.stringify(transfers, null, 4)
)
fs.writeFileSync(path.join(__dirname, '/responses/stuckTransfers.json'), JSON.stringify(transfers, null, 4))
logger.debug('Done')
} catch (e) {
logger.error('checkWorker3.js', e)
Expand Down
12 changes: 2 additions & 10 deletions monitor/eventsStats.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,10 @@ function compareTransferForeign(home) {
}

async function main() {
const {
foreignDeposits,
homeDeposits,
homeWithdrawals,
foreignWithdrawals,
isExternalErc20
} = await eventsInfo()
const { foreignDeposits, homeDeposits, homeWithdrawals, foreignWithdrawals, isExternalErc20 } = await eventsInfo()

const onlyInHomeDeposits = homeDeposits.filter(compareDepositsHome(foreignDeposits))
const onlyInForeignDeposits = foreignDeposits
.concat([])
.filter(compareDepositsForeign(homeDeposits))
const onlyInForeignDeposits = foreignDeposits.concat([]).filter(compareDepositsForeign(homeDeposits))

const onlyInHomeWithdrawals = isExternalErc20
? homeWithdrawals.filter(compareTransferHome(foreignWithdrawals))
Expand Down
20 changes: 4 additions & 16 deletions monitor/getBalances.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ const {

async function main(bridgeMode) {
if (bridgeMode === BRIDGE_MODES.ERC_TO_ERC) {
const foreignBridge = new web3Foreign.eth.Contract(
FOREIGN_ERC_TO_ERC_ABI,
FOREIGN_BRIDGE_ADDRESS
)
const foreignBridge = new web3Foreign.eth.Contract(FOREIGN_ERC_TO_ERC_ABI, FOREIGN_BRIDGE_ADDRESS)
const erc20Address = await foreignBridge.methods.erc20token().call()
const erc20Contract = new web3Foreign.eth.Contract(ERC20_ABI, erc20Address)
logger.debug('calling erc20Contract.methods.balanceOf')
Expand All @@ -55,15 +52,9 @@ async function main(bridgeMode) {
balanceDiff: Number(Web3Utils.fromWei(diff)),
lastChecked: Math.floor(Date.now() / 1000)
}
} else if (
bridgeMode === BRIDGE_MODES.NATIVE_TO_ERC ||
bridgeMode === BRIDGE_MODES.NATIVE_TO_ERC_V1
) {
} else if (bridgeMode === BRIDGE_MODES.NATIVE_TO_ERC || bridgeMode === BRIDGE_MODES.NATIVE_TO_ERC_V1) {
logger.debug('calling web3Home.eth.getBalance')
const foreignBridge = new web3Foreign.eth.Contract(
FOREIGN_NATIVE_TO_ERC_ABI,
FOREIGN_BRIDGE_ADDRESS
)
const foreignBridge = new web3Foreign.eth.Contract(FOREIGN_NATIVE_TO_ERC_ABI, FOREIGN_BRIDGE_ADDRESS)
const erc20Address = await foreignBridge.methods.erc677token().call()
const homeBalance = await web3Home.eth.getBalance(HOME_BRIDGE_ADDRESS)
const tokenContract = new web3Foreign.eth.Contract(ERC20_ABI, erc20Address)
Expand All @@ -84,10 +75,7 @@ async function main(bridgeMode) {
lastChecked: Math.floor(Date.now() / 1000)
}
} else if (bridgeMode === BRIDGE_MODES.ERC_TO_NATIVE) {
const foreignBridge = new web3Foreign.eth.Contract(
FOREIGN_ERC_TO_NATIVE_ABI,
FOREIGN_BRIDGE_ADDRESS
)
const foreignBridge = new web3Foreign.eth.Contract(FOREIGN_ERC_TO_NATIVE_ABI, FOREIGN_BRIDGE_ADDRESS)
const erc20Address = await foreignBridge.methods.erc20token().call()
const erc20Contract = new web3Foreign.eth.Contract(ERC20_ABI, erc20Address)
logger.debug('calling erc20Contract.methods.balanceOf')
Expand Down
4 changes: 1 addition & 3 deletions monitor/getShortEventStats.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ require('dotenv').config()
const eventsInfo = require('./utils/events')

async function main(bridgeMode) {
const { foreignDeposits, homeDeposits, homeWithdrawals, foreignWithdrawals } = await eventsInfo(
bridgeMode
)
const { foreignDeposits, homeDeposits, homeWithdrawals, foreignWithdrawals } = await eventsInfo(bridgeMode)

return {
depositsDiff: homeDeposits.length - foreignDeposits.length,
Expand Down
3 changes: 1 addition & 2 deletions monitor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ app.get('/eventsStats', async (req, res, next) => {
app.get('/alerts', async (req, res, next) => {
try {
const results = await readFile('./responses/alerts.json')
results.ok =
!results.executeAffirmations.mostRecentTxHash && !results.executeSignatures.mostRecentTxHash
results.ok = !results.executeAffirmations.mostRecentTxHash && !results.executeSignatures.mostRecentTxHash
res.json(results)
} catch (e) {
next(e)
Expand Down
7 changes: 1 addition & 6 deletions monitor/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ module.exports = function logger(name) {

function log(...args) {
const now = new Date()
console.log(
now.toISOString(),
`(+${lastlog ? now.getTime() - lastlog : 0}ms)`,
`[${name}]`,
...args
)
console.log(now.toISOString(), `(+${lastlog ? now.getTime() - lastlog : 0}ms)`, `[${name}]`, ...args)
lastlog = now.getTime()
}

Expand Down
3 changes: 1 addition & 2 deletions monitor/utils/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ async function main(mode) {
const homeBridge = new web3Home.eth.Contract(HOME_ABI, HOME_BRIDGE_ADDRESS)
const foreignBridge = new web3Foreign.eth.Contract(FOREIGN_ABI, FOREIGN_BRIDGE_ADDRESS)
const v1Bridge = bridgeMode === BRIDGE_MODES.NATIVE_TO_ERC_V1
const erc20MethodName =
bridgeMode === BRIDGE_MODES.NATIVE_TO_ERC || v1Bridge ? 'erc677token' : 'erc20token'
const erc20MethodName = bridgeMode === BRIDGE_MODES.NATIVE_TO_ERC || v1Bridge ? 'erc677token' : 'erc20token'
const erc20Address = await foreignBridge.methods[erc20MethodName]().call()
const tokenType = await getTokenType(
new web3Foreign.eth.Contract(ERC677_BRIDGE_TOKEN_ABI, erc20Address),
Expand Down
10 changes: 2 additions & 8 deletions monitor/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,14 @@ async function main(bridgeMode) {
const homeBridge = new web3Home.eth.Contract(HOME_ABI, HOME_BRIDGE_ADDRESS)
const foreignBridge = new web3Foreign.eth.Contract(FOREIGN_ABI, FOREIGN_BRIDGE_ADDRESS)
const homeValidatorsAddress = await homeBridge.methods.validatorContract().call()
const homeBridgeValidators = new web3Home.eth.Contract(
BRIDGE_VALIDATORS_ABI,
homeValidatorsAddress
)
const homeBridgeValidators = new web3Home.eth.Contract(BRIDGE_VALIDATORS_ABI, homeValidatorsAddress)

logger.debug('getting last block numbers')
const [homeBlockNumber, foreignBlockNumber] = await getBlockNumber(web3Home, web3Foreign)

logger.debug('calling foreignBridge.methods.validatorContract().call()')
const foreignValidatorsAddress = await foreignBridge.methods.validatorContract().call()
const foreignBridgeValidators = new web3Foreign.eth.Contract(
BRIDGE_VALIDATORS_ABI,
foreignValidatorsAddress
)
const foreignBridgeValidators = new web3Foreign.eth.Contract(BRIDGE_VALIDATORS_ABI, foreignValidatorsAddress)

logger.debug('calling foreignBridgeValidators getValidatorList()')
const foreignValidators = await getValidatorList(
Expand Down
5 changes: 1 addition & 4 deletions oracle-e2e/test/ercToErc.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ const { toBN } = foreignWeb3.utils
homeWeb3.eth.accounts.wallet.add(user.privateKey)
foreignWeb3.eth.accounts.wallet.add(user.privateKey)

const erc20Token = new foreignWeb3.eth.Contract(
ERC677_BRIDGE_TOKEN_ABI,
ercToErcBridge.foreignToken
)
const erc20Token = new foreignWeb3.eth.Contract(ERC677_BRIDGE_TOKEN_ABI, ercToErcBridge.foreignToken)
const erc677Token = new homeWeb3.eth.Contract(ERC677_BRIDGE_TOKEN_ABI, ercToErcBridge.homeToken)

describe('erc to erc', () => {
Expand Down
5 changes: 1 addition & 4 deletions oracle-e2e/test/ercToNative.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ const { toBN } = foreignWeb3.utils
homeWeb3.eth.accounts.wallet.add(user.privateKey)
foreignWeb3.eth.accounts.wallet.add(user.privateKey)

const erc20Token = new foreignWeb3.eth.Contract(
ERC677_BRIDGE_TOKEN_ABI,
ercToNativeBridge.foreignToken
)
const erc20Token = new foreignWeb3.eth.Contract(ERC677_BRIDGE_TOKEN_ABI, ercToNativeBridge.foreignToken)

describe('erc to native', () => {
it('should convert tokens in foreign to coins in home', async () => {
Expand Down
3 changes: 1 addition & 2 deletions oracle/config/affirmation-request-watcher.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ if (baseConfig.id === 'erc-erc' && initialChecks.foreignERC === ERC_TYPES.ERC677
const id = `${baseConfig.id}-affirmation-request`

module.exports =
(baseConfig.id === 'erc-erc' && initialChecks.foreignERC === ERC_TYPES.ERC20) ||
baseConfig.id === 'erc-native'
(baseConfig.id === 'erc-erc' && initialChecks.foreignERC === ERC_TYPES.ERC20) || baseConfig.id === 'erc-native'
? {
...baseConfig.bridgeConfig,
...baseConfig.foreignConfig,
Expand Down
3 changes: 1 addition & 2 deletions oracle/config/base.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ let maxProcessingTime = null
if (String(process.env.MAX_PROCESSING_TIME) === '0') {
maxProcessingTime = 0
} else if (!process.env.MAX_PROCESSING_TIME) {
maxProcessingTime =
4 * Math.max(process.env.HOME_POLLING_INTERVAL, process.env.FOREIGN_POLLING_INTERVAL)
maxProcessingTime = 4 * Math.max(process.env.HOME_POLLING_INTERVAL, process.env.FOREIGN_POLLING_INTERVAL)
} else {
maxProcessingTime = Number(process.env.MAX_PROCESSING_TIME)
}
Expand Down
5 changes: 1 addition & 4 deletions oracle/scripts/compute-stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ async function main() {
console.log('Signature Requests')
console.log(signatureRequestsStats)

const collectedSignaturesStats = computeCollectedSignaturesStats(
collectedSignatures,
senderForeign
)
const collectedSignaturesStats = computeCollectedSignaturesStats(collectedSignatures, senderForeign)
console.log('Collected Signatures')
console.log(collectedSignaturesStats)
}
Expand Down
3 changes: 1 addition & 2 deletions oracle/scripts/erc20_to_erc20/sendHome.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ const {
HOME_TEST_TX_GAS_PRICE
} = process.env

const NUMBER_OF_WITHDRAWALS_TO_SEND =
process.argv[2] || process.env.NUMBER_OF_WITHDRAWALS_TO_SEND || 1
const NUMBER_OF_WITHDRAWALS_TO_SEND = process.argv[2] || process.env.NUMBER_OF_WITHDRAWALS_TO_SEND || 1

const BRIDGEABLE_TOKEN_ABI = [
{
Expand Down
5 changes: 1 addition & 4 deletions oracle/scripts/getValidatorStartBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ async function getStartBlock(rpcUrl, bridgeAddress, bridgeAbi) {
const deployedAtBlock = await bridgeContract.methods.deployedAtBlock().call()

const validatorContractAddress = await bridgeContract.methods.validatorContract().call()
const validatorContract = new web3Instance.eth.Contract(
BRIDGE_VALIDATORS_ABI,
validatorContractAddress
)
const validatorContract = new web3Instance.eth.Contract(BRIDGE_VALIDATORS_ABI, validatorContractAddress)

const validatorDeployedAtBlock = await validatorContract.methods.deployedAtBlock().call()

Expand Down
5 changes: 1 addition & 4 deletions oracle/scripts/initialChecks.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ async function initialChecks() {

if (BRIDGE_MODE === 'ERC_TO_ERC') {
const foreignWeb3 = new Web3(new Web3.providers.HttpProvider(FOREIGN_RPC_URL))
const bridgeTokenContract = new foreignWeb3.eth.Contract(
ERC677_BRIDGE_TOKEN_ABI,
ERC20_TOKEN_ADDRESS
)
const bridgeTokenContract = new foreignWeb3.eth.Contract(ERC677_BRIDGE_TOKEN_ABI, ERC20_TOKEN_ADDRESS)

result.foreignERC = await getTokenType(bridgeTokenContract, FOREIGN_BRIDGE_ADDRESS)
}
Expand Down
3 changes: 1 addition & 2 deletions oracle/scripts/native_to_erc20/sendForeign.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ const {
FOREIGN_TEST_TX_GAS_PRICE
} = process.env

const NUMBER_OF_WITHDRAWALS_TO_SEND =
process.argv[2] || process.env.NUMBER_OF_WITHDRAWALS_TO_SEND || 1
const NUMBER_OF_WITHDRAWALS_TO_SEND = process.argv[2] || process.env.NUMBER_OF_WITHDRAWALS_TO_SEND || 1

const ERC677_ABI = [
{
Expand Down
28 changes: 6 additions & 22 deletions oracle/src/events/processAffirmationRequests/estimateGas.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,14 @@
const { HttpListProviderError } = require('http-list-provider')
const {
AlreadyProcessedError,
AlreadySignedError,
InvalidValidatorError
} = require('../../utils/errors')
const { AlreadyProcessedError, AlreadySignedError, InvalidValidatorError } = require('../../utils/errors')
const logger = require('../../services/logger').child({
module: 'processAffirmationRequests:estimateGas'
})

async function estimateGas({
web3,
homeBridge,
validatorContract,
recipient,
value,
txHash,
address
}) {
async function estimateGas({ web3, homeBridge, validatorContract, recipient, value, txHash, address }) {
try {
const gasEstimate = await homeBridge.methods
.executeAffirmation(recipient, value, txHash)
.estimateGas({
from: address
})
const gasEstimate = await homeBridge.methods.executeAffirmation(recipient, value, txHash).estimateGas({
from: address
})

return gasEstimate
} catch (e) {
Expand All @@ -36,9 +22,7 @@ async function estimateGas({
// Check if minimum number of validations was already reached
logger.debug('Check if minimum number of validations was already reached')
const numAffirmationsSigned = await homeBridge.methods.numAffirmationsSigned(messageHash).call()
const alreadyProcessed = await homeBridge.methods
.isAlreadyProcessed(numAffirmationsSigned)
.call()
const alreadyProcessed = await homeBridge.methods.isAlreadyProcessed(numAffirmationsSigned).call()

if (alreadyProcessed) {
throw new AlreadyProcessedError(e.message)
Expand Down
Loading