Use AtomicTimer for more accurate local solution rate
This commit is contained in:
@@ -64,6 +64,7 @@ AtomicCounter transactionsValidated;
|
|||||||
AtomicCounter ehSolverRuns;
|
AtomicCounter ehSolverRuns;
|
||||||
AtomicCounter solutionTargetChecks;
|
AtomicCounter solutionTargetChecks;
|
||||||
AtomicCounter minedBlocks;
|
AtomicCounter minedBlocks;
|
||||||
|
AtomicTimer miningTimer;
|
||||||
|
|
||||||
boost::synchronized_value<std::list<uint256>> trackedBlocks;
|
boost::synchronized_value<std::list<uint256>> trackedBlocks;
|
||||||
|
|
||||||
@@ -90,14 +91,9 @@ int64_t GetUptime()
|
|||||||
return GetTime() - *nNodeStartTime;
|
return GetTime() - *nNodeStartTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
double GetLocalSolPS_INTERNAL(int64_t uptime)
|
|
||||||
{
|
|
||||||
return uptime > 0 ? (double)solutionTargetChecks.get() / uptime : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
double GetLocalSolPS()
|
double GetLocalSolPS()
|
||||||
{
|
{
|
||||||
return GetLocalSolPS_INTERNAL(GetUptime());
|
return miningTimer.rate(solutionTargetChecks);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TriggerRefresh()
|
void TriggerRefresh()
|
||||||
@@ -240,7 +236,7 @@ int printMetrics(size_t cols, bool mining)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (mining && loaded) {
|
if (mining && loaded) {
|
||||||
double solps = GetLocalSolPS_INTERNAL(uptime);
|
double solps = GetLocalSolPS();
|
||||||
std::string strSolps = strprintf("%.4f Sol/s", solps);
|
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 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;
|
std::cout << "- " << strprintf(_("You have completed %d Equihash solver runs."), ehSolverRuns.get()) << std::endl;
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ public:
|
|||||||
extern AtomicCounter transactionsValidated;
|
extern AtomicCounter transactionsValidated;
|
||||||
extern AtomicCounter ehSolverRuns;
|
extern AtomicCounter ehSolverRuns;
|
||||||
extern AtomicCounter solutionTargetChecks;
|
extern AtomicCounter solutionTargetChecks;
|
||||||
|
extern AtomicTimer miningTimer;
|
||||||
|
|
||||||
void TrackMinedBlock(uint256 hash);
|
void TrackMinedBlock(uint256 hash);
|
||||||
|
|
||||||
|
|||||||
@@ -528,12 +528,14 @@ void static BitcoinMiner()
|
|||||||
cancelSolver = true;
|
cancelSolver = true;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
miningTimer.start();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
while (true) {
|
while (true) {
|
||||||
if (chainparams.MiningRequiresPeers()) {
|
if (chainparams.MiningRequiresPeers()) {
|
||||||
// Busy-wait for the network to come online so we don't waste time mining
|
// 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.
|
// on an obsolete chain. In regtest mode we expect to fly solo.
|
||||||
|
miningTimer.stop();
|
||||||
do {
|
do {
|
||||||
bool fvNodesEmpty;
|
bool fvNodesEmpty;
|
||||||
{
|
{
|
||||||
@@ -544,6 +546,7 @@ void static BitcoinMiner()
|
|||||||
break;
|
break;
|
||||||
MilliSleep(1000);
|
MilliSleep(1000);
|
||||||
} while (true);
|
} while (true);
|
||||||
|
miningTimer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -721,16 +724,19 @@ void static BitcoinMiner()
|
|||||||
}
|
}
|
||||||
catch (const boost::thread_interrupted&)
|
catch (const boost::thread_interrupted&)
|
||||||
{
|
{
|
||||||
|
miningTimer.stop();
|
||||||
c.disconnect();
|
c.disconnect();
|
||||||
LogPrintf("ZcashMiner terminated\n");
|
LogPrintf("ZcashMiner terminated\n");
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
catch (const std::runtime_error &e)
|
catch (const std::runtime_error &e)
|
||||||
{
|
{
|
||||||
|
miningTimer.stop();
|
||||||
c.disconnect();
|
c.disconnect();
|
||||||
LogPrintf("ZcashMiner runtime error: %s\n", e.what());
|
LogPrintf("ZcashMiner runtime error: %s\n", e.what());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
miningTimer.stop();
|
||||||
c.disconnect();
|
c.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user