Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/mining.cpp
Show First 20 Lines • Show All 126 Lines • ▼ Show 20 Lines | UniValue generateBlocks(const Config &config, | ||||
{ | { | ||||
// 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; | ||||
} | } | ||||
const uint64_t nExcessiveBlockSize = config.GetMaxBlockSize(); | |||||
unsigned int nExtraNonce = 0; | unsigned int nExtraNonce = 0; | ||||
UniValue blockHashes(UniValue::VARR); | UniValue blockHashes(UniValue::VARR); | ||||
while (nHeight < nHeightEnd && !ShutdownRequested()) { | while (nHeight < nHeightEnd && !ShutdownRequested()) { | ||||
std::unique_ptr<CBlockTemplate> pblocktemplate( | std::unique_ptr<CBlockTemplate> pblocktemplate( | ||||
BlockAssembler(config, g_mempool) | BlockAssembler(config, g_mempool) | ||||
.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(pblock, ::ChainActive().Tip(), | IncrementExtraNonce(pblock, ::ChainActive().Tip(), | ||||
config.GetMaxBlockSize(), nExtraNonce); | nExcessiveBlockSize, nExtraNonce); | ||||
} | } | ||||
while (nMaxTries > 0 && pblock->nNonce < nInnerLoopCount && | while (nMaxTries > 0 && pblock->nNonce < nInnerLoopCount && | ||||
!CheckProofOfWork(pblock->GetHash(), pblock->nBits, | !CheckProofOfWork(pblock->GetHash(), pblock->nBits, | ||||
config.GetChainParams().GetConsensus())) { | config.GetChainParams().GetConsensus())) { | ||||
++pblock->nNonce; | ++pblock->nNonce; | ||||
--nMaxTries; | --nMaxTries; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 544 Lines • ▼ Show 20 Lines | static UniValue getblocktemplate(const Config &config, | ||||
result.pushKV("coinbasevalue", | result.pushKV("coinbasevalue", | ||||
int64_t(pblock->vtx[0]->vout[0].nValue / SATOSHI)); | int64_t(pblock->vtx[0]->vout[0].nValue / SATOSHI)); | ||||
result.pushKV("longpollid", ::ChainActive().Tip()->GetBlockHash().GetHex() + | result.pushKV("longpollid", ::ChainActive().Tip()->GetBlockHash().GetHex() + | ||||
i64tostr(nTransactionsUpdatedLast)); | i64tostr(nTransactionsUpdatedLast)); | ||||
result.pushKV("target", hashTarget.GetHex()); | result.pushKV("target", hashTarget.GetHex()); | ||||
result.pushKV("mintime", int64_t(pindexPrev->GetMedianTimePast()) + 1); | result.pushKV("mintime", int64_t(pindexPrev->GetMedianTimePast()) + 1); | ||||
result.pushKV("mutable", aMutable); | result.pushKV("mutable", aMutable); | ||||
result.pushKV("noncerange", "00000000ffffffff"); | result.pushKV("noncerange", "00000000ffffffff"); | ||||
// FIXME: Allow for mining block greater than 1M. | result.pushKV("sigoplimit", | ||||
result.pushKV("sigoplimit", GetMaxBlockSigOpsCount(DEFAULT_MAX_BLOCK_SIZE)); | GetMaxBlockSigChecksCount(DEFAULT_MAX_BLOCK_SIZE)); | ||||
result.pushKV("sizelimit", DEFAULT_MAX_BLOCK_SIZE); | result.pushKV("sizelimit", DEFAULT_MAX_BLOCK_SIZE); | ||||
result.pushKV("curtime", pblock->GetBlockTime()); | result.pushKV("curtime", pblock->GetBlockTime()); | ||||
result.pushKV("bits", strprintf("%08x", pblock->nBits)); | result.pushKV("bits", strprintf("%08x", pblock->nBits)); | ||||
result.pushKV("height", int64_t(pindexPrev->nHeight) + 1); | result.pushKV("height", int64_t(pindexPrev->nHeight) + 1); | ||||
return result; | return result; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 178 Lines • Show Last 20 Lines |