Skip to content

Commit babe370

Browse files
committed
Additional updates to reputation miner
1 parent 73bd266 commit babe370

File tree

4 files changed

+25
-13
lines changed

4 files changed

+25
-13
lines changed

.gitignore

+2-3
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ ganache-accounts.json
2020
.vscode/
2121
yarn-error.log
2222
reputations.json
23-
reputationStates.sqlite
24-
reputationStates.sqlite-shm
25-
reputationStates.sqlite-wal
2623
truffle-security-output.json
2724
.coverage_contracts
2825
etherrouter-address.json
2926
ganache-chain-db
27+
.DS_Store
28+
*.sqlite*

packages/reputation-miner/ReputationMiner.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class ReputationMiner {
6262
this.minerAddress = this.realWallet.address;
6363
// TODO: Check that this wallet can stake?
6464
this.minerAddress = this.realWallet.address;
65-
console.log("Transactions will be signed from ", this.realWallet.address);
65+
console.log(`Transactions will be signed from ${this.realWallet.address}`);
6666
}
6767
}
6868

@@ -1254,6 +1254,8 @@ class ReputationMiner {
12541254
if (!blockNumber) {
12551255
throw new Error("Block number not supplied to sync");
12561256
}
1257+
console.log(`Beginning sync from block ${blockNumber}`)
1258+
12571259
// Get the events
12581260
const filter = this.colonyNetwork.filters.ReputationMiningCycleComplete(null, null);
12591261
filter.fromBlock = blockNumber;
@@ -1263,7 +1265,7 @@ class ReputationMiner {
12631265

12641266
// Run through events backwards find the most recent one that we know...
12651267
let syncFromIndex = 0;
1266-
for (let i = events.length - 1 ; i >= 0 ; i -= 1){
1268+
for (let i = events.length - 1 ; i >= 0 ; i -= 1) {
12671269
const event = events[i];
12681270
const hash = event.data.slice(0, 66);
12691271
const nLeaves = ethers.BigNumber.from(`0x${event.data.slice(66, 130)}`);
@@ -1286,8 +1288,10 @@ class ReputationMiner {
12861288
}
12871289

12881290
for (let i = syncFromIndex; i < events.length; i += 1) {
1289-
console.log(`${new Date().toLocaleTimeString()}: Syncing mining cycle ${i + 1} of ${events.length}...`)
12901291
const event = events[i];
1292+
console.log(
1293+
`${new Date().toLocaleTimeString()}: Syncing mining cycle ${i + 1} of ${events.length}, from block ${event.blockNumber} and localHash ${localHash}`
1294+
);
12911295
if (i === 0) {
12921296
// If we are syncing from the very start of the reputation history, the block
12931297
// before the very first 'ReputationMiningCycleComplete' does not have an
@@ -1327,7 +1331,8 @@ class ReputationMiner {
13271331
localHash = await this.reputationTree.getRootHash();
13281332
const localNLeaves = await this.nReputations;
13291333
if (localHash !== currentHash || !currentNLeaves.eq(localNLeaves)) {
1330-
console.log("ERROR: Sync failed and did not recover");
1334+
console.log(`Error: Sync failed and did not recover, final hash does not match ${currentHash}.`);
1335+
console.log("If the miner has been syncing for a while, try restarting, as the mining cycle may have advanced.");
13311336
} else {
13321337
console.log("Sync successful, even if there were warnings above");
13331338
}
@@ -1401,6 +1406,8 @@ class ReputationMiner {
14011406
const currentStateHash = await this.reputationTree.getRootHash();
14021407
if (currentStateHash !== reputationRootHash) {
14031408
console.log("WARNING: The supplied state failed to be recreated successfully. Are you sure it was saved?");
1409+
} else {
1410+
console.log(`Reputation state ${reputationRootHash} was loaded successfully.`);
14041411
}
14051412
}
14061413

packages/reputation-miner/ReputationMinerClient.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ class ReputationMinerClient {
220220
* @param {string} colonyNetworkAddress The address of the current `ColonyNetwork` contract
221221
* @return {Promise}
222222
*/
223-
async initialise(colonyNetworkAddress, startingBlock) {
223+
async initialise(colonyNetworkAddress, startingBlock, startingHash) {
224224
this.resolveBlockChecksFinished = undefined;
225225
await this._miner.initialise(colonyNetworkAddress);
226226

@@ -234,6 +234,9 @@ class ReputationMinerClient {
234234
await this._miner.loadState(latestReputationHash);
235235
if (this._miner.nReputations.eq(0)) {
236236
this._adapter.log("Latest state not found - need to sync");
237+
if (startingHash !== undefined) {
238+
await this._miner.loadState(startingHash);
239+
}
237240
await this._miner.sync(startingBlock, true);
238241
}
239242

@@ -422,7 +425,7 @@ class ReputationMinerClient {
422425
const {entryIndex} = this.best12Submissions[this.submissionIndex];
423426
const canSubmit = await this._miner.submissionPossible(entryIndex);
424427
if (canSubmit) {
425-
this._adapter.log("⏰ Looks like it's time to submit an entry to the current cycle");
428+
this._adapter.log(`⏰ ${new Date().toLocaleTimeString()}: Looks like it's time to submit an entry to the current cycle`);
426429
this.submissionIndex += 1;
427430
await this.updateGasEstimate('average');
428431
await this.submitEntry(entryIndex);
@@ -688,7 +691,7 @@ class ReputationMinerClient {
688691

689692
async submitEntry(entryIndex) {
690693
const rootHash = await this._miner.getRootHash();
691-
this._adapter.log(`#️⃣ Miner ${this._miner.minerAddress} submitting new reputation hash ${rootHash} at entry index ${entryIndex.toNumber()}`);
694+
this._adapter.log(`#️⃣ Submitting new reputation hash ${rootHash} at entry index ${entryIndex.toNumber()}`);
692695

693696
// Submit hash
694697
let submitRootHashTx = await this._miner.submitRootHash(entryIndex);
@@ -706,7 +709,7 @@ class ReputationMinerClient {
706709
const addr = await this._miner.colonyNetwork.getReputationMiningCycle(true);
707710
const repCycle = new ethers.Contract(addr, this._miner.repCycleContractDef.abi, this._miner.realWallet);
708711

709-
this._adapter.log("⏰ Looks like it's time to confirm the new hash");
712+
this._adapter.log(`⏰ ${new Date().toLocaleTimeString()}: Looks like it's time to confirm the new hash`);
710713
// Confirm hash
711714
const [round] = await this._miner.getMySubmissionRoundAndIndex();
712715
if (round && round.gte(0)) {

packages/reputation-miner/bin/index.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const { argv } = require("yargs")
88
.option('privateKey', {string:true})
99
.option('colonyNetworkAddress', {string:true})
1010
.option('minerAddress', {string:true})
11+
.option('startingHash', {string:true})
1112
.option('providerAddress', {type: "array", default: []});
1213
const ethers = require("ethers");
1314
const backoff = require("exponential-backoff").backOff;
@@ -33,6 +34,7 @@ const {
3334
oraclePort,
3435
processingDelay,
3536
adapterLabel,
37+
startingHash,
3638
} = argv;
3739

3840
class RetryProvider extends ethers.providers.StaticJsonRpcProvider {
@@ -53,7 +55,7 @@ class RetryProvider extends ethers.providers.StaticJsonRpcProvider {
5355
return backoff(() => super.getNetwork(), {retry: RetryProvider.attemptCheck});
5456
}
5557

56-
// This should return a Promise (and may throw erros)
58+
// This should return a Promise (and may throw errors)
5759
// method is the method name (e.g. getBalance) and params is an
5860
// object with normalized values passed in, depending on the method
5961
perform(method, params) {
@@ -118,4 +120,5 @@ const client = new ReputationMinerClient({
118120
oraclePort,
119121
processingDelay
120122
});
121-
client.initialise(colonyNetworkAddress, syncFrom);
123+
124+
client.initialise(colonyNetworkAddress, syncFrom, startingHash);

0 commit comments

Comments
 (0)