Depends on (includes) #9289. This is what I ultimately set out to fix with the net refactor.
In my (short) tests, it cuts network latency to ~50%. In some cases, more like 30%.
Test method: 1 fresh node (macbook) connected to a single other node (desktop). Testnet. Running until synced to block 10000. Results:
0new = patched with this PR.
1old = running [#9289](/bitcoin-bitcoin/9289/).
2client / server
3old / old: 100000 in 8:05
4new / old: 100000 in 3:24
5new / new: 100000 in 2:16
The results are very reproducible, always within a few seconds. Not only is it a nice improvement for the fresh node, but it compounds when its peer is running the updated code as well.
I had hoped to have the abstraction complete in time for 0.14, but it looks like that’s unlikely at this point. For reference, it would look something more like https://github.com/theuni/bitcoin/commit/1a6b10aea129ac363727c2d68fae809c2861e4da.
Anyway, this is an attempt to fix the actual issue in time for 0.14, and putting off the last bit of refactor until after that. This addresses the issue observed in #9415, but also cleans up the nasty locking issues.
I labeled this WIP because there are probably still several racy bits. Quite a bit of test-writing remains.
See the individual commits for the details. tl;dr: We currently either process a peer’s message or read from their socket, but never both simultaneously. The changes here remove that restriction.