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

Fix error handling on V1 monitor workers #29

Open
wants to merge 3 commits into
base: master-1.x
Choose a base branch
from
Open
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: 0 additions & 2 deletions checkWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ async function checkWorker() {
if (!vBalances) throw new Error('vBalances is empty: ' + JSON.stringify(vBalances));
fs.writeFileSync(__dirname + '/responses/validators.json', JSON.stringify(vBalances,null,4));
logger.debug("Done");
return status;
} catch(e) {
logger.error(e);
throw e;
}
}
checkWorker();
4 changes: 1 addition & 3 deletions checkWorker2.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ async function checkWorker2() {
if (!evStats) throw new Error('evStats is empty: ' + JSON.stringify(evStats));
fs.writeFileSync(__dirname + '/responses/eventsStats.json', JSON.stringify(evStats,null,4));
logger.debug("Done");
return evStats;
} catch(e) {
logger.error('checkWorker2.js', e);
throw e;
logger.error(e);
}
}
checkWorker2();
3 changes: 1 addition & 2 deletions checkWorker3.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ async function checkWorker3() {
logger.debug("Done");
return transfers;
} catch(e) {
logger.error('checkWorker3.js', e);
throw e;
logger.error(e);
}
}
checkWorker3();
54 changes: 24 additions & 30 deletions eventsStats.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,37 +37,31 @@ function compareDepositsForeign(home){
}

async function main(){
try {
const homeBridge = new web3Home.eth.Contract(HOME_ABI, HOME_BRIDGE_ADDRESS);
const foreignBridge = new web3Foreign.eth.Contract(FOREIGN_ABI, FOREIGN_BRIDGE_ADDRESS);
logger.debug("calling homeBridge.getPastEvents('Deposit')");
let homeDeposits = await homeBridge.getPastEvents('Deposit', {fromBlock: HOME_DEPLOYMENT_BLOCK});
logger.debug("calling foreignBridge.getPastEvents('Deposit')");
let foreignDeposits = await foreignBridge.getPastEvents('Deposit', {fromBlock: FOREIGN_DEPLOYMENT_BLOCK});
logger.debug("calling homeBridge.getPastEvents('Withdraw')");
let homeWithdrawals = await homeBridge.getPastEvents('Withdraw', {fromBlock: HOME_DEPLOYMENT_BLOCK});
logger.debug("calling foreignBridge.getPastEvents('Withdraw')");
let foreignWithdrawals = await foreignBridge.getPastEvents('Withdraw', {fromBlock: FOREIGN_DEPLOYMENT_BLOCK});

const onlyInHomeDeposits = homeDeposits.filter(compareDepositsHome(foreignDeposits))
const onlyInForeignDeposits = foreignDeposits.concat([]).filter(compareDepositsForeign(homeDeposits))
const homeBridge = new web3Home.eth.Contract(HOME_ABI, HOME_BRIDGE_ADDRESS);
const foreignBridge = new web3Foreign.eth.Contract(FOREIGN_ABI, FOREIGN_BRIDGE_ADDRESS);
logger.debug("calling homeBridge.getPastEvents('Deposit')");
let homeDeposits = await homeBridge.getPastEvents('Deposit', {fromBlock: HOME_DEPLOYMENT_BLOCK});
logger.debug("calling foreignBridge.getPastEvents('Deposit')");
let foreignDeposits = await foreignBridge.getPastEvents('Deposit', {fromBlock: FOREIGN_DEPLOYMENT_BLOCK});
logger.debug("calling homeBridge.getPastEvents('Withdraw')");
let homeWithdrawals = await homeBridge.getPastEvents('Withdraw', {fromBlock: HOME_DEPLOYMENT_BLOCK});
logger.debug("calling foreignBridge.getPastEvents('Withdraw')");
let foreignWithdrawals = await foreignBridge.getPastEvents('Withdraw', {fromBlock: FOREIGN_DEPLOYMENT_BLOCK});

const onlyInHomeWithdrawals = homeWithdrawals.filter(compareDepositsForeign(foreignWithdrawals))
const onlyInForeignWithdrawals = foreignWithdrawals.filter(compareDepositsHome(homeWithdrawals))

logger.debug("Done");
return {
onlyInHomeDeposits,
onlyInForeignDeposits,
onlyInHomeWithdrawals,
onlyInForeignWithdrawals,
lastChecked: Math.floor(Date.now() / 1000),
}
} catch(e) {
logger.error(e);
throw e;
}
const onlyInHomeDeposits = homeDeposits.filter(compareDepositsHome(foreignDeposits))
const onlyInForeignDeposits = foreignDeposits.concat([]).filter(compareDepositsForeign(homeDeposits))

const onlyInHomeWithdrawals = homeWithdrawals.filter(compareDepositsForeign(foreignWithdrawals))
const onlyInForeignWithdrawals = foreignWithdrawals.filter(compareDepositsHome(homeWithdrawals))

logger.debug("Done");
return {
onlyInHomeDeposits,
onlyInForeignDeposits,
onlyInHomeWithdrawals,
onlyInForeignWithdrawals,
lastChecked: Math.floor(Date.now() / 1000),
}
}

