Repository: dogecoin/dogecoin
File: src/rpc/mining.cpp (C++)

Code before:
        LOCK(cs_main);
        nHeightStart = chainActive.Height();
        nHeight = nHeightStart;
        nHeightEnd = nHeightStart+nGenerate;
    }
    unsigned int nExtraNonce = 0;
    UniValue blockHashes(UniValue::VARR);
    while (nHeight < nHeightEnd)
    {
        std::unique_ptr<CBlockTemplate> pblocktemplate(BlockAssembler(Params()).CreateNewBlock(coinbaseScript->reserveScript, fMineWitnessTx));
        if (!pblocktemplate.get())
            throw JSONRPCError(RPC_INTERNAL_ERROR, "Couldn't create new block");
        CBlock *pblock = &pblocktemplate->block;
        {
            LOCK(cs_main);
            IncrementExtraNonce(pblock, chainActive.Tip(), nExtraNonce);
        }
        if (!nMineAuxPow) {
            while (nMaxTries > 0 && pblock->nNonce < nInnerLoopCount && !CheckProofOfWork(pblock->GetPoWHash(), pblock->nBits, Params().GetConsensus(nHeight))) {
                ++pblock->nNonce;
                --nMaxTries;
            }
        } else {
            CAuxPow::initAuxPow(*pblock);
            CPureBlockHeader& miningHeader = pblock->auxpow->parentBlock;
            while (nMaxTries > 0 && miningHeader.nNonce < nInnerLoopCount && !CheckProofOfWork(miningHeader.GetHash(), pblock->nBits, Params().GetConsensus(nHeight))) {
                ++miningHeader.nNonce;
                --nMaxTries;
            }
        }
        if (nMaxTries == 0) {
            break;
        }
        if (!nMineAuxPow) {
            if (pblock->nNonce == nInnerLoopCount) {
                continue;
            }
        } else {
            CPureBlockHeader& miningHeader = pblock->auxpow->parentBlock;
            if (miningHeader.nNonce == nInnerLoopCount) {
                continue;
            }
        }
        std::shared_ptr<const CBlock> shared_pblock = std::make_shared<const CBlock>(*pblock);
        if (!ProcessNewBlock(Params(), shared_pblock, true, NULL))
            if (nMineAuxPow) {
                continue;
            }
            else { 
                throw JSONRPCError(RPC_INTERNAL_ERROR, "ProcessNewBlock, block not accepted"); 
            }

Review comment (suggestion):
`miningHeader.GetHash()` should be `miningHeader.GetPoWHash()` and then it works for me on testnet too!

https://chain.so/block/DOGETEST/1ab471a198f54310c98e5820a4766894f1cec53e654cb03e25082b387918b78b

Code after:
        LOCK(cs_main);
        nHeightStart = chainActive.Height();
        nHeight = nHeightStart;
        nHeightEnd = nHeightStart+nGenerate;
    }
    unsigned int nExtraNonce = 0;
    UniValue blockHashes(UniValue::VARR);
    while (nHeight < nHeightEnd)
    {
        std::unique_ptr<CBlockTemplate> pblocktemplate(BlockAssembler(Params()).CreateNewBlock(coinbaseScript->reserveScript, fMineWitnessTx));
        if (!pblocktemplate.get())
            throw JSONRPCError(RPC_INTERNAL_ERROR, "Couldn't create new block");
        CBlock *pblock = &pblocktemplate->block;
        {
            LOCK(cs_main);
            IncrementExtraNonce(pblock, chainActive.Tip(), nExtraNonce);
        }
        if (!nMineAuxPow) {
            while (nMaxTries > 0 && pblock->nNonce < nInnerLoopCount && !CheckProofOfWork(pblock->GetPoWHash(), pblock->nBits, Params().GetConsensus(nHeight))) {
                ++pblock->nNonce;
                --nMaxTries;
            }
        } else {
            CAuxPow::initAuxPow(*pblock);
            CPureBlockHeader& miningHeader = pblock->auxpow->parentBlock;
            while (nMaxTries > 0 && miningHeader.nNonce < nInnerLoopCount && !CheckProofOfWork(miningHeader.GetPoWHash(), pblock->nBits, Params().GetConsensus(nHeight))) {
                ++miningHeader.nNonce;
                --nMaxTries;
            }
        }
        if (nMaxTries == 0) {
            break;
        }
        if (!nMineAuxPow) {
            if (pblock->nNonce == nInnerLoopCount) {
                continue;
            }
        } else {
            CPureBlockHeader& miningHeader = pblock->auxpow->parentBlock;
            if (miningHeader.nNonce == nInnerLoopCount) {
                continue;
            }
        }
        std::shared_ptr<const CBlock> shared_pblock = std::make_shared<const CBlock>(*pblock);
        if (!ProcessNewBlock(Params(), shared_pblock, true, NULL))
            if (nMineAuxPow) {
                continue;
            }
            else { 
                throw JSONRPCError(RPC_INTERNAL_ERROR, "ProcessNewBlock, block not accepted"); 
            }