This is a bit of a rework of #16175, which is a rework of #12934. Built on top of #16279.
This is a roughly-minimal patchset to get PNB processing blocks in the background in a clean way, however it doesn’t actually enable any material parallelism yet - it only sets up a structure for significantly untangling cs_main in coming work.
Next steps:
- Notably, ProcessMessages will now call PNB, get a future for the block being fully processed, and then immediately block on cs_main waiting to process reject messages and other CNodeState data. This is rather easy to resolve using the new CPeerState (see comment about how we should slowly move things into CPeerState to reduce cs_main contention).
- In parallel, PNB (and, thus, CheckBlock, and the pre-store AcceptBlock bits) should start losing cs_main, this is primarily doable by splitting mapBlockIndex out of cs_main (probably via something like mempool.cs, where a cs_blockindex acts as a read mutex while writers take cs_main. Given the prevalence of cs_main calls just to look up entries in mapBlockIndex, this should improve things pretty significantly.