Repository navigation
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. External sites
ReviewsSee the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste 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. |
|
Concept ACK. Pretty straightforward change that makes it easier to navigate net_processing and better encapsulates logic. |
pablomartin4btc
left a comment
There was a problem hiding this comment.
Concept ACK.
I'm in favour of these refactoring, while reviewing #34824 also identified another possible candidate SendMessages() which is in the same file.
|
code review ACK 4fe745f |
pablomartin4btc
left a comment
There was a problem hiding this comment.
ACK 4fe745f.
ProcessMessage() went from ~1500 to ~1000 lines, but CMPCTBLOCK (248 lines) and VERSION (235 lines) remain the two dominant inline blocks — extracting those two alone would drop it another ~480 lines, bringing it under 550. The same move-only pattern applied here would make both independently reviewable. Not a blocker, perhaps worth a follow-up PR in the same vein?
On a side note, on the previous attempt mentioned above, there were concerns about "obscuring the control flow", I don't think this is the case here.
|
Concept -0 Let's say I'm reading a function called
These questions have to be answered when reading / modifying code and for all of the logic that lives in the I think the main thing I don't share is the feeling that Not trying to bikeshed, the PR seems reasonable and everything would be fine if it was merged, just the POV of one person that happens to like |
|
@davidgumberg Fair point. I agree the cost is real when a helper has multiple callers like These extractions are different though: they are private, single-caller helpers from The benefit I see is lock reasoning. EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex, !m_most_recent_block_mutex,
!m_headers_presync_mutex, g_msgproc_mutex,
!m_tx_download_mutex)After extraction, each handler states only what it actually needs. For example, So this does not add runtime safety by itself, but it makes the per-message lock contract more local and compiler-checked. Besides that, |
Should be easy to answer with 'yes', otherwise the function wouldn't sit in the peer manager impl?
Edit: I'd say generally the goal should be to avoid setup, but here it should be obvious from the function signature, which is passed
Should be easy to answer by looking at the header: If the function is public in the header, it is called externally. If it is not in the header, then it is not called externally. Generally, I don't think any
Should be easy to answer with yes, because no process handler was ever exposed publicly. Also, it should be easy to verify with a single call to Generally, I think the benefits here are limited, because devs generally know that at most a single message is handled in the large body (and thus no variables leak from one message handling block to the next). However, I think there is still a benefit in being able to review code changes with the git option Previously, it would basically print the whole file, even if only a single line in a single message type handling was changed. At least for me this makes review harder because I have to scroll past the irrelevant white lines every time and risk missing a green or red line. After this change, @w0xlt Please don't |
I meant directly, this is basically the same point as the set-up one.
Right, but after this PR you have to look in multiple places, even if there is only one caller that doesn't do any setup and it's
Yes, all of these questions can be answered quite easily by checking in one or two files and doing a grep or two, my point is that one doesn't have to just check the header and do an extra grep or two now. e.g. I don't use That being said, it sounds like other contributors prefer the style of this PR to the style of master, and given that this is a stylistic question the thing that people prefer is definitely the thing that should happen. |
4fe745f to
6a76b40
Compare
|
rereACK 0e3c1a2 I checked each commit manually (inlined the content back and checked the diff). The extractions are clean code moves, with a minimal log cleanup in the first commit and formatting and equivalent control-flow cleanups in the last. |
pablomartin4btc
left a comment
There was a problem hiding this comment.
re-ACK 0e3c1a2
Thanks for taking the suggestion dropping __func__ from debug log (in prepare commit).
Please rebase due to #36752.
vasild
left a comment
There was a problem hiding this comment.
ACK 0e3c1a2 (modulo the conflict with #36752)
Long overdue, thank you!
Show Signature
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
ACK 0e3c1a2de03596cfaf5de25cc052b96ef88728af (modulo the conflict with https://github.com/bitcoin/bitcoin/pull/36752)
Long overdue, thank you!
-----BEGIN PGP SIGNATURE-----
iQRPBAEBCAA5FiEE5k2NRWFNsHVF2czBVN8G9ktVy78FAmrzI6obFIAAAAAABAAO
bWFudTIsMi41KzEuMTIsMiwzAAoJEFTfBvZLVcu/ceQf/37r2DIZSTmzPhgHtvpw
ZmrfCLgPlHYdT+8NbB+TBejOCX2JDqpvB9gAhDhZgt+mLEwQNMvnjijzsLifiVDw
JDpK6Kffm5dSJcmZYe+pmM7901mQngXALoe03nEnjiQkgW0TbA8LdmfJEDFVX8Sz
pVdxGYyQCsn4uh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IRszTeHm4z
dxQZQSX0WmnCkiDYEpznRplIhDcFK6UdvaM/stz1KHJNrrHZHk/8O3CTMF5q2Pvr
GWriLYDZYgkJ0jqWHvPhwqPbqBhjdu6kkfPK5bbQaI5Qijn4a0k2DB897wEXd/mC
j8Y=
=FF1a
-----END PGP SIGNATURE-----
vasild's public key is on openpgp.org
The debug log for ignored old block header requests prefixes its message with __func__. The logging macros already record the calling function, which -logsourcelocations prints, so the prefix adds nothing. It also ties the log text to the name of the enclosing function, so moving the getheaders handling into its own helper would change it.
This commit can be reviewed with the git options: --color-moved=dimmed-zebra --color-moved-ws=ignore-all-space
This commit can be reviewed with the git options: --color-moved=dimmed-zebra --color-moved-ws=ignore-all-space
This commit can be reviewed with the git options: --color-moved=dimmed-zebra --color-moved-ws=ignore-all-space
This commit can be reviewed with the git options: --color-moved=dimmed-zebra --color-moved-ws=ignore-all-space Co-authored-by: Lőrinc <[email protected]>
This commit can be reviewed with the git options: --color-moved=dimmed-zebra --color-moved-ws=ignore-all-space
This commit can be reviewed with the git options: --color-moved=dimmed-zebra --color-moved-ws=ignore-all-space
This commit can be reviewed with the git options: --color-moved=dimmed-zebra --color-moved-ws=ignore-all-space
This commit can be reviewed with the git options: --color-moved=dimmed-zebra --color-moved-ws=ignore-all-space Co-authored-by: pablomartin4btc <[email protected]> Co-authored-by: Lőrinc <[email protected]>
This commit can be reviewed with the git options: --color-moved=dimmed-zebra --color-moved-ws=ignore-all-space Co-authored-by: pablomartin4btc <[email protected]>
Normalize brace placement, pointer and reference spacing, blank lines, and single-statement conditionals in the extracted handlers. Use returns in ProcessSendTxRcncl() and remove the send_getaddr temporary in ProcessVersion(), preserving the existing control flow. Co-authored-by: Lőrinc <[email protected]>
0e3c1a2 to
e7120dc
Compare
|
@l0rinc Thanks for the re-review. Both are fixed in the description: the line count is now ~1500, and the "no behavior change" sentence now mentions the debug log differences. |
|
This 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". |
|
Makes sense, thanks @maflcko. |
vasild
left a comment
There was a problem hiding this comment.
ACK e7120dc
This conflicts with a reviewed pull that is marked for possible backport
Which one?
For tracking: I assume this is 36521?
#36521 is closed and not for backport?
Show Signature
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
ACK e7120dc7002fd91c061df45e58d527fb03dd16e3
> This conflicts with a reviewed pull that is marked for possible backport
Which one?
> For tracking: I assume this is 36521?
https://github.com/bitcoin/bitcoin/pull/36521 is closed and not for backport?
-----BEGIN PGP SIGNATURE-----
iQRPBAEBCAA5FiEE5k2NRWFNsHVF2czBVN8G9ktVy78FAmsEXP4bFIAAAAAABAAO
bWFudTIsMi41KzEuMTIsMiwzAAoJEFTfBvZLVcu/46kf/27Q7MzK/tWsZs9MA//g
2bczSWSBt2lZ96azMH5lVxslrqRL6vSEw3Uf0uFdtqJtp3BC40cyPlhMdu2jIvda
wYyeM3QFs6WkE60OS6c/LmI+IvBAv/91tkDS9OK3hCRE/bduc5hgmuPp9QxaZLPF
HLak+2uZlcaqpGegzq7buO3/o5EevD808ks2Ek1cEJeRV5t8BGP/pnfKytTpfMYG
+7Cq2m7DomiLsJRUtdjxR/iTWvTKMVQ9Qj+gvkg51SuTqIveFHHOiR7mnTWLPjnS
X5fxRybRukKsnDALCJsWqL3AQoeLtjSjpcWhSHbRjSZjrbET7TEQIzac7ds0Bw54
YzHgCd6NELXn+g53x7UGd2kjHca0ftJPEMZG0SXr4V29or4tb4xqvbCfa641CxwV
mDFOfyhQZTD0N1uSlC8VnKoEOJphGpExDhC849QUAif1uMPARwslqquIBOOD6BnN
joFg7hTjxP82e2b1gjSUnJcE152p8qJUXmGTBpGV/XHsn9GuZ71lSFYGXwNou/VA
l4hEUmvkwZOsxIvjftcngBq4skUNpKUDX7oEwo2X+ie1r1aMXDnNZhVqO5rZuJLt
YCymzT3IRGASwptDouXFw67GqS88Y5GymTVi72TxNFnVu17/jGQnXUYHqx+sxcr2
4ziYMzMYcD1Mk4Q4qSHtWRmOzdluIDw+Sh3Qm8OGcuQNTXEc1cdDneGJzB+shMMn
TV23Yd5lf2QbjwQ1hE/BJFClsrGdTpl8j/VXvWUsMTHqKP3HugEbfB/SMipiCxqC
dDZD8xu7S+D7Q1wy2oBxb1fGW25Oi4d4DaunhOmK14NO7jOFvb9utk+CbCS2cYmj
wXwZnkG87tlsEGd6MkLDVTQyJUUc0jEDE0F94OInfdqwr9MopN6bQbilwyZ8LPKn
m7Hm1RAKt+/EQBWwK2tqco/v/lcGOREEpESL+xT1pLurPnyoGRo0wuKFK1Qpk2WR
PI7TTN5dZfEhSH4JgmLJLrn/S2BZMxLURGVcrcQWzBe/ORHE65aenTPS6sHTa3nM
xM8vN4rUNL39bmZuQxcJUOrFpX3PfriKj8pzKP7aHh1W8KHdtppPBTOKlReVCG0n
LA1LKUBvcx4+sX2GJh+iAIFQFCq6DJ5bLNeXsqUSWMFN//E+FZ0cJzKxqAfMDxwl
IDs/GAmTczQpyTIyrVAFDTAEjDVujXHTh4UrgLizH6wvl7Cnv/Tca1R43iRao2iD
FrQSVtTlMKJeKR8dSXOBViGGWgjmv1YbXJ9mc32kP7rko7h3TlSSzQAITN7H9xEQ
j0oWqO2IgVGbHs6lvzoZSkEuibbKJu7IwQe/X2dEHOwzX7CU3nGDw6cSPfbSkqwn
wxw=
=gy8S
-----END PGP SIGNATURE-----
vasild's public key is on openpgp.org
pablomartin4btc
left a comment
There was a problem hiding this comment.
re-ACK e7120dc
Clean rebase: range-diff vs 0e3c1a2 only touches the ProcessSendTxRcncl() extraction, picking up the reordering from #36752 (disconnect after VERACK before the m_txreconciliation check), still move-only.
#36521 is closed and not for backport?
Adding to @vasild's point: #36521 was closed and split up. The part marked for backport now, #36895 (33.0 milestone), doesn't touch net_processing.cpp and no longer conflicts with this PR. The other split-off, #36906, only has a trivial one-line conflict (TX_WITH_WITNESS -> TX_WITH_WITNESS_P2P in the tx handler) and isn't marked for backport.
@vasild, if you have some time, I'd really appreciate your review on #35522 (the same kind of extraction/ refactoring for SendMessages()), which I put in draft for the same reason @maflcko raised here. It doesn't conflict with #36895 or #36906 either, so I'll undraft it once I rebase it.

PeerManagerImpl::ProcessMessage()is a ~1500-line function handling every p2p message type inline, which makes it hard to navigate and review.This PR continues splitting it into per-message helper functions, following the pattern of the recently merged fa5ab02 (
ProcessPong()) and fa55723 (ProcessAddrs()), as suggested by maflcko #34588 (comment).A preparatory commit removes the
__func__prefix from one getheaders debug log, so moving it doesn't change the output.Nine handlers are extracted, one move-only commit each:
ProcessGetAddr()—getaddrProcessGetDataMessage()—getdata(named to avoid colliding with the existingProcessGetData(), which services the request queue this handler fills)ProcessGetBlocks()—getblocksProcessGetHeaders()—getheadersProcessInv()—invProcessSendTxRcncl()—sendtxrcnclProcessTx()—txProcessCompactBlock()—cmpctblockProcessVersion()—versionEach extraction commit is a code move with indentation adjustments: the only new lines are the declaration (with thread-safety annotations), the function signature, and the one-line call site.
Each call site is
Helper(...); return;, soreturnstatements inside the moved bodies keep identical semantics. No behavior change beyond debug log output.One final cleanup commit normalizes the remaining formatting, replaces equivalent
breakstatements withreturninProcessSendTxRcncl(), and simplifies thesend_getaddrconditional inProcessVersion().Each extraction commit can be reviewed with the git options:
--color-moved=dimmed-zebra --color-moved-ws=ignore-all-spaceDeclarations and definitions are placed next to related existing helpers (e.g.
ProcessGetDataMessagenext toProcessGetData,ProcessGetBlocksnext toProcessGetBlockData,ProcessGetAddrafterProcessAddrs).