First steps towards a stateless, side-effect free validation library #35906

pull purpleKarrot wants to merge 5 commits into bitcoin:master from purpleKarrot:validation changing 5 files +300 −15
  1. purpleKarrot commented at 6:50 PM on August 5, 2026: contributor

    This implements the following actions from #35904:

    1. Expose the validation interface

      Make the existing CheckBlockHeader, ContextualCheckBlockHeader, and ContextualCheckBlock functions part of the public validation interface by declaring them in validation.h.

    2. Interface Segregation: Remove dependency on ChainstateManager

      ContextualCheck* functions need a ChainstateManager only to access the consensus parameters. Pass Consensus::Params instead and access them at the call site.

    3. Make environmental dependencies explicit

      Pass the validation time explicitly to ContextualCheckBlockHeader instead of reading the system clock internally.

  2. DrahtBot commented at 6:50 PM on August 5, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/35906.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process. A summary of reviews will appear here.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #35820 (refactor: keep duration calculations typed by l0rinc)
    • #35570 (refactor: Change some validation.cpp methods to return BlockValidationState by optout21)
    • #30342 (kernel, logging: Pass Logger instances to kernel objects by ryanofsky)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  3. in src/validation.cpp:4123 in 7b358c2637 outdated
    4119 | @@ -4121,14 +4120,14 @@ static bool ContextualCheckBlockHeader(const CBlockHeader& block, BlockValidatio
    4120 |      }
    4121 |  
    4122 |      // Check timestamp
    4123 | -    if (block.Time() > NodeClock::now() + std::chrono::seconds{MAX_FUTURE_BLOCK_TIME}) {
    4124 | +    if (block.Time() > now + std::chrono::seconds{MAX_FUTURE_BLOCK_TIME}) {
    


    maflcko commented at 6:54 AM on August 6, 2026:

    This conflicts with #35557, which is an alternative to #35496.

    No opinion on the merge order, but I think it would be good if the authors of all three alternatives provided reviews on each pull request, so that ideally the same line of code is only changed once.

  4. in src/validation.cpp:4128 in 7b358c2637 outdated
    4127 |  
    4128 |      // Reject blocks with outdated version
    4129 | -    if ((block.nVersion < 2 && DeploymentActiveAfter(pindexPrev, chainman, Consensus::DEPLOYMENT_HEIGHTINCB)) ||
    4130 | -        (block.nVersion < 3 && DeploymentActiveAfter(pindexPrev, chainman, Consensus::DEPLOYMENT_DERSIG)) ||
    4131 | -        (block.nVersion < 4 && DeploymentActiveAfter(pindexPrev, chainman, Consensus::DEPLOYMENT_CLTV))) {
    4132 | +    if ((block.nVersion < 2 && DeploymentActiveAfter(pindexPrev, consensusParams, Consensus::DEPLOYMENT_HEIGHTINCB)) ||
    


    maflcko commented at 6:57 AM on August 6, 2026:

    this partially reverts 78adef17536edef833a0bfca06b61ce28120e486. Maybe that is fine, but if the motivation is better tests, maybe the refactor change would come with better tests included?

    E.g. this pull conflicts with #34895, which seems to be adding tests.


    purpleKarrot commented at 11:13 AM on August 7, 2026:

    maybe the refactor change would come with better tests included

    Good point. Done.

  5. Make validation functions accessible
    Make the existing `CheckBlockHeader`, `ContextualCheckBlockHeader`, and
    `ContextualCheckBlock` functions part of the public validation interface
    by declaring them in `validation.h`.
    8bb61e96a7
  6. Make `ContextualCheck*` not depend on `ChainstateManager`
    `ContextualCheck*` functions need a `ChainstateManager` only to access
    the consensus parameters. Pass `Consensus::Params` instead and access
    them at the call site.
    e2dd3a1696
  7. Make `ContextualCheckHeader` not depend on system time
    Pass the validation time explicitly to `ContextualCheckBlockHeader`
    instead of reading the system clock internally.
    28bf798910
  8. validation: Add unit tests for `CheckBlockHeader` 95635188f2
  9. purpleKarrot force-pushed on Aug 7, 2026
  10. validation: Add unit tests for `ContextualCheckBlockHeader` ab1674de05

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-08-10 11:50 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me