refactor: Use CBlockIndex parameters as reference #35229

pull optout21 wants to merge 6 commits into bitcoin:master from optout21:2605-block-param-ref changing 12 files +68 −60
  1. optout21 commented at 7:11 AM on May 7, 2026: contributor

    This is a janitorial refactor, a continuation of #34440. Input method parameters of type const CBlockIndex* are changed to reference const CBlockIndex& in some places where it makes no sense to call with a nullptr.

    Motivation: slight improvement in code quality, maintainability and robustness.

    • more explicit representation of the non-null input invariant
    • less chance of nullptr-access error with future code changes
    • more explicit checks at call sites for the non-null input invariant.

    The following methods are affected:

    • LastCommonAncestor() in chain.h
    • PeerManagerImpl::FindNextBlocks() (net_processing.cpp)
    • PeerManagerImpl::TryDownloadingHistoricalBlocks() (net_processing.cpp)
    • BlockFilterIndex::LookupFilterRange(), BlockFilterIndex::LookupFilterHashRange() (blockfilterindex.h), and LookupRange() in blockfilterindex.cpp
    • BaseIndex::ProcessBlock() (base.h)

    General guidelines:

    • When a method has an input of type const CBlockIndex*, and by contract it cannot be nullptr, change it to const CBlockIndex&. The reference type is an implicit documentation of the nun-nullptr invariant.
    • When calling a method with reference parameter, ensure that it cannot be nullptr (it is often derived from a pointer), by/because:
      • explicit prior check and error handling
      • an assert/Assert/Assume
      • itself being a non-nullptr invariant input
      • it is being an output from a method with no-nullptr output invariant
    • For local variables, use reference types whenever possible, for non-nullptr references
    • For technical reasons pointers are still used even in some non-nullptr cases:
      • containers/variables that can staty unitialized initially
      • containers that need reserve()
      • using reference type in std::set would result in some copy constructor calls
      • std::optional cannot hold a reference type
  2. refactor: In LastCommonAncestor, change CBlockIndex input to reference 0c6ca30471
  3. refactor: In FindNextBlocks, change CBlockIndex input to reference a0dfcd63ef
  4. DrahtBot added the label Refactoring on May 7, 2026
  5. DrahtBot commented at 7:11 AM on May 7, 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/35229.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    Concept ACK stickies-v

    If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #24230 (indexes: Stop using node internal types and locking cs_main, improve sync logic 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-->

  6. refactor: Assert and comments to ensure vBlocks never contains null 16bfd673ac
  7. refactor: In TryDownloadingHistoricalBlocks, change CBlockIndex input to reference 98942506aa
  8. refactor: In LookupX methods, change CBlockIndex input to reference
    Methods affected: BlockFilterIndex::LookupFilterRange, BlockFilterIndex::LookupFilterHashRange,
    and LookupRange, in blockfilterindex.
    02d383ec73
  9. refactor: In ProcessBlock change CBlockIndex input to reference dfe6221407
  10. optout21 force-pushed on May 7, 2026
  11. DrahtBot added the label CI failed on May 7, 2026
  12. in src/net_processing.cpp:928 in dfe6221407
     926 |      * \param vBlocks      Vector of blocks to download which will be appended to.
     927 | +    *                     Must not contain nullptr.
     928 |      * \param peer         Peer which blocks will be downloaded from.
     929 |      * \param state        Pointer to the state of the peer.
     930 | -    * \param pindexWalk   Pointer to the starting block to add to vBlocks.
     931 | +    * \param indexWalk    The starting block to add to vBlocks.
    


    stickies-v commented at 7:52 AM on May 7, 2026:

    nit: developer notes prefer camel_case while you're touching this

  13. stickies-v commented at 7:52 AM on May 7, 2026: contributor

    Concept ACK

  14. DrahtBot removed the label CI failed on May 7, 2026
  15. optout21 marked this as ready for review on May 9, 2026

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-05-11 12:12 UTC

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