module.exports = main;
module.exports = main;
44 changes: 19 additions & 25 deletions getBalances.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,25 @@ const web3Foreign = new Web3(foreignProvider);
const ERC677_ABI = require('./abis/ERC677.abi');

async function main(){
try {
logger.debug('calling web3Home.eth.getBalance');
const homeBalance = await web3Home.eth.getBalance(HOME_BRIDGE_ADDRESS)
const tokenContract = new web3Foreign.eth.Contract(ERC677_ABI, POA20_ADDRESS);
logger.debug('calling tokenContract.methods.totalSupply()');
const totalSupply = await tokenContract.methods.totalSupply().call()
const homeBalanceBN = new BN(homeBalance)
const foreignTotalSupplyBN = new BN(totalSupply)
const diff = homeBalanceBN.minus(foreignTotalSupplyBN).toString(10)
logger.debug("Done");
return {
home: {
balance: Web3Utils.fromWei(homeBalance)
},
foreign: {
totalSupply: Web3Utils.fromWei(totalSupply),
},
balanceDiff: Number(Web3Utils.fromWei(diff)),
lastChecked: Math.floor(Date.now() / 1000)
}
} catch(e) {
logger.error(e);
throw e;
logger.debug('calling web3Home.eth.getBalance');
const homeBalance = await web3Home.eth.getBalance(HOME_BRIDGE_ADDRESS)
const tokenContract = new web3Foreign.eth.Contract(ERC677_ABI, POA20_ADDRESS);
logger.debug('calling tokenContract.methods.totalSupply()');
const totalSupply = await tokenContract.methods.totalSupply().call()
const homeBalanceBN = new BN(homeBalance)
const foreignTotalSupplyBN = new BN(totalSupply)
const diff = homeBalanceBN.minus(foreignTotalSupplyBN).toString(10)
logger.debug("Done");
return {
home: {
balance: Web3Utils.fromWei(homeBalance)
},
foreign: {
totalSupply: Web3Utils.fromWei(totalSupply),
},
balanceDiff: Number(Web3Utils.fromWei(diff)),
lastChecked: Math.floor(Date.now() / 1000)
}

}

module.exports = main;
module.exports = main;
78 changes: 36 additions & 42 deletions getShortEventStats.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,47 +23,41 @@ const FOREIGN_ABI = require('./abis/Foreign.abi')
const BRIDGE_VALIDATORS_ABI = require('./abis/BridgeValidators.abi');

async function main(){
try {
const homeBridge = new web3Home.eth.Contract(HOME_ABI, HOME_BRIDGE_ADDRESS);
const foreignBridge = new web3Foreign.eth.Contract(FOREIGN_ABI, FOREIGN_BRIDGE_ADDRESS);
logger.debug("calling homeBridge.methods.validatorContract().call()");
const validatorHomeAddress = await homeBridge.methods.validatorContract().call()
logger.debug("calling foreignBridge.methods.validatorContract().call()");
const validatorForeignAddress = await foreignBridge.methods.validatorContract().call()
const homeValidators = new web3Home.eth.Contract(BRIDGE_VALIDATORS_ABI, validatorHomeAddress);
const foreignValidators = new web3Foreign.eth.Contract(BRIDGE_VALIDATORS_ABI, validatorForeignAddress);
logger.debug("calling homeValidators.methods.requiredSignatures().call()");
const reqSigHome = await homeValidators.methods.requiredSignatures().call()
logger.debug("calling foreignValidators.methods.requiredSignatures().call()");
const reqSigForeign = await foreignValidators.methods.requiredSignatures().call()
logger.debug("calling homeBridge.getPastEvents('Deposit')");
let homeDeposits = await homeBridge.getPastEvents('Deposit', {fromBlock: HOME_DEPLOYMENT_BLOCK});
logger.debug("calling foreignBridge.getPastEvents('Deposit')");
let foreignDeposits = await foreignBridge.getPastEvents('Deposit', {fromBlock: FOREIGN_DEPLOYMENT_BLOCK});
logger.debug("calling homeBridge.getPastEvents('Withdraw')");
let homeWithdrawals = await homeBridge.getPastEvents('Withdraw', {fromBlock: HOME_DEPLOYMENT_BLOCK});
logger.debug("calling foreignBridge.getPastEvents('Withdraw')");
let foreignWithdrawals = await foreignBridge.getPastEvents('Withdraw', {fromBlock: FOREIGN_DEPLOYMENT_BLOCK});
logger.debug("Done");
return {
depositsDiff: homeDeposits.length - foreignDeposits.length,
withdrawalDiff: homeWithdrawals.length - foreignWithdrawals.length,
home: {
deposits: homeDeposits.length,
withdrawals: homeWithdrawals.length,
requiredSignatures: Number(reqSigHome)
},
foreign: {
deposits: foreignDeposits.length,
withdrawals: foreignWithdrawals.length,
requiredSignatures: Number(reqSigForeign)
},
requiredSignaturesMatch: reqSigHome === reqSigForeign
}
} catch(e) {
logger.error(e);
throw e;
const homeBridge = new web3Home.eth.Contract(HOME_ABI, HOME_BRIDGE_ADDRESS);
const foreignBridge = new web3Foreign.eth.Contract(FOREIGN_ABI, FOREIGN_BRIDGE_ADDRESS);
logger.debug("calling homeBridge.methods.validatorContract().call()");
const validatorHomeAddress = await homeBridge.methods.validatorContract().call()
logger.debug("calling foreignBridge.methods.validatorContract().call()");
const validatorForeignAddress = await foreignBridge.methods.validatorContract().call()
const homeValidators = new web3Home.eth.Contract(BRIDGE_VALIDATORS_ABI, validatorHomeAddress);
const foreignValidators = new web3Foreign.eth.Contract(BRIDGE_VALIDATORS_ABI, validatorForeignAddress);
logger.debug("calling homeValidators.methods.requiredSignatures().call()");
const reqSigHome = await homeValidators.methods.requiredSignatures().call()
logger.debug("calling foreignValidators.methods.requiredSignatures().call()");
const reqSigForeign = await foreignValidators.methods.requiredSignatures().call()
logger.debug("calling homeBridge.getPastEvents('Deposit')");
let homeDeposits = await homeBridge.getPastEvents('Deposit', {fromBlock: HOME_DEPLOYMENT_BLOCK});
logger.debug("calling foreignBridge.getPastEvents('Deposit')");
let foreignDeposits = await foreignBridge.getPastEvents('Deposit', {fromBlock: FOREIGN_DEPLOYMENT_BLOCK});
logger.debug("calling homeBridge.getPastEvents('Withdraw')");
let homeWithdrawals = await homeBridge.getPastEvents('Withdraw', {fromBlock: HOME_DEPLOYMENT_BLOCK});
logger.debug("calling foreignBridge.getPastEvents('Withdraw')");
let foreignWithdrawals = await foreignBridge.getPastEvents('Withdraw', {fromBlock: FOREIGN_DEPLOYMENT_BLOCK});
logger.debug("Done");
return {
depositsDiff: homeDeposits.length - foreignDeposits.length,
withdrawalDiff: homeWithdrawals.length - foreignWithdrawals.length,
home: {
deposits: homeDeposits.length,
withdrawals: homeWithdrawals.length,
requiredSignatures: Number(reqSigHome)
},
foreign: {
deposits: foreignDeposits.length,
withdrawals: foreignWithdrawals.length,
requiredSignatures: Number(reqSigForeign)
},
requiredSignaturesMatch: reqSigHome === reqSigForeign
}

}
module.exports = main;
module.exports = main;
Loading