Miner stats didn't work in RPC and UI
authorCryptoManiac <balthazar@yandex.ru>
Tue, 14 Apr 2015 08:36:54 +0000 (11:36 +0300)
committerCryptoManiac <balthazar@yandex.ru>
Tue, 14 Apr 2015 08:36:54 +0000 (11:36 +0300)
src/miner.cpp
src/qt/bitcoingui.cpp
src/qt/walletmodel.cpp
src/qt/walletmodel.h
src/rpcmining.cpp
src/wallet.cpp
src/wallet.h

index 4f0130a..02b38bf 100644 (file)
@@ -17,6 +17,7 @@ using namespace std;
 
 int64_t nReserveBalance = 0;
 static unsigned int nMaxStakeSearchInterval = 60;
+uint64_t nStakeInputsMapSize = 0;
 
 int static FormatHashBlocks(void* pbuffer, unsigned int len)
 {
@@ -600,8 +601,10 @@ bool FillMap(CWallet *pwallet, uint32_t nUpperTime, MidstateMap &inputsMap)
             inputsMap[key] = make_pair(ctx, make_pair(pcoin->first->nTime, pcoin->first->vout[pcoin->second].nValue));
         }
 
+        nStakeInputsMapSize = inputsMap.size();
+
         if (fDebug)
-            printf("Stake miner: %" PRIszu " precalculated contexts created\n", inputsMap.size());
+            printf("Stake miner: map of %" PRIu64 " precalculated contexts has been created\n", nStakeInputsMapSize);
     }
 
     return true;
index a191a8d..c33f76c 100644 (file)
@@ -70,6 +70,7 @@
 #include <iostream>
 
 extern bool fWalletUnlockMintOnly;
+extern uint64_t nStakeInputsMapSize;
 
 BitcoinGUI::BitcoinGUI(QWidget *parent):
     QMainWindow(parent),
@@ -703,33 +704,13 @@ void BitcoinGUI::updateMining()
         return;
     }
 
