| 166 | } |
| 167 | |
| 168 | static 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 | |
| 195 | static UniValue generateBlocks(ChainstateManager& chainman, Mining& miner, const CScript& coinbase_output_script, int nGenerate, uint64_t nMaxTries) |
| 196 | { |
no test coverage detected