RFC: CChain Concurrency Improvement
This PR implements a copy-on-write based CChain design to enable concurrent access.
Motivation
Current CChain uses a single vector protected by cs_main, creating bottlenecks for multi-threaded access. This PR lays the groundwork for removing cs_main locks by enabling consistent snapshots without holding locks.
Design
See full design document: CChain Concurrency (Out of date after mutex removal - will be updated soon)
TL;DR: Split chain into base (bulk of history) + tail (recent ~1,000 blocks). Use nested stlab::copy_on_write so updates copy only tail, keeping base shared.
Thanks to @purplekarrot for pointing me to stlab::copy_on_write and making design suggestions.
Changes
- Implements copy-on-write based CChain with value semantics
- Removes
cs_mainlocks from RPC methods (where possible) - All validation locks remain in place (
cs_mainstill held during validation) - API unchanged - backward compatible
Request for Comments
- Is the nested copy-on-write architecture sound?
- Is
MAX_TAIL_SIZE = 1000reasonable? - What are the concerns for future lock removal?
- Is the added complexity worth the benefit?