MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / GenerateBlock

Function GenerateBlock

src/rpc/mining.cpp:168–193  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

166}
167
168static bool GenerateBlock(ChainstateManager& chainman, CBlock&& block, uint64_t& max_tries, std::shared_ptr<const CBlock>& block_out, bool process_new_block)
169{
170 block_out.reset();
171 block.hashMerkleRoot = BlockMerkleRoot(block);
172
173 while (max_tries > 0 && block.nNonce < std::numeric_limits<uint32_t>::max() && !CheckProofOfWork(block.GetHash(), block.nBits, chainman.GetConsensus()) && !chainman.m_interrupt) {
174 ++block.nNonce;
175 --max_tries;
176 }
177 if (max_tries == 0 || chainman.m_interrupt) {
178 return false;
179 }
180 if (block.nNonce == std::numeric_limits<uint32_t>::max()) {
181 return true;
182 }
183
184 block_out = std::make_shared<const CBlock>(std::move(block));
185
186 if (!process_new_block) return true;
187
188 if (!chainman.ProcessNewBlock(block_out, /*force_processing=*/true, /*min_pow_checked=*/true, nullptr)) {
189 throw JSONRPCError(RPC_INTERNAL_ERROR, "ProcessNewBlock, block not accepted");
190 }
191
192 return true;
193}
194
195static UniValue generateBlocks(ChainstateManager& chainman, Mining& miner, const CScript& coinbase_output_script, int nGenerate, uint64_t nMaxTries)
196{

Callers 2

generateBlocksFunction · 0.85
generateblockFunction · 0.85

Calls 6

BlockMerkleRootFunction · 0.85
CheckProofOfWorkFunction · 0.85
JSONRPCErrorFunction · 0.85
ProcessNewBlockMethod · 0.80
resetMethod · 0.45
GetHashMethod · 0.45

Tested by

no test coverage detected