-    float nKernelsRate = 0, nCoinDaysRate = 0;
-    walletModel->getStakeStats(nKernelsRate, nCoinDaysRate);
-
-    if (nKernelsRate > 0)
+    if (nStakeInputsMapSize > 0)
     {
         labelMiningIcon->setPixmap(QIcon(":/icons/mining_active").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
 
         uint64_t nNetworkWeight = clientModel->getPoSKernelPS();
-/*
-        double dDifficulty = clientModel->getDifficulty(true);
-        QString msg;
-
-        int nApproxTime = 4294967297 * dDifficulty / nTotalWeight;
-
-        if (nApproxTime < 60)
-            msg = tr("%n second(s)", "", nApproxTime);
-        else if (nApproxTime < 60*60)
-            msg = tr("%n minute(s)", "", nApproxTime / 60);
-        else if (nApproxTime < 24*60*60)
-            msg = tr("%n hour(s)", "", nApproxTime / 3600);
-        else
-            msg = tr("%n day(s)", "", nApproxTime / 86400);
-
-        labelMiningIcon->setToolTip(tr("Stake miner is active\nYour current stake weight is %1\nNetwork weight is %2\nAverage block generation time is %3").arg(nTotalWeight).arg(dNetworkWeight).arg(msg));
-*/
 
-        labelMiningIcon->setToolTip(QString("<nobr>")+tr("Stake miner is active<br>Kernel rate is %1 k/s<br>CD rate is %2 CD/s<br>Network weight is %3").arg(nKernelsRate).arg(nCoinDaysRate).arg(nNetworkWeight)+QString("<\nobr>"));
+        labelMiningIcon->setToolTip(QString("<nobr>")+tr("Stake miner is active<br>%1 inputs used the mining<br>Network weight is %3").arg(nStakeInputsMapSize).arg(nNetworkWeight)+QString("<\nobr>"));
     }
     else
         labelMiningIcon->setToolTip(tr("No suitable inputs were found"));
index f7658b0..4769fda 100644 (file)
@@ -332,11 +332,6 @@ bool WalletModel::changePassphrase(const SecureString &oldPass, const SecureStri
     return retval;
 }
 
-void WalletModel::getStakeStats(float &nKernelsRate, float &nCoinDaysRate)
-{
-    wallet->GetStakeStats(nKernelsRate, nCoinDaysRate);
-}
-
 void WalletModel::getStakeWeightFromValue(const int64_t& nTime, const int64_t& nValue, uint64_t& nWeight)
 {
     wallet->GetStakeWeightFromValue(nTime, nValue, nWeight);
index e0e1163..6aeace7 100644 (file)
@@ -103,7 +103,6 @@ public:
     bool dumpWallet(const QString &filename);
     bool importWallet(const QString &filename);
 
-    void getStakeStats(float &nKernelsRate, float &nCoinDaysRate);
     void getStakeWeightFromValue(const int64_t& nTime, const int64_t& nValue, uint64_t& nWeight);
 
     // RAI object for unlocking wallet, returned by requestUnlock()
index 28d6ed8..d5bc43b 100644 (file)
@@ -15,6 +15,7 @@ using namespace json_spirit;
 using namespace std;
 
 extern uint256 nPoWBase;
+extern uint64_t nStakeInputsMapSize;
 
 Value getsubsidy(const Array& params, bool fHelp)
 {
@@ -45,9 +46,6 @@ Value getmininginfo(const Array& params, bool fHelp)
             "getmininginfo\n"
             "Returns an object containing mining-related information.");
 
-    float nKernelsRate = 0, nCoinDaysRate = 0;
-    pwalletMain->GetStakeStats(nKernelsRate, nCoinDaysRate);
-
     Object obj, diff, weight;
     obj.push_back(Pair("blocks",        (int)nBestHeight));
     obj.push_back(Pair("currentblocksize",(uint64_t)nLastBlockSize));
@@ -64,11 +62,9 @@ Value getmininginfo(const Array& params, bool fHelp)
     obj.push_back(Pair("errors",        GetWarnings("statusbar")));
     obj.push_back(Pair("pooledtx",      (uint64_t)mempool.size()));
 
-    weight.push_back(Pair("kernelsrate",   nKernelsRate));
-    weight.push_back(Pair("cdaysrate",   nCoinDaysRate));
-    obj.push_back(Pair("stakestats", weight));
+    obj.push_back(Pair("stakeinputs", (uint64_t)nStakeInputsMapSize));
+    obj.push_back(Pair("stakeinterest",    (int64_t)GetProofOfStakeReward(0, GetLastBlockIndex(pindexBest, true)->nBits, GetLastBlockIndex(pindexBest, true)->nTime, true)));
 
-    obj.push_back(Pair("stakeinterest",    (uint64_t)GetProofOfStakeReward(0, GetLastBlockIndex(pindexBest, true)->nBits, GetLastBlockIndex(pindexBest, true)->nTime, true)));
     obj.push_back(Pair("testnet",       fTestNet));
     return obj;
 }
index bfa0e24..97648c8 100644 (file)
@@ -1697,40 +1697,6 @@ void CWallet::GetStakeWeightFromValue(const int64_t& nTime, const int64_t& nValu
     nWeight = bnCoinDayWeight.getuint64();
 }
 
-
-// NovaCoin: get current stake miner statistics
-void CWallet::GetStakeStats(float &nKernelsRate, float &nCoinDaysRate)
-{
-    static uint64_t nLastKernels = 0, nLastCoinDays = 0;
-    static float nLastKernelsRate = 0, nLastCoinDaysRate = 0;
-    static int64_t nLastTime = GetTime();
-
-    if (nKernelsTried < nLastKernels)
-    {
-        nLastKernels = 0;
-        nLastCoinDays = 0;
-
-        nLastTime = GetTime();
-    }
-
-    int64_t nInterval = GetTime() - nLastTime;
-    //if (nKernelsTried > 1000 && nInterval > 5)
-    if (nInterval > 10)
-    {
-        nKernelsRate = nLastKernelsRate = ( nKernelsTried - nLastKernels ) / (float) nInterval;
-        nCoinDaysRate = nLastCoinDaysRate = ( nCoinDaysTried - nLastCoinDays ) / (float) nInterval;
-
-        nLastKernels = nKernelsTried;
-        nLastCoinDays = nCoinDaysTried;
-        nLastTime = GetTime();
-    }
-    else
-    {
-        nKernelsRate = nLastKernelsRate;
-        nCoinDaysRate = nLastCoinDaysRate;
-    }
-}
-
 bool CWallet::MergeCoins(const int64_t& nAmount, const int64_t& nMinValue, const int64_t& nOutputValue, list<uint256>& listMerged)
 {
     int64_t nBalance = GetBalance();
index 9789c51..6071b91 100644 (file)
@@ -217,7 +217,6 @@ public:
     bool CreateTransaction(CScript scriptPubKey, int64_t nValue, CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, const CCoinControl *coinControl=NULL);
     bool CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey);
 
-    void GetStakeStats(float &nKernelsRate, float &nCoinDaysRate);
     void GetStakeWeightFromValue(const int64_t& nTime, const int64_t& nValue, uint64_t& nWeight);
     bool CreateCoinStake(uint256 &hashTx, uint32_t nOut, uint32_t nTime, uint32_t nBits, CTransaction &txNew, CKey& key);
     bool MergeCoins(const int64_t& nAmount, const int64_t& nMinValue, const int64_t& nMaxValue, std::list<uint256>& listMerged);