#36445 net: Skip cs_main when a peer has no orphan work
| Reviewability | Reviews | Agreement | Size | ||||
|---|---|---|---|---|---|---|---|
| #36445 net: Skip cs_main when a peer has no orphan work | Ready | 0 | Crickets | 2 + 36 tests | |||
|
|
|
|
| |||
Reviewability: ReadyStalePaused Agreement: StrongPositivePositive w/ caveatsNeutralMildDisputedBlockedCrickets Reviews: current code-review ACKs, then (+stale ACKs) and -NACKs; greener = more ACKs. Size: lines added or modified outside tests, then in tests; greener = smaller. | |||||||
Goal
Check whether a peer has orphan transactions waiting under m_tx_download_mutex before acquiring cs_main in ProcessOrphanTx. When no orphan work is queued, ProcessOrphanTx returns immediately without contending for cs_main. A unit test verifies ProcessMessages completes while cs_main is held elsewhere.
Problem: ProcessMessages routinely calls ProcessOrphanTx on each message-processing pass, acquiring cs_main unconditionally even when a peer has no orphan work. P2P message processing for that peer then blocks whenever validation, RPC, or wallet threads hold cs_main.
Evidence of importance:
- Author microbenchmarks show ProcessMessages handling a ping taking 50.1 ms on master when cs_main is held for 50 ms by another thread, dropping to 0.02 ms with this change.
- A unit test (process_messages_without_orphan_work) reproduces the block on master and passes with this change.
Scope: Small two-line change in net_processing.cpp paired with a multithreaded unit test in peerman_tests.cpp.
Risk of a mistake: low (p2p). A race condition or locking bug here could delay orphan transaction processing or cause deadlocks during P2P message handling.
Reviewability
Ready
Nothing known that would invalidate a review now.
Waiting on (from the thread read):
- reviewer: review of the PR and response to author explanation 2026-10-06
Agreement
Crickets
no substantive comment either way
Thread notes: Author updated the PR description for clarity; no new claims or reviews were added.
Objections, suggestions, and questions:
| Reviewer | Type | Harm, request, or question | Status | Must be | Author replied | Quote |
|---|---|---|---|---|---|---|
| instagibbs (member) | suggestion, usefulness | Only pursue this refactor if/when #36244 is an accepted goal for the project | answered · author explained that skipping cs_main without orphan work is beneficial on master on its own | answered | yes | 2026-10-06: 'I think these kind of refactors only make sense if/when https://github.com/bitcoin/bitcoin/pull/36244 is an accepted goal by the project' Status from: 2026-10-06: w0xlt: 'This PR stands on its own, though: skipping `cs_main` when a peer has no orphan work helps on master today, with or with' |
Participants:
- instagibbs (member, neutral, 1 statements 2026-10-06 to 2026-10-06): noted that such refactors may only make sense if #36244 is an accepted project goal
Files
36 lines under test/bench/ci.
- src/test/peerman_tests.cpp +36/-0
- src/net_processing.cpp +2/-0
Card
The short text the ranking pass compares across PRs.
Skips acquiring cs_main in ProcessOrphanTx when a peer has no orphan transactions queued, checking under m_tx_download_mutex first. Currently, ProcessMessages acquires cs_main unconditionally on every peer handler pass, blocking P2P message processing whenever validation, RPC, or wallet threads hold cs_main. In author benchmarks where cs_main was held for 50 ms, ping handling latency dropped from 50.1 ms to 0.02 ms. The PR is self-contained and related to broader lock-reduction work in #36244.
Data
thread read through 2026-10-07 (3 statements), head 6549bb4bd6
labels: P2P
Categories
P2P
P2 · speedup (ranking pass: Measured responsiveness win in the message loop; grouped with the other cs_main contention work.)
Eliminating unconditional `cs_main` acquisition in `ProcessOrphanTx` prevents peer message processing from blocking whenever validation, RPC, or wallet threads hold the lock. Microbenchmarks showed ping handling latency dropping from 50.1 ms to 0.02 ms during concurrent lock contention.
Membership: Touches `src/net_processing.cpp` to optimize peer message handling and carries the P2P label.
Factors: security/stability 1, bug 0, performance 2, user value 0, leverage 0