Skip to content

Commit

Permalink
Merge pull request #59 from poanetwork/#28-ability-to-configure-sever…
Browse files Browse the repository at this point in the history
…al-rpc-failover-urls

Support several RPC URLs
  • Loading branch information
Franco Victorio authored Aug 14, 2018
2 parents c71f4a4 + caa37a0 commit c24917a
Show file tree
Hide file tree
Showing 24 changed files with 240 additions and 68 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ script:
- npm run lint
- npm test
- cd e2e && ./run-tests.sh

env:
- HOME_RPC_URL=http://example.com FOREIGN_RPC_URL=http://example.com
6 changes: 4 additions & 2 deletions config/base.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const foreignNativeAbi = require('../abis/ForeignBridgeNativeToErc.abi')
const homeErcAbi = require('../abis/HomeBridgeErcToErc.abi')
const foreignErcAbi = require('../abis/ForeignBridgeErcToErc.abi')

const rpcUrlsManager = require('../src/services/getRpcUrlsManager')

const isErcToErc = process.env.BRIDGE_MODE && process.env.BRIDGE_MODE === 'ERC_TO_ERC'

const homeAbi = isErcToErc ? homeErcAbi : homeNativeAbi
Expand All @@ -20,7 +22,7 @@ const bridgeConfig = {
}

