Skip to content

Commit

Permalink
Merge pull request #48 from poanetwork/extend-logging-#8
Browse files Browse the repository at this point in the history
Extend logging functionality
  • Loading branch information
patitonar committed Jul 25, 2018
2 parents 07f822d + d8c0a43 commit 1616790
Show file tree
Hide file tree
Showing 18 changed files with 236 additions and 67 deletions.
1 change: 1 addition & 0 deletions config/collected-signatures-watcher-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const HomeABI = require('../abis/HomeBridge.abi')

module.exports = {
event: 'CollectedSignatures',
name: 'watcher-collected-signatures',
url: process.env.HOME_RPC_URL,
contractAddress: process.env.HOME_BRIDGE_ADDRESS,
abi: HomeABI,
Expand Down
1 change: 1 addition & 0 deletions config/deposit-watcher-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const HomeABI = require('../abis/HomeBridge.abi')

module.exports = {
event: 'Deposit',
name: 'watcher-deposit',
url: process.env.HOME_RPC_URL,
contractAddress: process.env.HOME_BRIDGE_ADDRESS,
abi: HomeABI,
Expand Down
3 changes: 2 additions & 1 deletion config/foreign-sender-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ module.exports = {
url: process.env.FOREIGN_RPC_URL,
contractAddress: process.env.FOREIGN_BRIDGE_ADDRESS,
queue: 'foreign',
id: 'foreign'
id: 'foreign',
name: 'sender-foreign'
}
3 changes: 2 additions & 1 deletion config/home-sender-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ module.exports = {
url: process.env.HOME_RPC_URL,
contractAddress: process.env.HOME_BRIDGE_ADDRESS,
queue: 'home',
id: 'home'
id: 'home',
name: 'sender-home'
}
1 change: 1 addition & 0 deletions config/withdraw-watcher-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const ForeignABI = require('../abis/ForeignBridge.abi')

module.exports = {
event: 'Withdraw',
name: 'watcher-withdraw',
url: process.env.FOREIGN_RPC_URL,
contractAddress: process.env.FOREIGN_BRIDGE_ADDRESS,
abi: ForeignABI,
Expand Down
120 changes: 110 additions & 10 deletions package-lock.json

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

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"sender:home": "node src/sender.js home-sender-config.js",
"sender:foreign": "node src/sender.js foreign-sender-config.js",
"dev": "concurrently -n 'watcher:deposit,watcher:collected-signatures,watcher:withdraw,sender:home,sender:foreign' -c 'red,green,yellow,blue,magenta' 'npm run watcher:deposit' 'npm run watcher:collected-signatures' 'npm run watcher:withdraw' 'npm run sender:home' 'npm run sender:foreign'",
"test": "mocha",
"coverage": "nyc --reporter=text --reporter=html mocha",
"test": "NODE_ENV=test mocha",
"coverage": "NODE_ENV=test nyc --reporter=text --reporter=html mocha",
"postinstall": "npm install --prefix e2e"
},
"author": "",
Expand All @@ -24,6 +24,7 @@
"dotenv": "^5.0.1",
"ioredis": "^3.2.2",
"node-fetch": "^2.1.2",
"pino": "^4.17.3",
"promise-retry": "^1.1.1",
"redlock": "^3.1.2",
"web3": "^1.0.0-beta.34",
Expand All @@ -42,6 +43,7 @@
"mocha": "^5.2.0",
"nyc": "^12.0.2",
"prettier": "^1.12.1",
"proxyquire": "^2.0.1",
"sinon": "^6.1.0"
},
"engines": {
Expand Down
20 changes: 18 additions & 2 deletions src/events/processCollectedSignatures.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require('dotenv').config()
const Web3 = require('web3')
const logger = require('../services/logger')
const { signatureToVRS } = require('../utils/message')

const {
Expand All @@ -24,14 +25,18 @@ const foreignBridge = new web3Foreign.eth.Contract(ForeignABI, FOREIGN_BRIDGE_AD

async function processCollectedSignatures(signatures) {
const txToSend = []
const callbacks = signatures.map(async (colSignature, indexSig) => {
const callbacks = signatures.map(async colSignature => {
const {
authorityResponsibleForRelay,
messageHash,
NumberOfCollectedSignatures
} = colSignature.returnValues

if (authorityResponsibleForRelay === web3Home.utils.toChecksumAddress(VALIDATOR_ADDRESS)) {
logger.info(
{ eventTransactionHash: colSignature.transactionHash },
`Processing CollectedSignatures ${colSignature.transactionHash}`
)
const message = await homeBridge.methods.message(messageHash).call()

const requiredSignatures = []
Expand All @@ -53,7 +58,13 @@ async function processCollectedSignatures(signatures) {
try {
gasEstimate = await foreignBridge.methods.deposit(v, r, s, message).estimateGas()
} catch (e) {
console.log(indexSig + 1, ' # already processed col sig', colSignature.transactionHash)
if (e.message.includes('Invalid JSON RPC response')) {
throw new Error(`RPC Connection Error: deposit Gas Estimate cannot be obtained.`)
}
logger.info(
{ eventTransactionHash: colSignature.transactionHash },
`Already processed CollectedSignatures ${colSignature.transactionHash}`
)
return
}
const data = await foreignBridge.methods.deposit(v, r, s, message).encodeABI()
Expand All @@ -62,6 +73,11 @@ async function processCollectedSignatures(signatures) {
gasEstimate,
transactionReference: colSignature.transactionHash
})
} else {
logger.info(
{ eventTransactionHash: colSignature.transactionHash },
`Validator not responsible for relaying CollectedSignatures ${colSignature.transactionHash}`
)
}
})

Expand Down
Loading

0 comments on commit 1616790

Please sign in to comment.