HomePhabricator

net: add NetEventsInterface::g_msgproc_mutex

Description

net: add NetEventsInterface::g_msgproc_mutex

Summary:

net: add NetEventsInterface::g_msgproc_mutex

There are many cases where we assume message processing is
single-threaded in order for how we access node-related memory to be
safe. Add an explicit mutex that we can use to document this, which allows
the compiler to catch any cases where we try to access that memory from
other threads and break that assumption.

https://github.com/bitcoin/bitcoin/pull/26036/commits/1e78f566d575a047a6f0b762bc79601e0208d103

net: drop cs_sendProcessing

SendMessages() is now protected g_msgproc_mutex; so this additional
per-node mutex is redundant.

https://github.com/bitcoin/bitcoin/pull/26036/commits/bf12abe4542f2cf658516ea7e7fbbff6864c2208

net_processing: add thread safety annotations for Peer members accessed only via the msgproc thread

https://github.com/bitcoin/bitcoin/pull/26036/commits/a66a7ccb822f0f1f554d27d04735b7fb585d3b71
https://github.com/bitcoin/bitcoin/pull/26036/commits/0ae7987f68211729d87c9255889f4d9d1aa6a37f

This is a partial backport of core#26036

Review notes:

  • we don't yet call SendMessages yet in the process_message.cpp and process_messages.cpp fuzzers in our codebase, but I decided to add the lock anyway because it is likely that it will be missed when we eventually backport the code that requires the lock
  • m_addr_token_bucket is accessed from multiple threads and has its own lock in our codebase: D11035

Test Plan:
With debug

ninja all check-all bitcoin-fuzzers

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D15286

Details

Provenance
Anthony Towns <aj@erisian.com.au>Authored on Sep 7 2022, 03:57
PiRKCommitted on Jan 26 2024, 16:30
PiRKPushed on Jan 26 2024, 16:30
Reviewer
Restricted Project
Differential Revision
D15286: net: add NetEventsInterface::g_msgproc_mutex
Parents
rABCb3a720827dfe: [e.cash] Update header for 2024
Branches
Unknown
Tags
Unknown