Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/mining.cpp
Show First 20 Lines • Show All 114 Lines • ▼ Show 20 Lines | static UniValue getnetworkhashps(const Config &config, | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
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 bool GenerateBlock(const Config &config, ChainstateManager &chainman, | static bool GenerateBlock(const Config &config, ChainstateManager &chainman, | ||||
CBlock &block, uint64_t &max_tries, | CBlock &block, uint64_t &max_tries, | ||||
unsigned int &extra_nonce, BlockHash &block_hash) { | BlockHash &block_hash) { | ||||
block_hash.SetNull(); | block_hash.SetNull(); | ||||
const uint64_t nExcessiveBlockSize = config.GetMaxBlockSize(); | const uint64_t nExcessiveBlockSize = config.GetMaxBlockSize(); | ||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
IncrementExtraNonce(&block, ::ChainActive().Tip(), nExcessiveBlockSize, | IncrementExtraNonce(&block, ::ChainActive().Tip(), nExcessiveBlockSize); | ||||
extra_nonce); | |||||
} | } | ||||
const Consensus::Params ¶ms = config.GetChainParams().GetConsensus(); | const Consensus::Params ¶ms = config.GetChainParams().GetConsensus(); | ||||
while (max_tries > 0 && | while (max_tries > 0 && | ||||
block.nNonce < std::numeric_limits<uint32_t>::max() && | block.nNonce < std::numeric_limits<uint32_t>::max() && | ||||
!CheckProofOfWork(block.GetHash(), block.nBits, params) && | !CheckProofOfWork(block.GetHash(), block.nBits, params) && | ||||
!ShutdownRequested()) { | !ShutdownRequested()) { | ||||
Show All 28 Lines | static 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; | ||||
} | } | ||||
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, mempool).CreateNewBlock(coinbase_script)); | BlockAssembler(config, mempool).CreateNewBlock(coinbase_script)); | ||||
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; | ||||
BlockHash block_hash; | BlockHash block_hash; | ||||
if (!GenerateBlock(config, chainman, *pblock, nMaxTries, nExtraNonce, | if (!GenerateBlock(config, chainman, *pblock, nMaxTries, block_hash)) { | ||||
block_hash)) { | |||||
break; | break; | ||||
} | } | ||||
if (!block_hash.IsNull()) { | if (!block_hash.IsNull()) { | ||||
++nHeight; | ++nHeight; | ||||
blockHashes.push_back(block_hash.GetHex()); | blockHashes.push_back(block_hash.GetHex()); | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 250 Lines • ▼ Show 20 Lines | block.vtx.insert(block.vtx.end(), txs.begin(), txs.end()); | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_VERIFY_ERROR, | RPC_VERIFY_ERROR, | ||||
strprintf("TestBlockValidity failed: %s", state.ToString())); | strprintf("TestBlockValidity failed: %s", state.ToString())); | ||||
} | } | ||||
} | } | ||||
BlockHash block_hash; | BlockHash block_hash; | ||||
uint64_t max_tries{1000000}; | uint64_t max_tries{1000000}; | ||||
unsigned int extra_nonce{0}; | |||||
if (!GenerateBlock(config, EnsureChainman(request.context), block, | if (!GenerateBlock(config, EnsureChainman(request.context), block, | ||||
max_tries, extra_nonce, block_hash) || | max_tries, block_hash) || | ||||
block_hash.IsNull()) { | block_hash.IsNull()) { | ||||
throw JSONRPCError(RPC_MISC_ERROR, "Failed to make block."); | throw JSONRPCError(RPC_MISC_ERROR, "Failed to make block."); | ||||
} | } | ||||
UniValue obj(UniValue::VOBJ); | UniValue obj(UniValue::VOBJ); | ||||
obj.pushKV("hash", block_hash.GetHex()); | obj.pushKV("hash", block_hash.GetHex()); | ||||
return obj; | return obj; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 704 Lines • Show Last 20 Lines |