net: Skip cs_main when a peer has no orphan work #36445

pull w0xlt wants to merge 1 commits into bitcoin:master from w0xlt:net/orphan-check-without-cs-main changing 2 files +38 −0
  1. w0xlt commented at 2:18 AM on October 6, 2026: contributor

    ProcessMessages takes cs_main for every peer on every handler pass, just to check for orphan transactions to reconsider, though most peers have none. This PR checks for orphan work under m_tx_download_mutex first and skips cs_main when there is none. Peers with orphan work take the same path as before, plus one uncontended lock.

    This removes needless cs_main contention with validation, RPC and wallet threads. It's part of a broader effort to reduce cs_main contention in net processing (see #36244 for context), but stands on its own.

    ProcessMessages handling a ping master this PR
    no contention 0.005 ms 0.005 ms
    another thread holds cs_main for 50 ms 50.1 ms 0.02 ms

    Release builds, median of 3 runs. SendMessages in the same handler pass still takes cs_main.

    Tested by process_messages_without_orphan_work, which fails without this change.

  2. net: Skip cs_main when a peer has no orphan work
    ProcessMessages reconsiders a peer's orphan transactions before taking
    its next message, and took cs_main for this even when the peer had
    none. Check for orphan work under m_tx_download_mutex first, so that a
    message from a peer without orphan work does not wait for a busy
    chainstate.
    
    Test that ProcessMessages completes for such a peer while cs_main is
    held.
    6549bb4bd6
  3. DrahtBot added the label P2P on Oct 6, 2026
  4. DrahtBot commented at 2:18 AM on October 6, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    External sites

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

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

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    No conflicts as of last run.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  5. instagibbs commented at 11:33 AM on October 6, 2026: member

    I think these kind of refactors only make sense if/when #36244 is an accepted goal by the project

    I have not actually looked, just noting for this PR's sake.

  6. w0xlt commented at 3:47 PM on October 6, 2026: contributor

    This PR stands on its own, though: skipping cs_main when a peer has no orphan work helps on master today, with or without #36244. #36244 just benefits more from it.

  7. w0xlt commented at 5:41 AM on October 7, 2026: contributor

    PR description updated for greater clarity.


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-10-17 22:51 UTC

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