@@ -1667,6 +1667,18 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
1667
1667
int64_t nTimeStart = GetTimeMicros ();
1668
1668
1669
1669
// Check it again in case a previous version let a bad block in
1670
+ // NOTE: We don't currently (re-)invoke ContextualCheckBlock() or
1671
+ // ContextualCheckBlockHeader() here. This means that if we add a new
1672
+ // consensus rule that is enforced in one of those two functions, then we
1673
+ // may have let in a block that violates the rule prior to updating the
1674
+ // software, and we would NOT be enforcing the rule here. Fully solving
1675
+ // upgrade from one software version to the next after a consensus rule
1676
+ // change is potentially tricky and issue-specific (see RewindBlockIndex()
1677
+ // for one general approach that was used for BIP 141 deployment).
1678
+ // Also, currently the rule against blocks more than 2 hours in the future
1679
+ // is enforced in ContextualCheckBlockHeader(); we wouldn't want to
1680
+ // re-enforce that rule here (at least until we make it impossible for
1681
+ // GetAdjustedTime() to go backward).
1670
1682
if (!CheckBlock (block, state, chainparams.GetConsensus (), !fJustCheck , !fJustCheck ))
1671
1683
return error (" %s: Consensus::CheckBlock: %s" , __func__, FormatStateMessage (state));
1672
1684
@@ -2952,7 +2964,13 @@ std::vector<unsigned char> GenerateCoinbaseCommitment(CBlock& block, const CBloc
2952
2964
2953
2965
/* * Context-dependent validity checks.
2954
2966
* By "context", we mean only the previous block headers, but not the UTXO
2955
- * set; UTXO-related validity checks are done in ConnectBlock(). */
2967
+ * set; UTXO-related validity checks are done in ConnectBlock().
2968
+ * NOTE: This function is not currently invoked by ConnectBlock(), so we
2969
+ * should consider upgrade issues if we change which consensus rules are
2970
+ * enforced in this function (eg by adding a new consensus rule). See comment
2971
+ * in ConnectBlock().
2972
+ * Note that -reindex-chainstate skips the validation that happens here!
2973
+ */
2956
2974
static bool ContextualCheckBlockHeader (const CBlockHeader& block, CValidationState& state, const CChainParams& params, const CBlockIndex* pindexPrev, int64_t nAdjustedTime)
2957
2975
{
2958
2976
assert (pindexPrev != nullptr );
@@ -2992,6 +3010,12 @@ static bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationSta
2992
3010
return true ;
2993
3011
}
2994
3012
3013
+ /* * NOTE: This function is not currently invoked by ConnectBlock(), so we
3014
+ * should consider upgrade issues if we change which consensus rules are
3015
+ * enforced in this function (eg by adding a new consensus rule). See comment
3016
+ * in ConnectBlock().
3017
+ * Note that -reindex-chainstate skips the validation that happens here!
3018
+ */
2995
3019
static bool ContextualCheckBlock (const CBlock& block, CValidationState& state, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev)
2996
3020
{
2997
3021
const int nHeight = pindexPrev == nullptr ? 0 : pindexPrev->nHeight + 1 ;
0 commit comments