Skip to content

Commit

Permalink
More real-world tweaks to error handling and logging
Browse files Browse the repository at this point in the history
  • Loading branch information
area committed Sep 10, 2021
1 parent 02a5714 commit 046c4bf
Show file tree
Hide file tree
Showing 6 changed files with 553 additions and 262 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
"eth-gas-reporter": "^0.2.15",
"ethereumjs-account": "^3.0.0",
"ethereumjs-util": "^7.0.0",
"ethers": "5.0.17",
"ethers": "5.4.6",
"ethlint": "^1.2.5",
"find-in-files": "^0.5.0",
"ganache-cli": "^6.10.1",
Expand Down
26 changes: 19 additions & 7 deletions packages/reputation-miner/ReputationMinerClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ class ReputationMinerClient {
* @return {Promise}
*/
async doBlockChecks(blockNumber) {
let repCycle;
try {
if (this.lockedForBlockProcessing) {
this.blockSeenWhileLocked = blockNumber;
Expand All @@ -324,7 +325,7 @@ class ReputationMinerClient {
const block = await this._miner.realProvider.getBlock(blockNumber);
const addr = await this._miner.colonyNetwork.getReputationMiningCycle(true);

const repCycle = new ethers.Contract(addr, this._miner.repCycleContractDef.abi, this._miner.realWallet);
repCycle = new ethers.Contract(addr, this._miner.repCycleContractDef.abi, this._miner.realWallet);
if (addr !== this.miningCycleAddress) {
// Then the cycle has completed since we last checked.
if (this.confirmTimeoutCheck) {
Expand Down Expand Up @@ -510,16 +511,26 @@ class ReputationMinerClient {
}
this.endDoBlockChecks();
} catch (err) {
this._adapter.error(`Error during block checks: ${err}`);
const repCycleCode = await this._miner.realProvider.getCode(repCycle.address);
// If it's out-of-ether...
if (err.toString().indexOf('does not have enough funds') >= 0 ) {
// This could obviously be much better in the future, but for now, we'll settle for this not triggering a restart loop.
this._adapter.error(`Block checks suspended due to not enough Ether. Send ether to \`${this._miner.minerAddress}\`, then restart the miner`);
} else if (this._exitOnError) {
process.exit(1);
// Note we don't call this.endDoBlockChecks here... this is a deliberate choice on my part; depending on what the error is,
// we might no longer be in a sane state, and might have only half-processed the reputation log, or similar. So playing it safe,
// and not unblocking the doBlockCheck function.
return;
}
if (repCycleCode === "0x") {
// The repcycle was probably advanced by another miner while we were trying to
// respond to it. That's fine, and we'll sort ourselves out on the next block.
this.endDoBlockChecks();
return;
}
this._adapter.error(`Error during block checks: ${err}`);
if (this._exitOnError) {
this._adapter.error(`Automatically restarting`);
process.exit(1);
// Note we don't call this.endDoBlockChecks here... this is a deliberate choice on my part; depending on what the error is,
// we might no longer be in a sane state, and might have only half-processed the reputation log, or similar. So playing it safe,
// and not unblocking the doBlockCheck function.
}
}
}
Expand Down Expand Up @@ -640,6 +651,7 @@ class ReputationMinerClient {
const [round] = await this._miner.getMySubmissionRoundAndIndex();
if (round && round.gte(0)) {
const gasEstimate = await repCycle.estimateGas.confirmNewHash(round);
await this.updateGasEstimate('average');

const confirmNewHashTx = await repCycle.confirmNewHash(round, { gasLimit: gasEstimate, gasPrice: this._miner.gasPrice });
this._adapter.log(`⛏️ Transaction waiting to be mined ${confirmNewHashTx.hash}`);
Expand Down
3 changes: 2 additions & 1 deletion packages/reputation-miner/adapters/discord.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class DiscordAdapter {
}

async error(output){
channel.send(`${this.label}${output}`);
channel.send(`${this.label}${output}`);
console.log(`${this.label}${output}`);
}
}

Expand Down
6 changes: 4 additions & 2 deletions packages/reputation-miner/bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,16 @@ class RetryProvider extends ethers.providers.JsonRpcProvider {
}

getNetwork(){
return backoff(() => super.getNetwork(), {retry: this.attemptCheck});
const that = this;
return backoff(() => super.getNetwork(), {retry: that.attemptCheck});
}

// This should return a Promise (and may throw erros)
// method is the method name (e.g. getBalance) and params is an
// object with normalized values passed in, depending on the method
perform(method, params) {
return backoff(() => super.perform(method, params), {retry: this.attemptCheck});
const that = this;
return backoff(() => super.perform(method, params), {retry: that.attemptCheck});
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/reputation-miner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"better-sqlite3": "^7.4.3",
"bn.js": "^5.0.0",
"discord.js": "^12.2.0",
"ethers": "^5.0.19",
"ethers": "^5.4.6",
"exponential-backoff": "^3.1.0",
"express": "^4.16.3",
"ganache-core": "^2.8.0",
Expand Down
Loading

0 comments on commit 046c4bf

Please sign in to comment.