Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/mining.cpp
Show First 20 Lines • Show All 113 Lines • ▼ Show 20 Lines | static UniValue getnetworkhashps(const Config &config, | ||||
return GetNetworkHashPS( | return GetNetworkHashPS( | ||||
!request.params[0].isNull() ? request.params[0].get_int() : 120, | !request.params[0].isNull() ? request.params[0].get_int() : 120, | ||||
!request.params[1].isNull() ? request.params[1].get_int() : -1); | !request.params[1].isNull() ? request.params[1].get_int() : -1); | ||||
} | } | ||||
static UniValue generateBlocks(const Config &config, | static UniValue generateBlocks(const Config &config, | ||||
const CScript &coinbase_script, int nGenerate, | const CScript &coinbase_script, int nGenerate, | ||||
uint64_t nMaxTries) { | uint64_t nMaxTries) { | ||||
static const int nInnerLoopCount = 0x100000; | |||||
int nHeightEnd = 0; | int nHeightEnd = 0; | ||||
int nHeight = 0; | int nHeight = 0; | ||||
{ | { | ||||
// Don't keep cs_main locked. | // Don't keep cs_main locked. | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
nHeight = ::ChainActive().Height(); | nHeight = ::ChainActive().Height(); | ||||
nHeightEnd = nHeight + nGenerate; | nHeightEnd = nHeight + nGenerate; | ||||
Show All 14 Lines | while (nHeight < nHeightEnd && !ShutdownRequested()) { | ||||
CBlock *pblock = &pblocktemplate->block; | CBlock *pblock = &pblocktemplate->block; | ||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
IncrementExtraNonce(pblock, ::ChainActive().Tip(), | IncrementExtraNonce(pblock, ::ChainActive().Tip(), | ||||
nExcessiveBlockSize, nExtraNonce); | nExcessiveBlockSize, nExtraNonce); | ||||
} | } | ||||
while (nMaxTries > 0 && pblock->nNonce < nInnerLoopCount && | while (nMaxTries > 0 && | ||||
pblock->nNonce < std::numeric_limits<uint32_t>::max() && | |||||
!CheckProofOfWork(pblock->GetHash(), pblock->nBits, | !CheckProofOfWork(pblock->GetHash(), pblock->nBits, | ||||
config.GetChainParams().GetConsensus())) { | config.GetChainParams().GetConsensus()) && | ||||
!ShutdownRequested()) { | |||||
++pblock->nNonce; | ++pblock->nNonce; | ||||
--nMaxTries; | --nMaxTries; | ||||
} | } | ||||
if (nMaxTries == 0) { | if (nMaxTries == 0 || ShutdownRequested()) { | ||||
break; | break; | ||||
} | } | ||||
if (pblock->nNonce == nInnerLoopCount) { | if (pblock->nNonce == std::numeric_limits<uint32_t>::max()) { | ||||
continue; | continue; | ||||
} | } | ||||
std::shared_ptr<const CBlock> shared_pblock = | std::shared_ptr<const CBlock> shared_pblock = | ||||
std::make_shared<const CBlock>(*pblock); | std::make_shared<const CBlock>(*pblock); | ||||
if (!ProcessNewBlock(config, shared_pblock, true, nullptr)) { | if (!ProcessNewBlock(config, shared_pblock, true, nullptr)) { | ||||
throw JSONRPCError(RPC_INTERNAL_ERROR, | throw JSONRPCError(RPC_INTERNAL_ERROR, | ||||
"ProcessNewBlock, block not accepted"); | "ProcessNewBlock, block not accepted"); | ||||
▲ Show 20 Lines • Show All 724 Lines • Show Last 20 Lines |