-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Net processing: move ProcessMessage() to PeerLogicValidation #19704
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Net processing: move ProcessMessage() to PeerLogicValidation #19704
Conversation
This was requested by @MarcoFalke @sdaftuar and @theuni in #19607 (#19607 (comment)). Changing EDIT: I've started by moving |
Fuzzers fail because |
Concept ACK -- this is definitely a more appropriate location for |
745346a
to
af783a5
Compare
I've fixed the fuzz build (I think). Let's see what Travis thinks. |
Hold a reference to connman rather than a pointer because: - PeerLogicValidation can't run without a connman - The pointer never gets reseated The alternative is to always assert that the pointer is non-null before dereferencing. Change the name from connman to m_connman at the same time to conform with current style guidelines.
rebased |
af783a5
to
cbcb80a
Compare
Light approach ACK, if there is a follow-up code branch to see where this is heading I'd look at it. |
Concept Ack and lite-cr ack (doesn't seem to change any logic, just refactor). In terms of approach might be nice to encapsulate processmessage as a subclass that only has access to the relevant references out of the PeerLogicValidation state, but I don't think that's required (just thinking ahead that we might want all the individual message handlers in their own class). edit: another reason for this is you can appropriately bind things in the interior class as const where relevant. |
Lots of discussion on this at http://www.erisian.com.au/meetbot/bitcoin-core-dev/2020/bitcoin-core-dev.2020-08-13-19.00.log.html#l-104 |
Code review ACK cbcb80a. Am I missing something or this should have refactoring label? First 2 commits could be merged on its own. |
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cr ACK cbcb80a 🎤
Show signature and timestamp
Signature:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
cr ACK cbcb80abc8b3bddaba81e8ba2b22c7d957f02f37 🎤
-----BEGIN PGP SIGNATURE-----
iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUgG4wwAjDXVdxnfaSOSedVWUkK0Xn7dJWYM57677OgNjxyljDUvsMvySG6Gg60O
ffe/wB6mwYqXkW2+O+B+Tw2VQbC0AnaXlw9vNnuBDv3S8QDU3f1HE/a+48DWYqPc
ipnSEOMZuDsWi31mQrtOOBHxD5hDulhF0Wx6I8SJ+iMhEk20Nd2T1ZQKZR6yJ2oS
zOUeRjr/7n3/aeXdCJZ/AiTkVLCZskNSn9fbTSpFsEdefw/kVFzfm4YViCfRvLsn
sb7Cs2Us07P64erk5JsJIzIh+C8QjWgWo57UW/sOb9zF05q7fCgpXjzf2iWxMlBe
jctdKBoo9Y6SVKY5+Lc3XX+Y36/ae6tKtO5KobjNCDACwLLRnITaJJzltKLs+dTU
AriR/ssfIsamz8cbhiMeJiDggdlNugaenPaW9U/EIDx6seOhkR10FkMl4aHJhTUx
VBoBzUnGnCf0nW0WVKd9uujdC8qG33ub5Ppq1s21i1NC47I8uv6hS4XZ8tUxCPlD
80mbsjhw
=WycG
-----END PGP SIGNATURE-----
Timestamp of file with hash c58fbfd8242739033e1f88dae62117af90263272c9149109ad99aba5f1597e88 -
cbcb80a
to
4d6c4d2
Compare
Great suggestions @MarcoFalke . I've taken them all. |
travis and cirrus:
https://travis-ci.org/github/bitcoin/bitcoin/jobs/719886303 https://github.com/bitcoin/bitcoin/pull/19704/checks?check_run_id=1011864356 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re-reviewing, I like these changes. One question below, in addition to the msan use-of-uninitialized-value issue.
4d6c4d2
to
daed542
Compare
It looks like that happens because Rather than fight against the unit test framework, I've removed that commit. It's not essential for this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review ACK daed542
It's nice to see that the interface of ProcessMessage() shrinks down from 10 to 6 parameters (or 7, if you also count the implicit this pointer).
re-ACK daed542, only change is removing second commit 🎴 Show signature and timestampSignature:
Timestamp of file with hash |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK daed542 code review and debug tested
Code review ACK daed542. |
…icValidation daed542 [net_processing] Move ProcessMessage to PeerLogicValidation (John Newbery) c556770 [net_processing] Change PeerLogicValidation to hold a connman reference (John Newbery) Pull request description: Rather than ProcessMessage() being a static function in net_processing.cpp, make it a private member function of PeerLogicValidation. This is the start of moving static functions and global variables into PeerLogicValidation to make it better encapsulated. ACKs for top commit: jonatack: ACK daed542 code review and debug tested promag: Code review ACK daed542. MarcoFalke: re-ACK daed542, only change is removing second commit 🎴 theStack: Code Review ACK daed542 Tree-SHA512: ddebf410d114d9ad5a9e536950018ff333a347c035d74fcc101fb4a3f20a281782c7eac2b7d1bd1c8f6bc7e59f5b5630fb52c2e1b4c32df454fa584673bd021e
fad84b7 test: Activate segwit in TestChain100Setup (MarcoFalke) fa11ff2 test: Pass empty tx pool to block assembler (MarcoFalke) fa96574 test: Move doxygen comment to header (MarcoFalke) Pull request description: This fixes not only a TODO in the code, but also prevents a never ending source of uninitialized reads. E.g. * #18376 * #19704 (comment) * ... ACKs for top commit: jnewbery: utACK fad84b7 Tree-SHA512: 64cf16a59656d49e022b603f3b06441ceae35a33a4253b4382bc8a89a56e08ad5412c8fa734d0fc7b58586f40ea6d57b348a3b4838bc6890a41ae2ec3902e378
fa9d590 scripted-diff: gArgs -> args (MarcoFalke) fa33bc2 init: Capture copy of blocknotify setting for BlockNotifyCallback (MarcoFalke) fa40017 init: Pass reference to ArgsManager around instead of relying on global (MarcoFalke) Pull request description: The gArgs global has several issues: * gArgs is used by each process (bitcoind, bitcoin-qt, bitcoin-wallet, bitcoin-cli, bitcoin-tx, ...), but it is hard to determine which arguments are actually used by each process. For example arguments that have never been registered, but are still used, will always return the fallback value. * Tests may run several sub-tests, which need different settings. So globals will have to be overwritten, but that is fragile on its own: e.g. #19704 (comment) or #19511 The goal is to remove gArgs, but as a first step in that direction this pull will change gArgs in init to use a passed-in reference instead. ACKs for top commit: ryanofsky: Code review ACK fa9d590. Looks good. Nice day to remove some globals, and add some lambdas 👍 fanquake: ACK fa9d590 - I'm not as familiar with the settings & argument handling code, but this make sense, and is a step in the right direction towards a reduction in the usage of globals. Not a huge fan of the clang-formatting in the scripted diff. jonasschnelli: Concept ACK fa9d590 Tree-SHA512: ed00db5f826566c7e3b4d0b3d2ee0fc1a49a6e748e04e5c93bdd694ac7da5598749e73937047d5fce86150d764a067d2ca344ba4ae3eb2704cc5c4fa0d20940f
fad84b7 test: Activate segwit in TestChain100Setup (MarcoFalke) fa11ff2 test: Pass empty tx pool to block assembler (MarcoFalke) fa96574 test: Move doxygen comment to header (MarcoFalke) Pull request description: This fixes not only a TODO in the code, but also prevents a never ending source of uninitialized reads. E.g. * bitcoin#18376 * bitcoin#19704 (comment) * ... ACKs for top commit: jnewbery: utACK fad84b7 Tree-SHA512: 64cf16a59656d49e022b603f3b06441ceae35a33a4253b4382bc8a89a56e08ad5412c8fa734d0fc7b58586f40ea6d57b348a3b4838bc6890a41ae2ec3902e378
fa9d590 scripted-diff: gArgs -> args (MarcoFalke) fa33bc2 init: Capture copy of blocknotify setting for BlockNotifyCallback (MarcoFalke) fa40017 init: Pass reference to ArgsManager around instead of relying on global (MarcoFalke) Pull request description: The gArgs global has several issues: * gArgs is used by each process (bitcoind, bitcoin-qt, bitcoin-wallet, bitcoin-cli, bitcoin-tx, ...), but it is hard to determine which arguments are actually used by each process. For example arguments that have never been registered, but are still used, will always return the fallback value. * Tests may run several sub-tests, which need different settings. So globals will have to be overwritten, but that is fragile on its own: e.g. bitcoin#19704 (comment) or bitcoin#19511 The goal is to remove gArgs, but as a first step in that direction this pull will change gArgs in init to use a passed-in reference instead. ACKs for top commit: ryanofsky: Code review ACK fa9d590. Looks good. Nice day to remove some globals, and add some lambdas 👍 fanquake: ACK fa9d590 - I'm not as familiar with the settings & argument handling code, but this make sense, and is a step in the right direction towards a reduction in the usage of globals. Not a huge fan of the clang-formatting in the scripted diff. jonasschnelli: Concept ACK fa9d590 Tree-SHA512: ed00db5f826566c7e3b4d0b3d2ee0fc1a49a6e748e04e5c93bdd694ac7da5598749e73937047d5fce86150d764a067d2ca344ba4ae3eb2704cc5c4fa0d20940f
bb6a32c [net processing] Move Misbehaving() to PeerManager (John Newbery) aa114b1 [net_processing] Move SendBlockTransactions into PeerManager (John Newbery) 3115e00 [net processing] Move MaybePunishPeerForTx to PeerManager (John Newbery) e662e2d [net processing] Move ProcessOrphanTx to PeerManager (John Newbery) b70cd89 [net processing] Move MaybePunishNodeForBlock into PeerManager (John Newbery) d777835 [net processing] Move ProcessHeadersMessage to PeerManager (John Newbery) 64f6162 [whitespace] tidy up indentation after scripted diff (John Newbery) 58bd369 scripted-diff: [net processing] Rename PeerLogicValidation to PeerManager (John Newbery) 2297b26 [net_processing] Pass chainparams to PeerLogicValidation constructor (John Newbery) 824bbd1 [move only] Collect all private members of PeerLogicValidation together (John Newbery) Pull request description: Continues the work of moving net_processing logic into PeerLogicValidation. See bitcoin/bitcoin#19704 and bitcoin/bitcoin#19607 (comment) for motivation. This PR also renames `PeerLogicValidation` to `PeerManager` as suggested in bitcoin/bitcoin#10756 (review). ACKs for top commit: MarcoFalke: re-ACK bb6a32c only change is rebase due to conflict in struct NodeContext and variable rename 🤸 hebasto: re-ACK bb6a32c, only rebased, and added renaming `s/peer_logic/peerman/` into scripted-diff since my [previous](bitcoin/bitcoin#19791 (review)) review (verified with `git range-diff`). Tree-SHA512: a2de4a521688fd25125b401e5575402c52b328a0fa27b3010567008d4f596b960aabbd02b2d81f42658f88f4365443fadb1008150a62fbcea123fb42d85a2c21
Summary: ```` Hold a reference to connman rather than a pointer because: - PeerLogicValidation can't run without a connman - The pointer never gets reseated The alternative is to always assert that the pointer is non-null before dereferencing. Change the name from connman to m_connman at the same time to conform with current style guidelines. ``` Partial backport (1/2) of core [[bitcoin/bitcoin#19704 | PR19704]]: bitcoin/bitcoin@c556770 Depends on D8777. Test Plan: ninja all check-all Reviewers: #bitcoin_abc, PiRK Reviewed By: #bitcoin_abc, PiRK Differential Revision: https://reviews.bitcoinabc.org/D8781
Summary: Completes backport (2/2) of core [[bitcoin/bitcoin#19704 | PR19704]]. Depends on D8781. Test Plan: ninja all check-all ninja bitcoin-fuzzers Reviewers: #bitcoin_abc, PiRK Reviewed By: #bitcoin_abc, PiRK Differential Revision: https://reviews.bitcoinabc.org/D8782
Rather than ProcessMessage() being a static function in net_processing.cpp, make it a private member function of PeerLogicValidation. This is the start of moving static functions and global variables into PeerLogicValidation to make it better encapsulated.