diff --git a/src/miner.cpp b/src/miner.cpp index 1a2afd327..b22cc406a 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -677,11 +677,11 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 if ( totalsats == 0 ) { LogPrintf("Could not create notary payment, trying again.\n"); - if ( !isStake ) - { - LEAVE_CRITICAL_SECTION(cs_main); - LEAVE_CRITICAL_SECTION(mempool.cs); - } + // Release unconditionally to match the unconditional ENTER above. The old + // `if(!isStake)` guard leaked cs_main/mempool.cs on the isStake path (this + // still return(0)s), while the success and timelock paths always release. + LEAVE_CRITICAL_SECTION(cs_main); + LEAVE_CRITICAL_SECTION(mempool.cs); return(0); } } else LogPrintf("vout 2 of notarization is not OP_RETURN scriptlen.%i\n", scriptlen); @@ -726,11 +726,11 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 CValidationState state; if ( !TestBlockValidity(state, *pblock, pindexPrev, false, false)) // invokes CC checks { - if ( !isStake ) - { - LEAVE_CRITICAL_SECTION(cs_main); - LEAVE_CRITICAL_SECTION(mempool.cs); - } + // Release unconditionally to match the unconditional ENTER above. The old + // `if(!isStake)` guard leaked cs_main/mempool.cs on the isStake path (this + // still return(0)s), while the success and timelock paths always release. + LEAVE_CRITICAL_SECTION(cs_main); + LEAVE_CRITICAL_SECTION(mempool.cs); LogPrintf("%s: TestBlockValidity failed!\n", __func__); //throw std::runtime_error("CreateNewBlock(): TestBlockValidity failed"); // crashes the node, moved to GetBlockTemplate and issue return. return(0);