mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 10:29:40 +00:00
refactor: Extract per-message helpers from SendMessages() (move-only) #35522
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!35522
Loading…
Reference in a new issue
No description provided.
Delete branch "refactor/extract-sendmessages-helpers"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
PeerManagerImpl::SendMessages()is a ~500-line function handling every p2p conditional send message type inline, which makes it hard to navigate and review. This was reduced to less than 90 lines.I've identified this issue/ possible improvement while reviewing #34824.
-Notes:
First (prepare) commit removes the unnecessary
__func__prefix from the debug logs in SendMessages(), as suggested by maflcko. The logging macros already capture the calling function viaSourceLocation, available on demand with-logsourcelocations.Each of the following 17 commits represents a helper function extraction so it can be easily reviewed, it's only a pure code move, the only new lines are the declaration (with thread-safety annotations), the function signature, and the one-line call site, and they can be reviewed with the git options:
--color-moved=dimmed-zebra --color-moved-ws=ignore-all-space.One final cleanup commit normalises formatting and simplifies some of the extracted helpers, preserving existing control flow and lock scopes.
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
External sites
Reviews
See the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste
<!--meta-tag:bot-skip-->into the comment that the bot should ignore.Conflicts
Reviewers, 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.
@w0xlt, my first impulse is to put it into draft till your both PRs #34824 and #35502 land and get merged before but perhaps you find this useful and easier to work on those changes on top of this one?
Approach ACK, same pattern as https://github.com/bitcoin/bitcoin/pull/35502.
MaybeSendTxMessagesacquires tx_relay lock internally.It only requires
cs_mainandg_msgproc_mutexheld.I don’t think this PR needs to be draft. Keeping it open is useful for review.
If this, #34824, or #35502 lands first, rebasing should be straightforward.
Done. Thanks!
-Updates:
MaybeSendTxMessages(), observed by @w0xlt.(iwyu CI failure is not related and I think it's being fixed in #35535)
🚧 At least one of the CI tasks failed.
Task
iwyu: https://github.com/bitcoin/bitcoin/actions/runs/27553084448/job/81447465260LLM reason (✨ experimental): CI failed because IWYU detected and auto-modified an include in
src/bench/pool.cpp(and intentionally returned failure: “Failure generated from IWYU”).Hints
Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:
Possibly due to a silent merge conflict (the changes in this pull request being
incompatible with the current code in the target branch). If so, make sure to rebase on the latest
commit of the target branch.
A sanitizer issue, which can only be found by compiling with the sanitizer and running the
affected test.
An intermittent issue.
Leave a comment here, if you need help tracking down a confusing failure.
🐙 This pull request conflicts with the target branch and needs rebase.
-Updates:
🐙 This pull request conflicts with the target branch and needs rebase.
Concept ACK
Was recently reviewing some code here and felt it would have been nice to be able to refer to smaller parts of
SendMessages()by name.I rebased this branch locally onto
bfdcd9797cand I tried a few non-blocking cleanups locally, similar to those in #35502:Details
fRevertToInvcondition; normalized pointer/reference spacing and single-statement if formatting.MaybeSendInitialGetheaders()toMaybeSendInitialGetHeaders(), matchingMaybeSendGetHeaders().MaybeSendTxMessages()under oneif (ScheduleTxRelayTrickle(...)), removing the temporary and repeated checks.MaybeSendMempoolResponse()and staller conditions inQueueBlocksGetData(), preserving short-circuit evaluation.size()with zero withempty()inMaybeSendTxInventory()andCheckBlockFlightTimeout().CheckBlockSyncTimeouts()to returnCheckHeadersSyncTimeout(...)directly. InComputeSyncBlocksAndHeaders(), removed the redundantelseafterreturnand returned the final boolean condition directly.diff
I also adjusted the commit history:
__func__log-prefix changes in the relevant extraction messages: firstSendMessages→MaybeSendBlockAnnouncements, then three logs →SendCompactBlockOrHeadersand one →SendBlockInvFallback.MaybeSendTxMessages(),CheckBlockFlightTimeout(),CheckHeadersSyncTimeout(), andQueueTxGetData().Indentation-only adjustments are included in the extraction commits, with the remaining formatting and refactoring changes batched into one cleanup commit at the end.
Or, if you prefer, you can use the updated branch with these changes already applied:
https://github.com/w0xlt/bitcoin/tree/refactor/extract-sendmessages-helpers
Earlier concerns neither republished nor resolved: 5 suggestions. See the Run archive linked from the Review report for their assessments.
No findings were published from this review.
Reviewed:
53e896e930f6· Review report · Previous reportspermalink
ACK
78a02a9588Thanks for the rebase, the cleanup suggestions, and the commit-history reorganization, @w0xlt — appreciated.
-Updates:
SendMessages()upstream after the previous rebase base, now folded intoCheckBlockSyncTimeouts()(d83647e7c4in #36080).__func__log-prefix documentation within affected commit messages;This gives me LLM vibes. Can you please write the description in your own words? See https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md
Forcing reviewers to count all
__func__seems like busy work and all the weird formatting will likely look ugly in a terminal-printedgit log.In any case, the logs shouldn't be using
__func__anyway. Each log line should be unique and descriptive by itself. Maybe a prepare commit can be added to do that?I think all of those mentions can be removed, as they are about the processing side, not the sending side.
Thanks @maflcko!
Ok, it doesn't sound to me like that but given the reasons below I'll remove it anyway. I originally included it because a reviewer had already flagged that "move-only" wasn't quite accurate — the log calls print different output on this branch (the new extracted function names) versus master (
SendMessages) — so I thought it was worth calling out in the description too.Ok, I'll take it into account for next PRs, and I also forgot about the
git logconsequences. Again, it will be removed as part of the change you suggested below.I'd do that, sure — I see the logging macros already capture the function name/file/line automatically via
SourceLocation, and it's available on demand with-logsourcelocations, so there's no need to hand-embed__func__in the message.I'll remove that too; it seems misleading.
-Updates:
__func__prefix from the debug logs inSendMessages().reACK
4d707f65bdThis conflicts with a reviewed pull that is marked for possible backport. I think it is a better use of review resources to defer this pull and rebase/review it later than to make the backport differ, which would require additional review/"rebase".
Converting to draft. I'll rebase once #36521 gets in.
-Updates:
reACK
53e896e930