cmpctblock: refactor: Delete unnecessary code in `PartiallyDownloadedBlock::InitData()` #35638

pull davidgumberg wants to merge 2 commits into bitcoin:master from davidgumberg:2026-06-30-cmpctblock-delete-havetxn changing 1 files +5 −11
  1. davidgumberg commented at 1:05 AM on July 2, 2026: contributor

    This is a refactor that was split out of work related to #35558.

    First, have_txn is redundant, since txn_available is a vector of shared_ptr:

    https://github.com/bitcoin/bitcoin/blob/bd1771fc0cd248438e87b028b096f59ffc976d18/src/blockencodings.h#L135

    resized:

    https://github.com/bitcoin/bitcoin/blob/bd1771fc0cd248438e87b028b096f59ffc976d18/src/blockencodings.cpp#L70

    Which means all of its members are value-initialized which for a shared_ptr means "Constructs a shared_ptr with no managed object, i.e. empty shared_ptr." and std::shared_ptr<T>::operator bool returns false for empty shared_ptr's.

    In fact, the existing code already relies on this behavior:

    https://github.com/bitcoin/bitcoin/blob/a8823c099618559fdf6116fe17c9afd311e88890/src/blockencodings.cpp#L161

    Second,

    if (a) {
        b()
    } else {
        if(!a) {
            c()
        }
    }
    

    is equivalent to

    if (a) {
        b()
    } else {
        c()
    }
    

    so I make this change.

  2. cmpctblock: refactor: Delete unnecessary `have_txn` vector dcbd5b47ca
  3. cmpctblock: refactor: Drop unnecessary if condition b55f06d0c4
  4. DrahtBot commented at 1:05 AM on July 2, 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/35638.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    Concept ACK w0xlt

    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:

    • #35558 (p2p: Prefill compact blocks by davidgumberg)

    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-->

  5. w0xlt commented at 5:44 AM on July 2, 2026: contributor

    Concept ACK

  6. l0rinc commented at 4:04 PM on July 2, 2026: contributor

    Isn't there a difference between have_txn and txn_available after a shortid duplicate resets txn_available[index]? A later match for the same index would still see have_txn[index] == true before this PR, but not after this PR. Is this still a refactor?

  7. bitcoin deleted a comment on Jul 2, 2026
  8. davidgumberg commented at 8:07 PM on July 2, 2026: contributor

    Isn't there a difference between have_txn and txn_available after a shortid duplicate resets txn_available[index]? A later match for the same index would still see have_txn[index] == true before this PR, but not after this PR. Is this still a refactor?

    Ah, good point! So, in the case where a collision has already happened, and there is a third transaction with the same shortid, this PR would cause a node to accept the third transaction instead of continuing on with txn_available[idit->second] == false.

    This PR was based on a misunderstanding so I'll close, thanks for catching.

  9. davidgumberg closed this on Jul 2, 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-07-05 11:51 UTC

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