Track mined blocks to detect and report orphans and mining revenue
Part of #1713 Closes #1716
This commit is contained in:
parent
1feaefac51
commit
d793f94b8a
|
@ -36,6 +36,7 @@ class CMainParams : public CChainParams {
|
||||||
public:
|
public:
|
||||||
CMainParams() {
|
CMainParams() {
|
||||||
strNetworkID = "main";
|
strNetworkID = "main";
|
||||||
|
strCurrencyUnits = "ZEC";
|
||||||
consensus.fCoinbaseMustBeProtected = true;
|
consensus.fCoinbaseMustBeProtected = true;
|
||||||
consensus.nSubsidySlowStartInterval = 20000;
|
consensus.nSubsidySlowStartInterval = 20000;
|
||||||
consensus.nSubsidyHalvingInterval = 840000;
|
consensus.nSubsidyHalvingInterval = 840000;
|
||||||
|
@ -202,6 +203,7 @@ class CTestNetParams : public CMainParams {
|
||||||
public:
|
public:
|
||||||
CTestNetParams() {
|
CTestNetParams() {
|
||||||
strNetworkID = "test";
|
strNetworkID = "test";
|
||||||
|
strCurrencyUnits = "TAZ";
|
||||||
consensus.nMajorityEnforceBlockUpgrade = 51;
|
consensus.nMajorityEnforceBlockUpgrade = 51;
|
||||||
consensus.nMajorityRejectBlockOutdated = 75;
|
consensus.nMajorityRejectBlockOutdated = 75;
|
||||||
consensus.nMajorityWindow = 400;
|
consensus.nMajorityWindow = 400;
|
||||||
|
@ -287,6 +289,7 @@ class CRegTestParams : public CTestNetParams {
|
||||||
public:
|
public:
|
||||||
CRegTestParams() {
|
CRegTestParams() {
|
||||||
strNetworkID = "regtest";
|
strNetworkID = "regtest";
|
||||||
|
strCurrencyUnits = "REG";
|
||||||
consensus.fCoinbaseMustBeProtected = false;
|
consensus.fCoinbaseMustBeProtected = false;
|
||||||
consensus.nSubsidySlowStartInterval = 0;
|
consensus.nSubsidySlowStartInterval = 0;
|
||||||
consensus.nSubsidyHalvingInterval = 150;
|
consensus.nSubsidyHalvingInterval = 150;
|
||||||
|
|
|
@ -67,6 +67,7 @@ public:
|
||||||
int64_t PruneAfterHeight() const { return nPruneAfterHeight; }
|
int64_t PruneAfterHeight() const { return nPruneAfterHeight; }
|
||||||
unsigned int EquihashN() const { return nEquihashN; }
|
unsigned int EquihashN() const { return nEquihashN; }
|
||||||
unsigned int EquihashK() const { return nEquihashK; }
|
unsigned int EquihashK() const { return nEquihashK; }
|
||||||
|
std::string CurrencyUnits() const { return strCurrencyUnits; }
|
||||||
/** Make miner stop after a block is found. In RPC, don't return until nGenProcLimit blocks are generated */
|
/** Make miner stop after a block is found. In RPC, don't return until nGenProcLimit blocks are generated */
|
||||||
bool MineBlocksOnDemand() const { return fMineBlocksOnDemand; }
|
bool MineBlocksOnDemand() const { return fMineBlocksOnDemand; }
|
||||||
/** In the future use NetworkIDString() for RPC fields */
|
/** In the future use NetworkIDString() for RPC fields */
|
||||||
|
@ -99,6 +100,7 @@ protected:
|
||||||
std::vector<CDNSSeedData> vSeeds;
|
std::vector<CDNSSeedData> vSeeds;
|
||||||
std::vector<unsigned char> base58Prefixes[MAX_BASE58_TYPES];
|
std::vector<unsigned char> base58Prefixes[MAX_BASE58_TYPES];
|
||||||
std::string strNetworkID;
|
std::string strNetworkID;
|
||||||
|
std::string strCurrencyUnits;
|
||||||
CBlock genesis;
|
CBlock genesis;
|
||||||
std::vector<SeedSpec6> vFixedSeeds;
|
std::vector<SeedSpec6> vFixedSeeds;
|
||||||
bool fRequireRPCPassword = false;
|
bool fRequireRPCPassword = false;
|
||||||
|
|
|
@ -5,9 +5,11 @@
|
||||||
#include "metrics.h"
|
#include "metrics.h"
|
||||||
|
|
||||||
#include "chainparams.h"
|
#include "chainparams.h"
|
||||||
|
#include "main.h"
|
||||||
#include "ui_interface.h"
|
#include "ui_interface.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "utiltime.h"
|
#include "utiltime.h"
|
||||||
|
#include "utilmoneystr.h"
|
||||||
|
|
||||||
#include <boost/thread.hpp>
|
#include <boost/thread.hpp>
|
||||||
#include <boost/thread/synchronized_value.hpp>
|
#include <boost/thread/synchronized_value.hpp>
|
||||||
|
@ -20,10 +22,18 @@ AtomicCounter ehSolverRuns;
|
||||||
AtomicCounter solutionTargetChecks;
|
AtomicCounter solutionTargetChecks;
|
||||||
AtomicCounter minedBlocks;
|
AtomicCounter minedBlocks;
|
||||||
|
|
||||||
|
boost::synchronized_value<std::list<uint256>> trackedBlocks;
|
||||||
|
|
||||||
boost::synchronized_value<std::list<std::string>> messageBox;
|
boost::synchronized_value<std::list<std::string>> messageBox;
|
||||||
boost::synchronized_value<std::string> initMessage;
|
boost::synchronized_value<std::string> initMessage;
|
||||||
bool loaded = false;
|
bool loaded = false;
|
||||||
|
|
||||||
|
void TrackMinedBlock(uint256 hash)
|
||||||
|
{
|
||||||
|
minedBlocks.increment();
|
||||||
|
trackedBlocks->push_back(hash);
|
||||||
|
}
|
||||||
|
|
||||||
static bool metrics_ThreadSafeMessageBox(const std::string& message,
|
static bool metrics_ThreadSafeMessageBox(const std::string& message,
|
||||||
const std::string& caption,
|
const std::string& caption,
|
||||||
unsigned int style)
|
unsigned int style)
|
||||||
|
@ -121,8 +131,43 @@ int printMetrics(size_t cols, int64_t nStart, bool mining)
|
||||||
|
|
||||||
int mined = minedBlocks.get();
|
int mined = minedBlocks.get();
|
||||||
if (mined > 0) {
|
if (mined > 0) {
|
||||||
|
LOCK(cs_main);
|
||||||
|
boost::strict_lock_ptr<std::list<uint256>> u = trackedBlocks.synchronize();
|
||||||
|
auto consensusParams = Params().GetConsensus();
|
||||||
|
auto tipHeight = chainActive.Height();
|
||||||
|
std::string units = Params().CurrencyUnits();
|
||||||
|
|
||||||
|
// Update orphans and calculate subsidies
|
||||||
|
CAmount immature {0};
|
||||||
|
CAmount mature {0};
|
||||||
|
for (std::list<uint256>::iterator it = u->begin(); it != u->end(); it++) {
|
||||||
|
auto hash = *it;
|
||||||
|
if (mapBlockIndex.count(hash) > 0 &&
|
||||||
|
chainActive.Contains(mapBlockIndex[hash])) {
|
||||||
|
int height = mapBlockIndex[hash]->nHeight;
|
||||||
|
CAmount subsidy = GetBlockSubsidy(height, consensusParams);
|
||||||
|
if ((height > 0) && (height <= consensusParams.GetLastFoundersRewardBlockHeight())) {
|
||||||
|
subsidy -= subsidy/5;
|
||||||
|
}
|
||||||
|
if (std::max(0, COINBASE_MATURITY - (tipHeight - height)) > 0) {
|
||||||
|
immature += subsidy;
|
||||||
|
} else {
|
||||||
|
mature += subsidy;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
it = u->erase(it);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int orphaned = mined - u->size();
|
||||||
|
|
||||||
std::cout << "- " << strprintf(_("You have mined %d blocks!"), mined) << std::endl;
|
std::cout << "- " << strprintf(_("You have mined %d blocks!"), mined) << std::endl;
|
||||||
lines++;
|
std::cout << " "
|
||||||
|
<< strprintf(_("Orphaned: %d blocks, Immature: %u %s, Mature: %u %s"),
|
||||||
|
orphaned,
|
||||||
|
FormatMoney(immature), units,
|
||||||
|
FormatMoney(mature), units)
|
||||||
|
<< std::endl;
|
||||||
|
lines += 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
// Distributed under the MIT software license, see the accompanying
|
// Distributed under the MIT software license, see the accompanying
|
||||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
|
#include "uint256.h"
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
@ -26,7 +28,8 @@ struct AtomicCounter {
|
||||||
extern AtomicCounter transactionsValidated;
|
extern AtomicCounter transactionsValidated;
|
||||||
extern AtomicCounter ehSolverRuns;
|
extern AtomicCounter ehSolverRuns;
|
||||||
extern AtomicCounter solutionTargetChecks;
|
extern AtomicCounter solutionTargetChecks;
|
||||||
extern AtomicCounter minedBlocks;
|
|
||||||
|
void TrackMinedBlock(uint256 hash);
|
||||||
|
|
||||||
void ConnectMetricsScreen();
|
void ConnectMetricsScreen();
|
||||||
void ThreadShowMetricsScreen();
|
void ThreadShowMetricsScreen();
|
||||||
|
|
|
@ -438,7 +438,7 @@ static bool ProcessBlockFound(CBlock* pblock, CWallet& wallet, CReserveKey& rese
|
||||||
if (!ProcessNewBlock(state, NULL, pblock, true, NULL))
|
if (!ProcessNewBlock(state, NULL, pblock, true, NULL))
|
||||||
return error("ZcashMiner: ProcessNewBlock, block not accepted");
|
return error("ZcashMiner: ProcessNewBlock, block not accepted");
|
||||||
|
|
||||||
minedBlocks.increment();
|
TrackMinedBlock(pblock->GetHash());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -205,7 +205,6 @@ endloop:
|
||||||
CValidationState state;
|
CValidationState state;
|
||||||
if (!ProcessNewBlock(state, NULL, pblock, true, NULL))
|
if (!ProcessNewBlock(state, NULL, pblock, true, NULL))
|
||||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "ProcessNewBlock, block not accepted");
|
throw JSONRPCError(RPC_INTERNAL_ERROR, "ProcessNewBlock, block not accepted");
|
||||||
minedBlocks.increment();
|
|
||||||
++nHeight;
|
++nHeight;
|
||||||
blockHashes.push_back(pblock->GetHash().GetHex());
|
blockHashes.push_back(pblock->GetHash().GetHex());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue