Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/mining.cpp
Show First 20 Lines • Show All 126 Lines • ▼ Show 20 Lines | static UniValue generateBlocks(const Config &config, | ||||
} | } | ||||
unsigned int nExtraNonce = 0; | unsigned int nExtraNonce = 0; | ||||
UniValue blockHashes(UniValue::VARR); | UniValue blockHashes(UniValue::VARR); | ||||
while (nHeight < nHeightEnd) { | while (nHeight < nHeightEnd) { | ||||
std::unique_ptr<CBlockTemplate> pblocktemplate( | std::unique_ptr<CBlockTemplate> pblocktemplate( | ||||
BlockAssembler(config, Params()) | BlockAssembler(config, Params()) | ||||
.CreateNewBlock(coinbaseScript->reserveScript)); | .CreateNewBlock(coinbaseScript->reserveScript)); | ||||
if (!pblocktemplate.get()) { | if (!pblocktemplate.get()) { | ||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Couldn't create new block"); | throw JSONRPCError(RPC_INTERNAL_ERROR, "Couldn't create new block"); | ||||
} | } | ||||
CBlock *pblock = &pblocktemplate->block; | CBlock *pblock = &pblocktemplate->block; | ||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
IncrementExtraNonce(config, pblock, chainActive.Tip(), nExtraNonce); | IncrementExtraNonce(config, pblock, chainActive.Tip(), nExtraNonce); | ||||
} | } | ||||
while (nMaxTries > 0 && pblock->nNonce < nInnerLoopCount && | while (nMaxTries > 0 && pblock->nNonce < nInnerLoopCount && | ||||
!CheckProofOfWork(pblock->GetHash(), pblock->nBits, | !CheckProofOfWork(pblock->GetHash(), pblock->nBits, config)) { | ||||
Params().GetConsensus())) { | |||||
++pblock->nNonce; | ++pblock->nNonce; | ||||
--nMaxTries; | --nMaxTries; | ||||
} | } | ||||
if (nMaxTries == 0) { | if (nMaxTries == 0) { | ||||
break; | break; | ||||
} | } | ||||
if (pblock->nNonce == nInnerLoopCount) { | if (pblock->nNonce == nInnerLoopCount) { | ||||
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"); | ||||
} | } | ||||
++nHeight; | ++nHeight; | ||||
blockHashes.push_back(pblock->GetHash().GetHex()); | blockHashes.push_back(pblock->GetHash().GetHex()); | ||||
▲ Show 20 Lines • Show All 501 Lines • ▼ Show 20 Lines | if (pindexPrev != chainActive.Tip() || | ||||
BlockAssembler(config, Params()).CreateNewBlock(scriptDummy); | BlockAssembler(config, Params()).CreateNewBlock(scriptDummy); | ||||
if (!pblocktemplate) { | if (!pblocktemplate) { | ||||
throw JSONRPCError(RPC_OUT_OF_MEMORY, "Out of memory"); | throw JSONRPCError(RPC_OUT_OF_MEMORY, "Out of memory"); | ||||
} | } | ||||
// Need to update only after we know CreateNewBlock succeeded | // Need to update only after we know CreateNewBlock succeeded | ||||
pindexPrev = pindexPrevNew; | pindexPrev = pindexPrevNew; | ||||
} | } | ||||
CBlock *pblock = &pblocktemplate->block; // pointer for convenience | |||||
const Consensus::Params &consensusParams = Params().GetConsensus(); | // pointer for convenience | ||||
CBlock *pblock = &pblocktemplate->block; | |||||
const Consensus::Params &consensusParams = | |||||
config.GetChainParams().GetConsensus(); | |||||
// Update nTime | // Update nTime | ||||
UpdateTime(pblock, config, pindexPrev); | UpdateTime(pblock, config, pindexPrev); | ||||
pblock->nNonce = 0; | pblock->nNonce = 0; | ||||
UniValue aCaps(UniValue::VARR); | UniValue aCaps(UniValue::VARR); | ||||
aCaps.push_back("proposal"); | aCaps.push_back("proposal"); | ||||
▲ Show 20 Lines • Show All 416 Lines • Show Last 20 Lines |