refactor: decompose Peer struct into focused sub-components #34588

pull w0xlt wants to merge 5 commits into bitcoin:master from w0xlt:refactor/decompose-peer-struct changing 1 files +243 −223
  1. w0xlt commented at 2:47 am on February 14, 2026: contributor

    The Peer struct in net_processing.cpp has ~40 fields protected by 6 different mutexes, mixing address relay, headers sync, block announcements, ping/pong, transaction relay, and misbehavior state into one flat struct. This makes it hard to see which fields belong together and which mutex protects what.

    This PR groups related fields into four sub-structs, each owning its mutex where applicable:

    Sub-struct Fields Mutex
    PeerAddrRelay 12 m_addr_send_times_mutex
    PeerHeadersSyncState 7 m_headers_sync_mutex
    PeerBlockAnnouncement 3 m_block_inv_mutex
    PeerLatency 3 (all atomic)

    Access changes from flat (peer.m_addrs_to_send) to qualified (peer.m_addr_relay.m_addrs_to_send). No locking semantics, runtime behavior, or public interfaces change.

    The first commit defines the four structs and adds them as members of Peer. The remaining four commits each move one group of fields and update all call sites.

  2. refactor: define Peer sub-structs for addr, headers, blocks, latency
    Define four new sub-structs in the anonymous namespace before Peer:
    - PeerAddrRelay: address gossip fields and mutex
    - PeerHeadersSyncState: headers sync fields and mutex
    - PeerBlockAnnouncement: block inv relay fields and mutex
    - PeerLatency: ping/pong atomics (no mutex needed)
    
    Add four member objects to Peer (m_addr_relay, m_headers_sync_state,
    m_block_announcement, m_latency). No call sites change yet -- old
    fields still exist alongside the new sub-struct members.
    
    This prepares for subsequent scripted-diff commits that will move
    fields from Peer into the corresponding sub-structs.
    249e6a1c09
  3. refactor: move address relay fields into Peer::m_addr_relay
    Move-only rename: all address relay fields (m_addrs_to_send,
    m_addr_known, m_addr_relay_enabled, m_getaddr_sent, m_getaddr_recvd,
    m_wants_addrv2, m_addr_token_bucket, m_addr_token_timestamp,
    m_addr_rate_limited, m_addr_processed, m_next_addr_send,
    m_next_local_addr_send, m_addr_send_times_mutex) are moved from
    Peer into Peer::m_addr_relay (PeerAddrRelay sub-struct).
    
    Also moves m_inv_triggered_getheaders_before_sync into
    Peer::m_headers_sync_state since it was adjacent to the removed
    addr fields and belongs to headers sync state.
    
    Delete original fields from Peer, update all ~50 call sites.
    15a927b975
  4. refactor: move headers sync fields into Peer::m_headers_sync_state
    Move-only rename: all headers sync fields (m_headers_sync_mutex,
    m_headers_sync, m_sent_sendheaders, m_headers_sync_timeout,
    m_prefers_headers, m_last_getheaders_timestamp) are moved from
    Peer into Peer::m_headers_sync_state (PeerHeadersSyncState sub-struct).
    
    Update EXCLUSIVE_LOCKS_REQUIRED annotations on
    IsContinuationOfLowWorkHeadersSync() and TryLowWorkHeadersSync()
    to reference peer.m_headers_sync_state.m_headers_sync_mutex.
    
    Delete original fields from Peer, update all ~40 call sites.
    406ad938da
  5. refactor: move block announcement fields into Peer::m_block_announcement
    Move-only rename: all block announcement fields (m_block_inv_mutex,
    m_blocks_for_inv_relay, m_blocks_for_headers_relay,
    m_continuation_block) are moved from Peer into
    Peer::m_block_announcement (PeerBlockAnnouncement sub-struct).
    
    Delete original fields from Peer, update all ~25 call sites.
    bb5f95a266
  6. refactor: move ping/pong fields into Peer::m_latency
    Move-only rename: all latency measurement fields (m_ping_nonce_sent,
    m_ping_start, m_ping_queued) are moved from Peer into
    Peer::m_latency (PeerLatency sub-struct).
    
    All fields are atomic so no mutex is needed for the sub-struct.
    
    Delete original fields from Peer, update all ~25 call sites.
    eea7d69707
  7. DrahtBot added the label Refactoring on Feb 14, 2026
  8. DrahtBot commented at 2:47 am on February 14, 2026: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Reviews

    See the guideline for information on the review process. A summary of reviews will appear here.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #34565 (refactor: extract BlockDownloadManager from PeerManagerImpl by w0xlt)
    • #34389 (net/log: standardize peer+addr log formatting via LogPeer by l0rinc)
    • #34059 (refactor: Use NodeClock::time_point for m_addr_token_timestamp by maflcko)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

    LLM Linter (✨ experimental)

    Possible typos and grammar issues:

    • will not potentially leaking addr information -> will not potentially leak addr information [grammatical error: incorrect verb form “leaking” should be the base form “leak” to follow “will not potentially”]

    Possible places where named args for integral literals may be used (e.g. func(x, /*named_arg=*/0) in C++, and func(x, named_arg=0) in Python):

    • LogDebug(BCLog::NET, “ping timeout: %fs, %s”, 0.000001 * count_microseconds(now - peer.m_latency.m_ping_start.load()), node_to.DisconnectMsg(fLogIPs)) in src/net_processing.cpp

    2026-02-14 02:47:54

  9. DrahtBot added the label CI failed on Feb 14, 2026

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-02-17 06:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me