Unify claimtrie tests, add some additional root hash checks #181
4 changed files with 67 additions and 1 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -45,6 +45,8 @@ src/qt/forms/ui_*.h
|
|||
|
||||
src/qt/test/moc*.cpp
|
||||
|
||||
dependencies/*
|
||||
|
||||
.deps
|
||||
.dirstamp
|
||||
.libs
|
||||
|
|
|
@ -479,6 +479,9 @@ void IncrementExtraNonce(CBlock* pblock, const CBlockIndex* pindexPrev, unsigned
|
|||
// Internal miner
|
||||
//
|
||||
|
||||
double dHashesPerSec = 0.0;
|
||||
int64_t nHPSTimerStart = 0;
|
||||
|
||||
static bool ProcessBlockFound(const CBlock* pblock, const CChainParams& chainparams)
|
||||
{
|
||||
LogPrintf("%s\n", pblock->ToString());
|
||||
|
@ -562,7 +565,10 @@ void static BitcoinMiner(const CChainParams& chainparams)
|
|||
uint256 hash;
|
||||
pblock->nNonce = 0;
|
||||
bool found = false;
|
||||
while (true) {
|
||||
while (true)
|
||||
{
|
||||
unsigned int nHashesDone = 0;
|
||||
|
||||
// Check if something found
|
||||
while (true)
|
||||
{
|
||||
|
@ -586,10 +592,42 @@ void static BitcoinMiner(const CChainParams& chainparams)
|
|||
}
|
||||
pblock->nNonce += 1;
|
||||
if ((pblock->nNonce & 0xFF) == 0)
|
||||
{
|
||||
nHashesDone = 0xFF+1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found)
|
||||
break;
|
||||
|
||||
// Meter hashes/sec
|
||||
static int64_t nHashCounter;
|
||||
if (nHPSTimerStart == 0)
|
||||
{
|
||||
nHPSTimerStart = GetTimeMillis();
|
||||
nHashCounter = 0;
|
||||
}
|
||||
else
|
||||
nHashCounter += nHashesDone;
|
||||
if (GetTimeMillis() - nHPSTimerStart > 4000)
|
||||
{
|
||||
static CCriticalSection cs;
|
||||
{
|
||||
LOCK(cs);
|
||||
if (GetTimeMillis() - nHPSTimerStart > 4000)
|
||||
{
|
||||
dHashesPerSec = 1000.0 * nHashCounter / (GetTimeMillis() - nHPSTimerStart);
|
||||
nHPSTimerStart = GetTimeMillis();
|
||||
nHashCounter = 0;
|
||||
static int64_t nLogTime;
|
||||
if (GetTime() - nLogTime > 30 * 60)
|
||||
{
|
||||
nLogTime = GetTime();
|
||||
LogPrintf("hashmeter %6.0f khash/s\n", dHashesPerSec/1000.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check for stop or if block needs to be rebuilt
|
||||
boost::this_thread::interruption_point();
|
||||
|
|
|
@ -37,4 +37,7 @@ CBlockTemplate* CreateNewBlock(const CChainParams& chainparams, const CScript& s
|
|||
void IncrementExtraNonce(CBlock* pblock, const CBlockIndex* pindexPrev, unsigned int& nExtraNonce);
|
||||
int64_t UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev);
|
||||
|
||||
extern double dHashesPerSec;
|
||||
extern int64_t nHPSTimerStart;
|
||||
|
||||
#endif // BITCOIN_MINER_H
|
||||
|
|
|
@ -72,6 +72,26 @@ UniValue GetNetworkHashPS(int lookup, int height) {
|
|||
return workDiff.getdouble() / timeDiff;
|
||||
}
|
||||
|
||||
UniValue gethashespersec(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() != 0)
|
||||
throw runtime_error(
|
||||
"gethashespersec\n"
|
||||
"\nReturns a recent hashes per second performance measurement while generating.\n"
|
||||
"See the getgenerate and setgenerate calls to turn generation on and off.\n"
|
||||
"\nResult:\n"
|
||||
"n (numeric) The recent hashes per second when generation is on (will return 0 if generation is off)\n"
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli("gethashespersec", "")
|
||||
+ HelpExampleRpc("gethashespersec", "")
|
||||
);
|
||||
|
||||
if (GetTimeMillis() - nHPSTimerStart > 8000)
|
||||
return (int64_t)0;
|
||||
return (int64_t)dHashesPerSec;
|
||||
}
|
||||
|
||||
|
||||
UniValue getnetworkhashps(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() > 2)
|
||||
|
@ -291,6 +311,7 @@ UniValue getmininginfo(const UniValue& params, bool fHelp)
|
|||
" \"errors\": \"...\" (string) Current errors\n"
|
||||
" \"generate\": true|false (boolean) If the generation is on or off (see getgenerate or setgenerate calls)\n"
|
||||
" \"genproclimit\": n (numeric) The processor limit for generation. -1 if no generation. (see getgenerate or setgenerate calls)\n"
|
||||
" \"hashespersec\": n (numeric) The hashes per second of the generation, or 0 if no generation.\n"
|
||||
" \"pooledtx\": n (numeric) The size of the mem pool\n"
|
||||
" \"testnet\": true|false (boolean) If using testnet or not\n"
|
||||
" \"chain\": \"xxxx\", (string) current network name as defined in BIP70 (main, test, regtest)\n"
|
||||
|
@ -315,6 +336,7 @@ UniValue getmininginfo(const UniValue& params, bool fHelp)
|
|||
obj.push_back(Pair("testnet", Params().TestnetToBeDeprecatedFieldRPC()));
|
||||
obj.push_back(Pair("chain", Params().NetworkIDString()));
|
||||
obj.push_back(Pair("generate", getgenerate(params, false)));
|
||||
obj.push_back(Pair("hashespersec", gethashespersec(params, false)));
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
@ -853,6 +875,7 @@ static const CRPCCommand commands[] =
|
|||
{ // category name actor (function) okSafeMode
|
||||
// --------------------- ------------------------ ----------------------- ----------
|
||||
{ "mining", "getnetworkhashps", &getnetworkhashps, true },
|
||||
{ "mining", "gethashespersec", &gethashespersec, true },
|
||||
{ "mining", "getmininginfo", &getmininginfo, true },
|
||||
{ "mining", "prioritisetransaction", &prioritisetransaction, true },
|
||||
{ "mining", "getblocktemplate", &getblocktemplate, true },
|
||||
|
|
Loading…
Reference in a new issue