const homeConfig = {
url: process.env.HOME_RPC_URL,
urls: rpcUrlsManager.homeUrls,
eventContractAddress: process.env.HOME_BRIDGE_ADDRESS,
eventAbi: homeAbi,
bridgeContractAddress: process.env.HOME_BRIDGE_ADDRESS,
Expand All @@ -30,7 +32,7 @@ const homeConfig = {
}

const foreignConfig = {
url: process.env.FOREIGN_RPC_URL,
urls: rpcUrlsManager.foreignUrls,
eventContractAddress: process.env.FOREIGN_BRIDGE_ADDRESS,
eventAbi: foreignAbi,
bridgeContractAddress: process.env.FOREIGN_BRIDGE_ADDRESS,
Expand Down
4 changes: 3 additions & 1 deletion config/foreign-sender.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
require('dotenv').config()

const rpcUrlsManager = require('../src/services/getRpcUrlsManager')

module.exports = {
url: process.env.FOREIGN_RPC_URL,
urls: rpcUrlsManager.foreignUrls,
queue: 'foreign',
id: 'foreign',
name: 'sender-foreign'
Expand Down
4 changes: 3 additions & 1 deletion config/home-sender.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
require('dotenv').config()

const rpcUrlsManager = require('../src/services/getRpcUrlsManager')

module.exports = {
url: process.env.HOME_RPC_URL,
urls: rpcUrlsManager.homeUrls,
queue: 'home',
id: 'home',
name: 'sender-home'
Expand Down
5 changes: 2 additions & 3 deletions e2e/scripts/deployERC20.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ const {
} = require('../submodules/poa-bridge-contracts/deploy/src/deploymentUtils')
const {
web3Foreign,
deploymentPrivateKey,
FOREIGN_RPC_URL
deploymentPrivateKey
} = require('../submodules/poa-bridge-contracts/deploy/src/web3')
const POA20 = require('../submodules/poa-bridge-contracts/build/contracts/ERC677BridgeToken.json')
const { user } = require('../constants.json')
Expand All @@ -38,7 +37,7 @@ async function deployErc20() {
nonce: foreignNonce,
to: poa20foreign.options.address,
privateKey: deploymentPrivateKey,
url: FOREIGN_RPC_URL
url: process.env.FOREIGN_RPC_URL
})
} catch (e) {
console.log(e)
Expand Down
18 changes: 16 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
"amqplib": "^0.5.2",
"bignumber.js": "^7.2.1",
"dotenv": "^5.0.1",
"http-list-provider": "0.0.2",
"ioredis": "^3.2.2",
"lodash": "^4.17.10",
"node-fetch": "^2.1.2",
"pino": "^4.17.3",
"promise-retry": "^1.1.1",
Expand Down
10 changes: 7 additions & 3 deletions scripts/getValidatorStartBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const HomeErcABI = require('../abis/HomeBridgeErcToErc.abi')
const ForeignErcABI = require('../abis/ForeignBridgeErcToErc.abi')
const bridgeValidatorsABI = require('../abis/BridgeValidators.abi')

const rpcUrlsManager = require('../src/services/getRpcUrlsManager')

const isErcToErc = process.env.BRIDGE_MODE && process.env.BRIDGE_MODE === 'ERC_TO_ERC'

const homeABI = isErcToErc ? HomeErcABI : HomeNativeABI
Expand Down Expand Up @@ -42,10 +44,12 @@ async function getStartBlock(rpcUrl, bridgeAddress, bridgeAbi) {
}

async function main() {
const { HOME_RPC_URL, FOREIGN_RPC_URL, HOME_BRIDGE_ADDRESS, FOREIGN_BRIDGE_ADDRESS } = process.env
const { HOME_BRIDGE_ADDRESS, FOREIGN_BRIDGE_ADDRESS } = process.env

const homeStartBlock = await getStartBlock(HOME_RPC_URL, HOME_BRIDGE_ADDRESS, homeABI)
const foreignStartBlock = await getStartBlock(FOREIGN_RPC_URL, FOREIGN_BRIDGE_ADDRESS, foreignABI)
const homeRpcUrl = rpcUrlsManager.homeUrls[0]
const foreignRpcUrl = rpcUrlsManager.foreignUrls[0]
const homeStartBlock = await getStartBlock(homeRpcUrl, HOME_BRIDGE_ADDRESS, homeABI)
const foreignStartBlock = await getStartBlock(foreignRpcUrl, FOREIGN_BRIDGE_ADDRESS, foreignABI)
const result = {
homeStartBlock,
foreignStartBlock
Expand Down
11 changes: 6 additions & 5 deletions scripts/sendUserTxToErcForeign.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
require('dotenv').config()
const Web3 = require('web3')
const Web3Utils = require('web3-utils')
const rpcUrlsManager = require('../src/services/getRpcUrlsManager')
const { sendTx, sendRawTx } = require('../src/tx/sendTx')

const {
USER_ADDRESS,
USER_ADDRESS_PRIVATE_KEY,
FOREIGN_BRIDGE_ADDRESS,
FOREIGN_RPC_URL,
FOREIGN_MIN_AMOUNT_PER_TX,
ERC20_TOKEN_ADDRESS
} = process.env
Expand Down Expand Up @@ -40,20 +40,21 @@ const ERC20_ABI = [
}
]

const foreignProvider = new Web3.providers.HttpProvider(FOREIGN_RPC_URL)
const foreignRpcUrl = rpcUrlsManager.foreignUrls[0]
const foreignProvider = new Web3.providers.HttpProvider(foreignRpcUrl)
const web3Foreign = new Web3(foreignProvider)

const poa20 = new web3Foreign.eth.Contract(ERC20_ABI, ERC20_TOKEN_ADDRESS)

async function main() {
try {
const foreignChaindId = await sendRawTx({
url: FOREIGN_RPC_URL,
chain: 'foreign',
params: [],
method: 'net_version'
})
let nonce = await sendRawTx({
url: FOREIGN_RPC_URL,
chain: 'foreign',
method: 'eth_getTransactionCount',
params: [USER_ADDRESS, 'latest']
})
Expand All @@ -67,7 +68,7 @@ async function main() {
.transfer(FOREIGN_BRIDGE_ADDRESS, Web3Utils.toWei(FOREIGN_MIN_AMOUNT_PER_TX))
.encodeABI({ from: USER_ADDRESS })
const txHash = await sendTx({
rpcUrl: FOREIGN_RPC_URL,
chain: 'foreign',
privateKey: USER_ADDRESS_PRIVATE_KEY,
data,
nonce,
Expand Down
11 changes: 6 additions & 5 deletions scripts/sendUserTxToErcHome.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
require('dotenv').config()
const Web3 = require('web3')
const Web3Utils = require('web3-utils')
const rpcUrlsManager = require('../src/services/getRpcUrlsManager')
const { sendTx, sendRawTx } = require('../src/tx/sendTx')

const {
USER_ADDRESS,
USER_ADDRESS_PRIVATE_KEY,
HOME_BRIDGE_ADDRESS,
HOME_RPC_URL,
HOME_MIN_AMOUNT_PER_TX,
BRIDGEABLE_TOKEN_ADDRESS
} = process.env
Expand Down Expand Up @@ -45,20 +45,21 @@ const BRIDGEABLE_TOKEN_ABI = [
}
]

const homeProvider = new Web3.providers.HttpProvider(HOME_RPC_URL)
const homeRpcUrl = rpcUrlsManager.homeUrls[0]
const homeProvider = new Web3.providers.HttpProvider(homeRpcUrl)
const web3Home = new Web3(homeProvider)

const erc677 = new web3Home.eth.Contract(BRIDGEABLE_TOKEN_ABI, BRIDGEABLE_TOKEN_ADDRESS)

async function main() {
try {
const homeChainId = await sendRawTx({
url: HOME_RPC_URL,
chain: 'home',
params: [],
method: 'net_version'
})
let nonce = await sendRawTx({
url: HOME_RPC_URL,
chain: 'home',
method: 'eth_getTransactionCount',
params: [USER_ADDRESS, 'latest']
})
Expand All @@ -72,7 +73,7 @@ async function main() {
.transferAndCall(HOME_BRIDGE_ADDRESS, Web3Utils.toWei(HOME_MIN_AMOUNT_PER_TX), '0x')
.encodeABI({ from: USER_ADDRESS })
const txHash = await sendTx({
rpcUrl: HOME_RPC_URL,
chain: 'home',
privateKey: USER_ADDRESS_PRIVATE_KEY,
data,
nonce,
Expand Down
11 changes: 6 additions & 5 deletions scripts/sendUserTxToForeign.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
require('dotenv').config()
const Web3 = require('web3')
const Web3Utils = require('web3-utils')
const HttpListProvider = require('http-list-provider')
const rpcUrlsManager = require('../src/services/getRpcUrlsManager')
const { sendTx, sendRawTx } = require('../src/tx/sendTx')

const {
USER_ADDRESS,
USER_ADDRESS_PRIVATE_KEY,
FOREIGN_BRIDGE_ADDRESS,
FOREIGN_RPC_URL,
FOREIGN_MIN_AMOUNT_PER_TX,
ERC20_TOKEN_ADDRESS
} = process.env
Expand Down Expand Up @@ -45,20 +46,20 @@ const ERC20_ABI = [
}
]

const foreignProvider = new Web3.providers.HttpProvider(FOREIGN_RPC_URL)
const foreignProvider = new HttpListProvider(rpcUrlsManager.foreignUrls)
const web3Foreign = new Web3(foreignProvider)

const poa20 = new web3Foreign.eth.Contract(ERC20_ABI, ERC20_TOKEN_ADDRESS)

async function main() {
try {
const foreignChaindId = await sendRawTx({
url: FOREIGN_RPC_URL,
chain: 'foreign',
params: [],
method: 'net_version'
})
let nonce = await sendRawTx({
url: FOREIGN_RPC_URL,
chain: 'foreign',
method: 'eth_getTransactionCount',
params: [USER_ADDRESS, 'latest']
})
Expand All @@ -72,7 +73,7 @@ async function main() {
.transferAndCall(FOREIGN_BRIDGE_ADDRESS, Web3Utils.toWei(FOREIGN_MIN_AMOUNT_PER_TX), '0x')
.encodeABI({ from: USER_ADDRESS })
const txHash = await sendTx({
rpcUrl: FOREIGN_RPC_URL,
chain: 'foreign',
privateKey: USER_ADDRESS_PRIVATE_KEY,
data,
nonce,
Expand Down
11 changes: 6 additions & 5 deletions scripts/sendUserTxToHome.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,39 @@
require('dotenv').config()
const Web3 = require('web3')
const Web3Utils = require('web3-utils')
const HttpListProvider = require('http-list-provider')
const { sendTx, sendRawTx } = require('../src/tx/sendTx')
const rpcUrlsManager = require('../src/services/getRpcUrlsManager')

const {
USER_ADDRESS,
USER_ADDRESS_PRIVATE_KEY,
HOME_BRIDGE_ADDRESS,
HOME_RPC_URL,
HOME_MIN_AMOUNT_PER_TX
} = process.env

const NUMBER_OF_DEPOSITS_TO_SEND = process.argv[2] || 1

const homeProvider = new Web3.providers.HttpProvider(HOME_RPC_URL)
const homeProvider = HttpListProvider(rpcUrlsManager.homeUrls)
const web3Home = new Web3(homeProvider)

async function main() {
try {
const homeChaindId = await sendRawTx({
url: HOME_RPC_URL,
chain: 'home',
params: [],
method: 'net_version'
})
let nonce = await sendRawTx({
url: HOME_RPC_URL,
chain: 'home',
method: 'eth_getTransactionCount',
params: [USER_ADDRESS, 'latest']
})
nonce = Web3Utils.hexToNumber(nonce)
let actualSent = 0
for (let i = 0; i < Number(NUMBER_OF_DEPOSITS_TO_SEND); i++) {
const txHash = await sendTx({
rpcUrl: HOME_RPC_URL,
chain: 'home',
privateKey: USER_ADDRESS_PRIVATE_KEY,
data: '0x',
nonce,
Expand Down
6 changes: 4 additions & 2 deletions src/events/processAffirmationRequests.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
require('dotenv').config()
const Web3 = require('web3')
const HttpListProvider = require('http-list-provider')
const logger = require('../services/logger')
const rpcUrlsManager = require('../services/getRpcUrlsManager')

const { HOME_RPC_URL, VALIDATOR_ADDRESS } = process.env
const { VALIDATOR_ADDRESS } = process.env

function processAffirmationRequestsBuilder(config) {
const homeProvider = new Web3.providers.HttpProvider(HOME_RPC_URL)
const homeProvider = new HttpListProvider(rpcUrlsManager.homeUrls)
const web3Home = new Web3(homeProvider)
const homeBridge = new web3Home.eth.Contract(config.homeBridgeAbi, config.homeBridgeAddress)

Expand Down
8 changes: 5 additions & 3 deletions src/events/processCollectedSignatures.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
require('dotenv').config()
const Web3 = require('web3')
const HttpListProvider = require('http-list-provider')
const logger = require('../services/logger')
const rpcUrlsManager = require('../services/getRpcUrlsManager')
const { signatureToVRS } = require('../utils/message')

const { HOME_RPC_URL, FOREIGN_RPC_URL, VALIDATOR_ADDRESS } = process.env
const { VALIDATOR_ADDRESS } = process.env

function processCollectedSignaturesBuilder(config) {
const homeProvider = new Web3.providers.HttpProvider(HOME_RPC_URL)
const homeProvider = new HttpListProvider(rpcUrlsManager.homeUrls)
const web3Home = new Web3(homeProvider)
const homeBridge = new web3Home.eth.Contract(config.homeBridgeAbi, config.homeBridgeAddress)

const foreignProvider = new Web3.providers.HttpProvider(FOREIGN_RPC_URL)
const foreignProvider = new HttpListProvider(rpcUrlsManager.foreignUrls)
const web3Foreign = new Web3(foreignProvider)
const foreignBridge = new web3Foreign.eth.Contract(
config.foreignBridgeAbi,
Expand Down
6 changes: 4 additions & 2 deletions src/events/processSignatureRequests.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
require('dotenv').config()
const Web3 = require('web3')
const HttpListProvider = require('http-list-provider')
const logger = require('../services/logger')
const rpcUrlsManager = require('../services/getRpcUrlsManager')
const { createMessage } = require('../utils/message')

const { HOME_RPC_URL, VALIDATOR_ADDRESS, VALIDATOR_ADDRESS_PRIVATE_KEY } = process.env
const { VALIDATOR_ADDRESS, VALIDATOR_ADDRESS_PRIVATE_KEY } = process.env

function processSignatureRequestsBuilder(config) {
const homeProvider = new Web3.providers.HttpProvider(HOME_RPC_URL)
const homeProvider = new HttpListProvider(rpcUrlsManager.homeUrls)
const web3Home = new Web3(homeProvider)
const homeBridge = new web3Home.eth.Contract(config.homeBridgeAbi, config.homeBridgeAddress)

Expand Down
Loading

0 comments on commit c24917a

Please sign in to comment.