]> Git Repo - VerusCoin.git/blobdiff - src/metrics.cpp
Build fix
[VerusCoin.git] / src / metrics.cpp
index 1fe7660b33f30e6393f02bf67816d9e846e432a6..fd59bf92e6d4537f58086623d8c28fcaab45635d 100644 (file)
 #include <boost/thread.hpp>
 #include <boost/thread/synchronized_value.hpp>
 #include <string>
-#ifdef WIN32
+#ifdef _WIN32
 #include <io.h>
+#include <windows.h>
 #else
 #include <sys/ioctl.h>
 #endif
 #include <unistd.h>
 
+extern uint64_t ASSETCHAINS_TIMELOCKGTE;
+extern uint32_t ASSETCHAINS_ALGO, ASSETCHAINS_VERUSHASH;
+int64_t komodo_block_unlocktime(uint32_t nHeight);
+
 void AtomicTimer::start()
 {
     std::unique_lock<std::mutex> lock(mtx);
@@ -69,15 +74,58 @@ double AtomicTimer::rate(const AtomicCounter& count)
     return duration > 0 ? (double)count.get() / duration : 0;
 }
 
-static CCriticalSection cs_metrics;
-
-static boost::synchronized_value<int64_t> nNodeStartTime;
-static boost::synchronized_value<int64_t> nNextRefresh;
+boost::synchronized_value<int64_t> nNodeStartTime;
+boost::synchronized_value<int64_t> nNextRefresh;
 AtomicCounter transactionsValidated;
 AtomicCounter ehSolverRuns;
 AtomicCounter solutionTargetChecks;
 static AtomicCounter minedBlocks;
-AtomicTimer miningTimer;
+PerfCounterTimer miningTimer;
+CCriticalSection cs_metrics;
+
+double AtomicTimer::rate(const int64_t &count)
+{
+    std::unique_lock<std::mutex> 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;
+}
+
+double PerfCounterTimer::rate()
+{
+    return AtomicTimer::rate(counter);
+}
+
+double PerfCounterTimer::rate(const AtomicCounter &count)
+{
+    return AtomicTimer::rate(count);
+}
+
+double PerfCounterTimer::rate(const int64_t &count)
+{
+    return AtomicTimer::rate(count);
+}
+
+void PerfCounterTimer::clear()
+{
+    std::unique_lock<std::mutex> lock(mtx);
+    if (!threads)
+    {
+        counter = 0;
+        start_time = GetTime();
+        total_time = 0;
+    }
+}
+
+int64_t PerfCounterTimer::operator+=(int64_t operand)
+{
+    std::unique_lock<std::mutex> lock(mtx);
+    return counter += operand;
+}
 
 static boost::synchronized_value<std::list<uint256>> trackedBlocks;
 
@@ -106,7 +154,12 @@ int64_t GetUptime()
 
 double GetLocalSolPS()
 {
-    return miningTimer.rate(solutionTargetChecks);
+    if (ASSETCHAINS_ALGO == ASSETCHAINS_VERUSHASH)
+    {
+        return miningTimer.rate();
+    }
+    else
+        return miningTimer.rate(solutionTargetChecks);
 }
 
 int EstimateNetHeight(const Consensus::Params& params, int currentHeadersHeight, int64_t currentHeadersTime)
@@ -207,7 +260,7 @@ int printStats(bool mining)
     {
         LOCK2(cs_main, cs_vNodes);
         height = chainActive.Height();
-        currentHeadersHeight = pindexBestHeader ? pindexBestHeader->nHeight: -1;
+        currentHeadersHeight = pindexBestHeader ? pindexBestHeader->GetHeight(): -1;
         currentHeadersTime = pindexBestHeader ? pindexBestHeader->nTime : 0;
         connections = vNodes.size();
         netsolps = GetNetworkHashPS(120, -1);
@@ -328,12 +381,14 @@ int printMetrics(size_t cols, bool mining)
                 auto hash = *it;
                 if (mapBlockIndex.count(hash) > 0 &&
                         chainActive.Contains(mapBlockIndex[hash])) {
-                    int height = mapBlockIndex[hash]->nHeight;
+                    int height = mapBlockIndex[hash]->GetHeight();
                     CAmount subsidy = GetBlockSubsidy(height, consensusParams);
                     if ((height > 0) && (height <= consensusParams.GetLastFoundersRewardBlockHeight(height))) {
                         subsidy -= subsidy/5;
                     }
-                    if (std::max(0, COINBASE_MATURITY - (tipHeight - height)) > 0) {
+
+                    if ((std::max(0, COINBASE_MATURITY - (tipHeight - height)) > 0) ||
+                        (tipHeight < komodo_block_unlocktime(height) && subsidy >= ASSETCHAINS_TIMELOCKGTE)) {
                         immature += subsidy;
                     } else {
                         mature += subsidy;
@@ -475,7 +530,7 @@ void ThreadShowMetricsScreen()
 
         // Get current window size
         if (isTTY) {
-#ifdef WIN32
+#ifdef _WIN32
             CONSOLE_SCREEN_BUFFER_INFO csbi;
             if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi) != 0) {
                 cols = csbi.srWindow.Right - csbi.srWindow.Left + 1;
This page took 0.027531 seconds and 4 git commands to generate.