Page MenuHomePhabricator

net/net_processing: Add thread safety related annotations for CNode and Peer
ClosedPublic

Authored by PiRK on Jun 13 2025, 08:52.

Details

Summary

Adds GUARDED_BY and const annotations to document how we currently ensure various members of CNode and Peer aren't subject to race conditions.

net/net_processing: add missing thread safety annotations

https://github.com/bitcoin/bitcoin/pull/25174/commits/06ebdc886fcb4ca22f695bafe0956cff6d70a250

net: mark TransportSerializer/m_serializer as const

The (V1)TransportSerializer instance CNode::m_serializer is used from
multiple threads via PushMessage without protection by a mutex. This
is only thread safe because the class does not have any mutable state,
so document that by marking the methods and the object as "const".

https://github.com/bitcoin/bitcoin/pull/25174/commits/bbec32c9ad2fe213314db9d39aa1eacff2e0bc23

net: mark CNode unique_ptr members as const

Dereferencing a unique_ptr is not necessarily thread safe. The reason
these are safe is because their values are set at construction and do
not change later; so mark them as const and set them via the initializer
list to guarantee that.

https://github.com/bitcoin/bitcoin/pull/25174/commits/ef26f2f421071986a3878a1a94b0149ae8e16fcd

The last commit adding comments about constness is bypassed by D17110 which makes the members actually const.

This is a backport of core#25174
Depends on D18249

Test Plan

ninja all check-all

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

PiRK requested review of this revision.Jun 13 2025, 08:52
Unknown Object (User) added a subscriber: Unknown Object (User).Jun 13 2025, 09:35
This comment was removed by Fabien.
Unknown Object (User) added a subscriber: Unknown Object (User).Jun 13 2025, 10:34
This comment was removed by Fabien.
This revision is now accepted and ready to land.Jun 13 2025, 11:03
Unknown Object (User) added a subscriber: Unknown Object (User).Jun 19 2025, 21:51
This comment was removed by Klakurka.
Unknown Object (User) added a subscriber: Unknown Object (User).Jun 20 2025, 21:26
This comment was removed by Klakurka.
Unknown Object (User) added a comment.Jun 20 2025, 21:44
This comment was removed by Unknown Object (User).