Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RPC: Get rid of the internal miner's hashmeter #5599

Merged
merged 1 commit into from
Jan 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 2 additions & 40 deletions src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,6 @@ void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int&
//
// Internal miner
//
double dHashesPerSec = 0.0;
int64_t nHPSTimerStart = 0;

//
// ScanHash scans nonces looking for a hash with at least some zero bits.
Expand Down Expand Up @@ -395,10 +393,8 @@ bool static ScanHash(const CBlockHeader *pblock, uint32_t& nNonce, uint256 *phas
return true;

// If nothing found after trying for a while, return -1
if ((nNonce & 0xffff) == 0)
return false;
if ((nNonce & 0xfff) == 0)
boost::this_thread::interruption_point();
return false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is okay, but seems unrelated from the PR description?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maaku suggested on #4793 when I changed this boost::this_thread::interruption_point() to return false that the change belonged to the removal of the hashmeter as it was the reason for the interruption point to be there in the first place.

}
}

Expand Down Expand Up @@ -485,14 +481,9 @@ void static BitcoinMiner(CWallet *pwallet)
uint256 hashTarget = uint256().SetCompact(pblock->nBits);
uint256 hash;
uint32_t nNonce = 0;
uint32_t nOldNonce = 0;
while (true) {
bool fFound = ScanHash(pblock, nNonce, &hash);
uint32_t nHashesDone = nNonce - nOldNonce;
nOldNonce = nNonce;

// Check if something found
if (fFound)
if (ScanHash(pblock, nNonce, &hash))
{
if (hash <= hashTarget)
{
Expand All @@ -514,35 +505,6 @@ void static BitcoinMiner(CWallet *pwallet)
}
}

// 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();
// Regtest mode doesn't require peers
Expand Down
3 changes: 0 additions & 3 deletions src/miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,4 @@ void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int&
bool CheckWork(CBlock* pblock, CWallet& wallet, CReserveKey& reservekey);
void UpdateTime(CBlockHeader* block, const CBlockIndex* pindexPrev);

extern double dHashesPerSec;
extern int64_t nHPSTimerStart;

#endif // BITCOIN_MINER_H
20 changes: 0 additions & 20 deletions src/rpcmining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,24 +201,6 @@ Value setgenerate(const Array& params, bool fHelp)
return Value::null;
}

Value gethashespersec(const Array& 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;
}
#endif


Expand All @@ -237,7 +219,6 @@ Value getmininginfo(const Array& 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"
Expand All @@ -260,7 +241,6 @@ Value getmininginfo(const Array& params, bool fHelp)
obj.push_back(Pair("chain", Params().NetworkIDString()));
#ifdef ENABLE_WALLET
obj.push_back(Pair("generate", getgenerate(params, false)));
obj.push_back(Pair("hashespersec", gethashespersec(params, false)));
#endif
return obj;
}
Expand Down
1 change: 0 additions & 1 deletion src/rpcserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,6 @@ static const CRPCCommand vRPCCommands[] =
#ifdef ENABLE_WALLET
/* Coin generation */
{ "generating", "getgenerate", &getgenerate, true, false, false },
{ "generating", "gethashespersec", &gethashespersec, true, false, false },
{ "generating", "setgenerate", &setgenerate, true, true, false },
#endif

Expand Down
1 change: 0 additions & 1 deletion src/rpcserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ extern json_spirit::Value importwallet(const json_spirit::Array& params, bool fH
extern json_spirit::Value getgenerate(const json_spirit::Array& params, bool fHelp); // in rpcmining.cpp
extern json_spirit::Value setgenerate(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getnetworkhashps(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value gethashespersec(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getmininginfo(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value prioritisetransaction(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getblocktemplate(const json_spirit::Array& params, bool fHelp);
Expand Down