| 124 | } |
| 125 | |
| 126 | static bool GenerateBlock(ChainstateManager& chainman, CBlock& block, uint64_t& max_tries, unsigned int& extra_nonce, uint256& block_hash) |
| 127 | { |
| 128 | block_hash.SetNull(); |
| 129 | |
| 130 | { |
| 131 | LOCK(cs_main); |
| 132 | IncrementExtraNonce(&block, chainman.ActiveChain().Tip(), extra_nonce); |
| 133 | } |
| 134 | |
| 135 | CChainParams chainparams(Params()); |
| 136 | |
| 137 | // Signed blocks have no PoW requirements, but merkle root computed above in |
| 138 | // IncrementExtraNonce |
| 139 | if (!g_signed_blocks) { |
| 140 | while (max_tries > 0 && block.nNonce < std::numeric_limits<uint32_t>::max() && !CheckProofOfWork(block.GetHash(), block.nBits, chainparams.GetConsensus()) && !ShutdownRequested()) { |
| 141 | ++block.nNonce; |
| 142 | --max_tries; |
| 143 | } |
| 144 | if (max_tries == 0 || ShutdownRequested()) { |
| 145 | return false; |
| 146 | } |
| 147 | if (block.nNonce == std::numeric_limits<uint32_t>::max()) { |
| 148 | return true; |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | // Handle OP_TRUE m_signblockscript case |
| 153 | CScript op_true(OP_TRUE); |
| 154 | if (block.m_dynafed_params.m_current.m_signblockscript == |
| 155 | GetScriptForDestination(WitnessV0ScriptHash(op_true))) { |
| 156 | block.m_signblock_witness.stack.push_back(std::vector<unsigned char>(op_true.begin(), op_true.end())); |
| 157 | } else if (!block.m_dynafed_params.IsNull()) { |
| 158 | throw JSONRPCError(RPC_MISC_ERROR, "Unable to fill out dynamic federation signblockscript witness, are you sure it's WSH(OP_TRUE)?"); |
| 159 | } |
| 160 | |
| 161 | std::shared_ptr<const CBlock> shared_pblock = std::make_shared<const CBlock>(block); |
| 162 | if (!chainman.ProcessNewBlock(chainparams, shared_pblock, true, nullptr)) { |
| 163 | throw JSONRPCError(RPC_INTERNAL_ERROR, "ProcessNewBlock, block not accepted"); |
| 164 | } |
| 165 | |
| 166 | block_hash = block.GetHash(); |
| 167 | return true; |
| 168 | } |
| 169 | |
| 170 | static UniValue generateBlocks(ChainstateManager& chainman, const CTxMemPool& mempool, const CScript& coinbase_script, int nGenerate, uint64_t nMaxTries) |
| 171 | { |
no test coverage detected