Browse Source
Use AtomicTimer for more accurate local solution rate
pull/4/head
Jack Grigg
7 years ago
No known key found for this signature in database
GPG Key ID: 6A6914DAFBEA00DA
3 changed files with
10 additions and
7 deletions
-
src/metrics.cpp
-
src/metrics.h
-
src/miner.cpp
|
|
@ -64,6 +64,7 @@ AtomicCounter transactionsValidated; |
|
|
|
AtomicCounter ehSolverRuns; |
|
|
|
AtomicCounter solutionTargetChecks; |
|
|
|
AtomicCounter minedBlocks; |
|
|
|
AtomicTimer miningTimer; |
|
|
|
|
|
|
|
boost::synchronized_value<std::list<uint256>> trackedBlocks; |
|
|
|
|
|
|
@ -90,14 +91,9 @@ int64_t GetUptime() |
|
|
|
return GetTime() - *nNodeStartTime; |
|
|
|
} |
|
|
|
|
|
|
|
double GetLocalSolPS_INTERNAL(int64_t uptime) |
|
|
|
{ |
|
|
|
return uptime > 0 ? (double)solutionTargetChecks.get() / uptime : 0; |
|
|
|
} |
|
|
|
|
|
|
|
double GetLocalSolPS() |
|
|
|
{ |
|
|
|
return GetLocalSolPS_INTERNAL(GetUptime()); |
|
|
|
return miningTimer.rate(solutionTargetChecks); |
|
|
|
} |
|
|
|
|
|
|
|
void TriggerRefresh() |
|
|
@ -240,7 +236,7 @@ int printMetrics(size_t cols, bool mining) |
|
|
|
} |
|
|
|
|
|
|
|
if (mining && loaded) { |
|
|
|
double solps = GetLocalSolPS_INTERNAL(uptime); |
|
|
|
double solps = GetLocalSolPS(); |
|
|
|
std::string strSolps = strprintf("%.4f Sol/s", solps); |
|
|
|
std::cout << "- " << strprintf(_("You have contributed %s on average to the network solution rate."), strSolps) << std::endl; |
|
|
|
std::cout << "- " << strprintf(_("You have completed %d Equihash solver runs."), ehSolverRuns.get()) << std::endl; |
|
|
|
|
|
@ -55,6 +55,7 @@ public: |
|
|
|
extern AtomicCounter transactionsValidated; |
|
|
|
extern AtomicCounter ehSolverRuns; |
|
|
|
extern AtomicCounter solutionTargetChecks; |
|
|
|
extern AtomicTimer miningTimer; |
|
|
|
|
|
|
|
void TrackMinedBlock(uint256 hash); |
|
|
|
|
|
|
|
|
|
@ -528,12 +528,14 @@ void static BitcoinMiner() |
|
|
|
cancelSolver = true; |
|
|
|
} |
|
|
|
); |
|
|
|
miningTimer.start(); |
|
|
|
|
|
|
|
try { |
|
|
|
while (true) { |
|
|
|
if (chainparams.MiningRequiresPeers()) { |
|
|
|
// Busy-wait for the network to come online so we don't waste time mining
|
|
|
|
// on an obsolete chain. In regtest mode we expect to fly solo.
|
|
|
|
miningTimer.stop(); |
|
|
|
do { |
|
|
|
bool fvNodesEmpty; |
|
|
|
{ |
|
|
@ -544,6 +546,7 @@ void static BitcoinMiner() |
|
|
|
break; |
|
|
|
MilliSleep(1000); |
|
|
|
} while (true); |
|
|
|
miningTimer.start(); |
|
|
|
} |
|
|
|
|
|
|
|
//
|
|
|
@ -721,16 +724,19 @@ void static BitcoinMiner() |
|
|
|
} |
|
|
|
catch (const boost::thread_interrupted&) |
|
|
|
{ |
|
|
|
miningTimer.stop(); |
|
|
|
c.disconnect(); |
|
|
|
LogPrintf("ZcashMiner terminated\n"); |
|
|
|
throw; |
|
|
|
} |
|
|
|
catch (const std::runtime_error &e) |
|
|
|
{ |
|
|
|
miningTimer.stop(); |
|
|
|
c.disconnect(); |
|
|
|
LogPrintf("ZcashMiner runtime error: %s\n", e.what()); |
|
|
|
return; |
|
|
|
} |
|
|
|
miningTimer.stop(); |
|
|
|
c.disconnect(); |
|
|
|
} |
|
|
|
|
|
|
|