refactor: decompose Peer struct into focused sub-components#34588
Open
w0xlt wants to merge 5 commits intobitcoin:masterfrom
Open
refactor: decompose Peer struct into focused sub-components#34588w0xlt wants to merge 5 commits intobitcoin:masterfrom
w0xlt wants to merge 5 commits intobitcoin:masterfrom
Conversation
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.
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.
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.
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.
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.
Contributor
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ReviewsSee the guideline for information on the review process. ConflictsReviewers, this pull request conflicts with the following ones:
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:
Possible places where named args for integral literals may be used (e.g.
2026-02-14 02:47:54 |
This was referenced Feb 14, 2026
This was referenced Mar 4, 2026
Contributor
|
🐙 This pull request conflicts with the target branch and needs rebase. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
Peerstruct innet_processing.cpphas ~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:
PeerAddrRelaym_addr_send_times_mutexPeerHeadersSyncStatem_headers_sync_mutexPeerBlockAnnouncementm_block_inv_mutexPeerLatencyAccess 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.