#36244 validation, net: Process blocks asynchronously and reduce cs_main contention

full analysis

https://github.com/bitcoin/bitcoin/pull/36244 · w0xlt · +3134/-294 in 41 files, 20 commits · labels: none · draft

Goal

  • Keep nodes responsive to peers and avoid network latency spikes while validating incoming blocks
  • Ensure compact block responses and regular peer messaging stay fast during heavy validation load

This PR moves block processing off the P2P message processing thread onto a dedicated asynchronous worker thread. Initial header and validity checks continue to run synchronously, after which admitted blocks are queued for storage and chain activation. In addition, it reduces cs_main locking across P2P message handling, tracking block sources and downloads under dedicated mutexes.

Problem: The P2P message processing thread currently blocks synchronously while validating and connecting new blocks under cs_main. During initial block download or heavy validation at the tip, the node cannot respond to other peers' PINGs, compact block transaction requests, or block download requests in a timely manner.

Category: Validation (#8 of 48)

P2 · speedup

  • P2 because it mitigates validation lock contention on the main critical section
  • Unblocks future architectural improvements such as parallel sibling block validation

Substantially refactors the block acceptance and persistence pipeline to run asynchronously on a dedicated worker, directly tackling cs_main contention and unblocking future parallel validation work.

Membership: Refactors ProcessNewBlock, separates block storage admission from persistence, introduces ValidationQueue, and delivers BlockChecked asynchronously.

Factors: security/stability 1, bug 0, performance 2, user value 1, leverage 2

Category: P2P (#5 of 65)

P2 · DoS protection

  • P2 because it resolves a major responsiveness bottleneck where peers time out during block validation
  • Ping latency drops by 98 percent and block-serving response times improve up to 45 percent under load

Prevents the P2P message handler from stalling during block processing, directly improving node responsiveness and DoS resistance with a measured 98% reduction in PING response latency during heavy validation.

Membership: Modifies net_processing.cpp to decouple P2P message processing from block validation, moves block download tracking out of cs_main, and avoids unnecessary lock waits.

Factors: security/stability 2, bug 0, performance 2, user value 1, leverage 1

Reviewability: Ready

  • Ready for review now, passing CI with extensive unit and regression test coverage

The author opened this draft to gather feedback on the overall approach, but the branch compiles cleanly, passes tests, and has no pending reviewer blocks.

Author status: Active; responded to concept questions from andrewtoth.

Agreement: Crickets

  • Early architectural discussion is positive with no objections raised
  • Points out steady-state message processing and compact-block serving as key benefits (andrewtoth)
  • Notes that it enables eventual parallel validation of competing sibling blocks (andrewtoth)

Crickets; andrewtoth asked about design motivation and parallel validation, answered by author.

The PR has not yet received formal ACKs or substantive code reviews.

  • 2026-09-15: andrewtoth asked whether the main point is steady-state responsiveness and parallel sibling validation.
  • 2026-09-15: w0xlt clarified that responsiveness at the tip is indeed the main motivation and benchmarked IBD as a repeatable workload.

Objections: none enumerated.

Participants: andrewtoth (question)

State derived from the lists: no substantive comment either way

Review verdicts (DrahtBot): 0

Dependencies

Enables:

  • Parallel sibling block validation and further cs_main concurrency improvements

Files

2284 lines under test/bench/ci.

  • src/test/peerman_tests.cpp +1229/-2
  • src/net_processing.cpp +320/-144
  • src/test/validation_queue_tests.cpp +319/-0
  • src/test/validation_block_tests.cpp +272/-7
  • src/validation.cpp +144/-60
  • src/test/validationinterface_tests.cpp +167/-3
  • src/validation_queue.cpp +120/-0
  • src/test/util/validation.cpp +103/-0
  • src/validation.h +79/-9
  • src/validation_queue.h +88/-0
  • src/test/util/validation.h +71/-6
  • src/primitives/block.h +37/-7
  • src/node/miner.cpp +21/-15
  • src/kernel/bitcoinkernel.cpp +16/-7
  • src/rpc/mining.cpp +14/-6
  • src/test/util/mining.cpp +11/-8
  • src/validationinterface.cpp +13/-3
  • src/blockencodings.h +10/-4
  • src/test/blockfilter_index_tests.cpp +10/-3
  • src/test/fuzz/cmpctblock.cpp +11/-1
  • src/test/fuzz/process_messages.cpp +11/-1
  • src/test/baseindex_tests.cpp +6/-1
  • src/test/util/net.h +7/-0
  • src/validationinterface.h +7/-0
  • src/bench/blockencodings.cpp +4/-2
  • src/init.cpp +6/-0
  • src/net_processing.h +6/-0
  • src/test/util/setup_common.cpp +5/-1
  • src/test/validation_tests.cpp +3/-3
  • src/test/txindex_tests.cpp +5/-0
  • src/test/validation_chainstate_tests.cpp +3/-1
  • src/net.h +3/-0
  • src/net.cpp +2/-0
  • src/test/coinstatsindex_tests.cpp +2/-0
  • src/test/fuzz/util/net.h +2/-0
  • src/test/txospenderindex_tests.cpp +2/-0
  • src/CMakeLists.txt +1/-0
  • src/kernel/CMakeLists.txt +1/-0
  • src/kernel/chainstatemanager_opts.h +1/-0
  • src/test/CMakeLists.txt +1/-0
  • src/test/validation_chainstatemanager_tests.cpp +1/-0

Card

PR #36244 moves block processing off the P2P message thread onto a dedicated worker thread after initial validation checks, reducing cs_main contention and preventing network message handling from stalling. Benchmark results show up to a 98% reduction in PING response latency and a 30-45% reduction in block-serving response times during validation. It establishes foundational architecture towards parallel sibling block validation. The PR is currently marked draft for concept feedback with no formal reviews yet.

Data

dossier JSON · extract JSON · model openrouter/google/gemini-3.8-flash, generated 2026-09-17T21:49, confidence high, input hash 1baf905440535b42