@@ -62,9 +62,11 @@ class ReputationMiner {
62
62
if ( minerAddress ) {
63
63
this . realWallet = this . realProvider . getSigner ( minerAddress ) ;
64
64
} else {
65
+ // TODO: Check that this wallet can stake?
65
66
this . realWallet = new ethers . Wallet ( privateKey , this . realProvider ) ;
66
- console . log ( "Transactions will be signed from " , this . realWallet . address ) ;
67
+ this . minerAddress = this . realWallet . address ;
67
68
}
69
+ console . log ( `Transactions will be signed from ${ this . realWallet . address } ` ) ;
68
70
}
69
71
70
72
/**
@@ -1347,20 +1349,20 @@ class ReputationMiner {
1347
1349
* @param { Bool } saveHistoricalStates Whether to save historical (valid) states while syncing
1348
1350
* @return {Promise } A promise that resolves once the state is up-to-date
1349
1351
*/
1350
- async sync ( blockNumber , saveHistoricalStates = false ) {
1351
- if ( ! blockNumber ) {
1352
- throw new Error ( "Block number not supplied to sync" ) ;
1353
- }
1352
+ async sync ( blockNumber = 1 , saveHistoricalStates = false ) {
1353
+
1354
1354
// Get the events
1355
1355
const filter = this . colonyNetwork . filters . ReputationMiningCycleComplete ( null , null ) ;
1356
1356
filter . fromBlock = blockNumber ;
1357
1357
const events = await this . realProvider . getLogs ( filter ) ;
1358
1358
let localHash = await this . reputationTree . getRootHash ( ) ;
1359
1359
let applyLogs = false ;
1360
1360
1361
+ console . log ( `Beginning sync from block ${ blockNumber } with ${ events . length } cycles` )
1362
+
1361
1363
// Run through events backwards find the most recent one that we know...
1362
1364
let syncFromIndex = 0 ;
1363
- for ( let i = events . length - 1 ; i >= 0 ; i -= 1 ) {
1365
+ for ( let i = events . length - 1 ; i >= 0 ; i -= 1 ) {
1364
1366
const event = events [ i ] ;
1365
1367
const hash = event . data . slice ( 0 , 66 ) ;
1366
1368
const nLeaves = ethers . BigNumber . from ( `0x${ event . data . slice ( 66 , 130 ) } ` ) ;
@@ -1369,12 +1371,15 @@ class ReputationMiner {
1369
1371
if ( res . n === 1 ) {
1370
1372
// We know that state! We can just sync from the next one...
1371
1373
syncFromIndex = i + 1 ;
1374
+ localHash = hash ;
1372
1375
await this . loadState ( hash ) ;
1373
1376
applyLogs = true ;
1374
1377
break ;
1375
1378
}
1376
1379
}
1377
1380
1381
+ console . log ( `Syncing forward from index ${ syncFromIndex } with local hash ${ localHash } ` )
1382
+
1378
1383
// We're not going to apply the logs unless we're syncing from scratch (which is this if statement)
1379
1384
// or we find a hash that we recognise as our current state, and we're going to sync from there (which
1380
1385
// is the if statement at the end of the loop below
@@ -1383,8 +1388,10 @@ class ReputationMiner {
1383
1388
}
1384
1389
1385
1390
for ( let i = syncFromIndex ; i < events . length ; i += 1 ) {
1386
- console . log ( `${ new Date ( ) . toLocaleTimeString ( ) } : Syncing mining cycle ${ i + 1 } of ${ events . length } ...` )
1387
1391
const event = events [ i ] ;
1392
+ const time = new Date ( ) . toLocaleTimeString ( ) ;
1393
+ console . log ( `${ time } : Syncing mining cycle ${ i + 1 } of ${ events . length } , from block ${ event . blockNumber } and localHash ${ localHash } ` ) ;
1394
+
1388
1395
if ( i === 0 ) {
1389
1396
// If we are syncing from the very start of the reputation history, the block
1390
1397
// before the very first 'ReputationMiningCycleComplete' does not have an
@@ -1433,7 +1440,8 @@ class ReputationMiner {
1433
1440
localHash = await this . reputationTree . getRootHash ( ) ;
1434
1441
const localNLeaves = await this . nReputations ;
1435
1442
if ( localHash !== currentHash || ! currentNLeaves . eq ( localNLeaves ) ) {
1436
- console . log ( "ERROR: Sync failed and did not recover" ) ;
1443
+ console . log ( `Error: Sync failed and did not recover, final hash does not match ${ currentHash } .` ) ;
1444
+ console . log ( "If the miner has been syncing for a while, try restarting, as the mining cycle may have advanced." ) ;
1437
1445
} else {
1438
1446
console . log ( "Sync successful, even if there were warnings above" ) ;
1439
1447
}
@@ -1505,6 +1513,8 @@ class ReputationMiner {
1505
1513
const currentStateHash = await this . reputationTree . getRootHash ( ) ;
1506
1514
if ( currentStateHash !== reputationRootHash ) {
1507
1515
console . log ( "WARNING: The supplied state failed to be recreated successfully. Are you sure it was saved?" ) ;
1516
+ } else {
1517
+ console . log ( `Reputation state ${ reputationRootHash } was loaded successfully.` ) ;
1508
1518
}
1509
1519
}
1510
1520
0 commit comments