Skip to content

Commit 46d1ebf

Browse files
committed
Merge #11737: Document partial validation in ConnectBlock()
9d811dc Document partial validation in ConnectBlock() (Suhas Daftuar) Pull request description: `ConnectBlock()` relies on validation that happens in `ContextualCheckBlock()` and `ContextualCheckBlockHeader()`. This has implications for implementing consensus changes and handling software upgrade to ensure that nodes upgrading their software end up enforcing all the consensus rules. Tree-SHA512: 36a252af2221b0e5d5d6f8d5f8b16f8b566ca0db2d56242130a5523302c8757599ac234594a6a946c1689b260d18a32c2c7f8c3831304e78b9832e2ce5ac435a
2 parents e970396 + 9d811dc commit 46d1ebf

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

src/validation.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1667,6 +1667,18 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
16671667
int64_t nTimeStart = GetTimeMicros();
16681668

16691669
// 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).
16701682
if (!CheckBlock(block, state, chainparams.GetConsensus(), !fJustCheck, !fJustCheck))
16711683
return error("%s: Consensus::CheckBlock: %s", __func__, FormatStateMessage(state));
16721684

@@ -2952,7 +2964,13 @@ std::vector<unsigned char> GenerateCoinbaseCommitment(CBlock& block, const CBloc
29522964

29532965
/** Context-dependent validity checks.
29542966
* 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+
*/
29562974
static bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& state, const CChainParams& params, const CBlockIndex* pindexPrev, int64_t nAdjustedTime)
29572975
{
29582976
assert(pindexPrev != nullptr);
@@ -2992,6 +3010,12 @@ static bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationSta
29923010
return true;
29933011
}
29943012

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+
*/
29953019
static bool ContextualCheckBlock(const CBlock& block, CValidationState& state, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev)
29963020
{
29973021
const int nHeight = pindexPrev == nullptr ? 0 : pindexPrev->nHeight + 1;

0 commit comments

Comments
 (0)