diff --git a/src/metrics.cpp b/src/metrics.cpp index e10e5cf8d..39050f681 100644 --- a/src/metrics.cpp +++ b/src/metrics.cpp @@ -25,6 +25,7 @@ #include extern int64_t ASSETCHAINS_TIMELOCKGTE; +extern uint32_t ASSETCHAINS_ALGO, ASSETCHAINS_VERUSHASH; int64_t komodo_block_unlocktime(uint32_t nHeight); void AtomicTimer::start() @@ -74,8 +75,21 @@ double AtomicTimer::rate(const AtomicCounter& count) CCriticalSection cs_metrics; +double AtomicTimer::rate(const int64_t count) +{ + std::unique_lock lock(mtx); + LOCK(cs_metrics); + int64_t duration = total_time; + if (threads > 0) { + // Timer is running, so get the latest count + duration += GetTime() - start_time; + } + return duration > 0 ? (double)count / duration : 0; +} + boost::synchronized_value nNodeStartTime; boost::synchronized_value nNextRefresh; +int64_t nHashCount; AtomicCounter transactionsValidated; AtomicCounter ehSolverRuns; AtomicCounter solutionTargetChecks; @@ -109,7 +123,12 @@ int64_t GetUptime() double GetLocalSolPS() { - return miningTimer.rate(solutionTargetChecks); + if (ASSETCHAINS_ALGO == ASSETCHAINS_VERUSHASH) + { + return miningTimer.rate(nHashCount); + } + else + return miningTimer.rate(solutionTargetChecks); } int EstimateNetHeightInner(int height, int64_t tipmediantime, diff --git a/src/metrics.h b/src/metrics.h index 65d88ce84..0fc03bf8a 100644 --- a/src/metrics.h +++ b/src/metrics.h @@ -8,6 +8,8 @@ #include #include +extern int64_t nHashCount; + struct AtomicCounter { std::atomic value; @@ -52,6 +54,8 @@ public: uint64_t threadCount(); double rate(const AtomicCounter& count); + double rate(const int64_t count); + }; extern AtomicCounter transactionsValidated; diff --git a/src/miner.cpp b/src/miner.cpp index d8590e9bc..4854b9a28 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -107,6 +107,7 @@ void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, #include "komodo_defs.h" +extern CCriticalSection cs_metrics; extern int32_t ASSETCHAINS_SEED,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAIN_INIT,KOMODO_INITDONE,KOMODO_ON_DEMAND,KOMODO_INITDONE,KOMODO_PASSPORT_INITDONE; extern uint64_t ASSETCHAINS_COMMISSION, ASSETCHAINS_STAKED; extern uint64_t ASSETCHAINS_REWARD[ASSETCHAINS_MAX_ERAS], ASSETCHAINS_TIMELOCKGTE, ASSETCHAINS_NONCEMASK[]; @@ -1154,18 +1155,12 @@ void static BitcoinMiner_noeq() CVerusHash &vh = ss.GetState(); uint256 hashResult = uint256(); vh.ClearExtra(); - int64_t count = ASSETCHAINS_NONCEMASK[ASSETCHAINS_ALGO] + 1; + int64_t i, count = ASSETCHAINS_NONCEMASK[ASSETCHAINS_ALGO] + 1; int64_t hashesToGo = ASSETCHAINS_HASHESPERROUND[ASSETCHAINS_ALGO]; - // for speed check 4 giga hash at a time - for (int64_t i = 0; i < count; i++) + // for speed check NONCEMASK at a time + for (i = 0; i < count; i++) { - solutionTargetChecks.increment(); - - // Update nNonce - //ss.buf.charBuf[108] = *((unsigned char *)&(pblock->nNonce)) = i & 0xff; - //ss.buf.charBuf[109] = *(((unsigned char *)&(pblock->nNonce))+1) = (i >> 8) & 0xff; - //ss.buf.charBuf[110] = *(((unsigned char *)&(pblock->nNonce))+2) = (i >> 16) & 0xff; *extraPtr = i; vh.ExtraHash((unsigned char *)&hashResult); @@ -1218,6 +1213,11 @@ void static BitcoinMiner_noeq() } } + { + LOCK(cs_metrics); + nHashCount += i; + } + // Check for stop or if block needs to be rebuilt boost::this_thread::interruption_point();