This simplifies generateBlocks and further encapsulates the use of nNonce and nBits inside pow.o by introducing a new function MaybeGenerateProof.
This should be helpful for any attempt to support a testnet with signed blocks (see #9177 )
97+ while (max_tries > 0 && pblock->nNonce < nInnerLoopCount && !CheckProofOfWork(blockHash, pblock->nBits, params)) {
98+ ++pblock->nNonce;
99+ blockHash = pblock->GetHash();
100+ --max_tries;
101+ }
102+ return CheckProofOfWork(blockHash, pblock->nBits, params);
CheckProofOfWork
twice. You can move it from the while loop into the body, and make it return true immediately when it succeeds.