From 96f9009e29a2ffcb99e1fdd69e54eb7c9603b1dc Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Apr 2018 05:25:07 +0300 Subject: [PATCH] Fixup mining PoW checks --- src/main.cpp | 15 +++++++-------- src/main.h | 2 +- src/miner.cpp | 4 ++-- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index edae9c5aa..83026de4b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2429,7 +2429,7 @@ static int64_t nTimeIndex = 0; static int64_t nTimeCallbacks = 0; static int64_t nTimeTotal = 0; -bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& view, bool fJustCheck) +bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& view, bool fJustCheck,bool fCheckPOW) { const CChainParams& chainparams = Params(); @@ -2447,7 +2447,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin auto disabledVerifier = libzcash::ProofVerifier::Disabled(); // Check it again to verify JoinSplit proofs, and in case a previous version let a bad block in - if (!CheckBlock(pindex->nHeight,pindex,block, state, fExpensiveChecks ? verifier : disabledVerifier, 1, !fJustCheck)) //!fJustCheck, !fJustCheck)) + if (!CheckBlock(pindex->nHeight,pindex,block, state, fExpensiveChecks ? verifier : disabledVerifier, fCheckPOW, !fJustCheck)) //!fJustCheck, !fJustCheck)) return false; // verify that the view's current state corresponds to the previous block @@ -2923,7 +2923,7 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock * LogPrint("bench", " - Load block from disk: %.2fms [%.2fs]\n", (nTime2 - nTime1) * 0.001, nTimeReadFromDisk * 0.000001); { CCoinsViewCache view(pcoinsTip); - bool rv = ConnectBlock(*pblock, state, pindexNew, view); + bool rv = ConnectBlock(*pblock, state, pindexNew, view, false, true); GetMainSignals().BlockChecked(*pblock, state); if (!rv) { if (state.IsInvalid()) @@ -3565,8 +3565,7 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat // redundant with the call in AcceptBlockHeader. if (!CheckBlockHeader(height,pindex,block,state,fCheckPOW)) { - - fprintf(stderr,"checkblockheader error\n"); + fprintf(stderr,"checkblockheader error PoW.%d\n",fCheckPOW); return false; } komodo_block2pubkey33(pubkey33,(CBlock *)&block); @@ -3971,7 +3970,7 @@ bool TestBlockValidity(CValidationState &state, const CBlock& block, CBlockIndex } if (!CheckBlock(indexDummy.nHeight,0,block, state, verifier, fCheckPOW, fCheckMerkleRoot)) { - //fprintf(stderr,"TestBlockValidity failure B\n"); + fprintf(stderr,"TestBlockValidity failure B\n"); return false; } if (!ContextualCheckBlock(block, state, pindexPrev)) @@ -3979,7 +3978,7 @@ bool TestBlockValidity(CValidationState &state, const CBlock& block, CBlockIndex fprintf(stderr,"TestBlockValidity failure C\n"); return false; } - if (!ConnectBlock(block, state, &indexDummy, viewNew, true)) + if (!ConnectBlock(block, state, &indexDummy, viewNew, true,fCheckPOW)) { fprintf(stderr,"TestBlockValidity failure D\n"); return false; @@ -4417,7 +4416,7 @@ bool CVerifyDB::VerifyDB(CCoinsView *coinsview, int nCheckLevel, int nCheckDepth CBlock block; if (!ReadBlockFromDisk(block, pindex)) return error("VerifyDB(): *** ReadBlockFromDisk failed at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString()); - if (!ConnectBlock(block, state, pindex, coins)) + if (!ConnectBlock(block, state, pindex, coins,false, true)) return error("VerifyDB(): *** found unconnectable block at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString()); } } diff --git a/src/main.h b/src/main.h index 1c864de20..cb10e0168 100644 --- a/src/main.h +++ b/src/main.h @@ -447,7 +447,7 @@ bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex); bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& coins, bool* pfClean = NULL); /** Apply the effects of this block (with given index) on the UTXO set represented by coins */ -bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& coins, bool fJustCheck = false); +bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& coins, bool fJustCheck = false,bool fCheckPOW = false); /** Context-independent validity checks */ bool CheckBlockHeader(int32_t height,CBlockIndex *pindex,const CBlockHeader& block, CValidationState& state, bool fCheckPOW = true); diff --git a/src/miner.cpp b/src/miner.cpp index b419b7e16..e571f3617 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -935,9 +935,9 @@ void static BitcoinMiner() else { CValidationState state; - if ( !TestBlockValidity(state, *pblock, chainActive.Tip(), false, false)) + if ( !TestBlockValidity(state, *pblock, chainActive.Tip(), true, false)) { - //fprintf(stderr,"Invalid block mined, try again\n"); + fprintf(stderr,"Invalid block mined, try again\n"); return(false); } if ( NOTARY_PUBKEY33[0] != 0 )