@@ -2896,11 +2896,6 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
28962896 if (pindex->IsProofOfStake ())
28972897 setStakeSeen.insert (make_pair (pindex->prevoutStake , pindex->nStakeTime ));
28982898
2899- // Check proof of stake
2900- if (block.nBits != GetNextTargetRequired (pindex->pprev , block.IsProofOfStake ())){
2901- return state.DoS (1 ,error (" ContextualCheckBlock() : incorrect %s at height %d (%d)" , !block.IsProofOfStake () ? " proof-of-work" : " proof-of-stake" ,pindex->pprev ->nHeight , block.nBits ), REJECT_INVALID , " bad-diffbits" );
2902- }
2903-
29042899 arith_uint256 hashProof;
29052900
29062901 // Verify hash target and signature of coinstake tx
@@ -2910,7 +2905,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
29102905 // Signature will be checked in CheckInputs(), we can avoid it here (fCheckSignature = false)
29112906 if (!CheckProofOfStake (pindex->pprev , block.vtx [1 ], block.nBits , hashProof, targetProofOfStake, NULL , false ))
29122907 {
2913- return error (" ContextualCheckBlock () : check proof-of-stake signature failed for block %s" , block.GetHash ().GetHex ());
2908+ return error (" ConnectBlock () : check proof-of-stake signature failed for block %s" , block.GetHash ().GetHex ());
29142909 }
29152910 }
29162911
@@ -2920,15 +2915,15 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
29202915 }
29212916
29222917 if (!pindex->SetStakeEntropyBit (block.GetStakeEntropyBit ()))
2923- return state.DoS (1 ,error (" ContextualCheckBlock () : SetStakeEntropyBit() failed" ), REJECT_INVALID , " bad-entropy-bit" );
2918+ return state.DoS (1 ,error (" ConnectBlock () : SetStakeEntropyBit() failed" ), REJECT_INVALID , " bad-entropy-bit" );
29242919
29252920 // Record proof hash value
29262921 pindex->hashProof = hashProof;
29272922
29282923 uint64_t nStakeModifier = 0 ;
29292924 bool fGeneratedStakeModifier = false ;
29302925 if (!ComputeNextStakeModifier (pindex->pprev , nStakeModifier, fGeneratedStakeModifier ))
2931- return state.DoS (1 , error (" ContextualCheckBlock () : ComputeNextStakeModifier() failed" ), REJECT_INVALID , " bad-stake-modifier" );
2926+ return state.DoS (1 , error (" ConnectBlock () : ComputeNextStakeModifier() failed" ), REJECT_INVALID , " bad-stake-modifier" );
29322927
29332928 pindex->SetStakeModifier (nStakeModifier, fGeneratedStakeModifier );
29342929
@@ -4734,6 +4729,7 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta
47344729 if ((block.nVersion & nV452ForkMask) != nV452ForkMask && pindexPrev->nHeight >= Params ().GetConsensus ().nHeightv452Fork )
47354730 return state.Invalid (false , REJECT_OBSOLETE , strprintf (" bad-version(0x%08x)" , block.nVersion ),
47364731 " rejected, block version isn't v4.5.2" );
4732+
47374733 return true ;
47384734}
47394735
@@ -4747,6 +4743,11 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIn
47474743 if (VersionBitsState (pindexPrev, consensusParams, Consensus::DEPLOYMENT_CSV , versionbitscache) == THRESHOLD_ACTIVE ) {
47484744 nLockTimeFlags |= LOCKTIME_MEDIAN_TIME_PAST ;
47494745 }
4746+
4747+ // Check proof of stake
4748+ if (nHeight > 0 && block.nBits != GetNextTargetRequired (pindexPrev, block.IsProofOfStake ())){
4749+ return state.DoS (1 ,error (" ContextualCheckBlock() : incorrect %s at height %d (%d)" , !block.IsProofOfStake () ? " proof-of-work" : " proof-of-stake" , nHeight, block.nBits ), REJECT_INVALID , " bad-diffbits" );
4750+ }
47504751
47514752 if (block.IsProofOfWork () && nHeight > Params ().GetConsensus ().nLastPOWBlock )
47524753 return state.DoS (10 , false , REJECT_INVALID , " check-pow-height" , " pow-mined blocks not allowed" );
0 commit comments