Skip to content

Conversation

jnewbery
Copy link
Contributor

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.

@fanquake fanquake added the P2P label Aug 12, 2020
@jnewbery
Copy link
Contributor Author

jnewbery commented Aug 12, 2020

This was requested by @MarcoFalke @sdaftuar and @theuni in #19607 (#19607 (comment)).

Changing CConnman* connman to CConnman& m_connman is the continuation of work in #19174. See #19542 (comment) and #19174 (comment) for further discussion. Prior to this PR, connman was a pointer in PeerLogicValidation, but a reference everywhere else in net_processing. Changing it to a reference in PeerLogicValidation is required before moving the rest of the functions into PeerLogicValidation.

EDIT: I've started by moving ProcessMessage() into PLV because in order to move the new Peer struct into PLV, Misbehaving() needs to be a member function of PLV, which means everything above it in this call tree https://doxygen.bitcoincore.org/net__processing_8cpp.html#ad2983e754c4d90bd68adf91b208664f5 needs to be a member (or hold a reference to peer_logic, which I don't think makes sense)

@Crypt-iQ
Copy link
Contributor

Fuzzers fail because ProcessMessage is used in the harnesses.

@theStack
Copy link
Contributor

Concept ACK -- this is definitely a more appropriate location for ProcessMessage than the whole net_processing module scope.

@jnewbery jnewbery force-pushed the 2020-07-process-message-plv branch from 745346a to af783a5 Compare August 12, 2020 13:19
@jnewbery
Copy link
Contributor Author

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.
@jnewbery
Copy link
Contributor Author

rebased

@jnewbery jnewbery force-pushed the 2020-07-process-message-plv branch from af783a5 to cbcb80a Compare August 12, 2020 13:31
@jonatack
Copy link
Member

Light approach ACK, if there is a follow-up code branch to see where this is heading I'd look at it.

@JeremyRubin
Copy link
Contributor

JeremyRubin commented Aug 13, 2020

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.

@jnewbery
Copy link
Contributor Author

@promag
Copy link
Contributor

promag commented Aug 14, 2020

Code review ACK cbcb80a.

Am I missing something or this should have refactoring label?

First 2 commits could be merged on its own.

@DrahtBot
Copy link
Contributor

DrahtBot commented Aug 20, 2020

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

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.

Copy link
Member

@maflcko maflcko left a 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 -

@jnewbery jnewbery force-pushed the 2020-07-process-message-plv branch from cbcb80a to 4d6c4d2 Compare August 21, 2020 10:05
@jnewbery
Copy link
Contributor Author

jnewbery commented Aug 21, 2020

Great suggestions @MarcoFalke . I've taken them all.

@jonatack
Copy link
Member

travis and cirrus:

MemorySanitizer: use-of-uninitialized-value 
src/net_processing.cpp:656:82 in (anonymous namespace)::TipMayBeStale(Consensus::Params const&)

https://travis-ci.org/github/bitcoin/bitcoin/jobs/719886303

https://github.com/bitcoin/bitcoin/pull/19704/checks?check_run_id=1011864356

Copy link
Member

@jonatack jonatack left a 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.

@jnewbery jnewbery force-pushed the 2020-07-process-message-plv branch from 4d6c4d2 to daed542 Compare August 21, 2020 12:11
@jnewbery
Copy link
Contributor Author

travis and cirrus:

MemorySanitizer: use-of-uninitialized-value
src/net_processing.cpp:656:82 in (anonymous namespace)::TipMayBeStale(Consensus::Params const&)

It looks like that happens because SelectParams() is called twice in the TestChain100Setup constructor, including after
the PeerLogicValidation object is constructed (see 666696b).

Rather than fight against the unit test framework, I've removed that commit. It's not essential for this PR.

Copy link
Contributor

@theStack theStack left a 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).

@maflcko
Copy link
Member

maflcko commented Aug 24, 2020

re-ACK daed542, only change is removing second commit 🎴

Show signature and timestamp

Signature:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

re-ACK daed542a12, only change is removing second commit 🎴
-----BEGIN PGP SIGNATURE-----

iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUi57gv/VAtt+n9kwA+RHgQQQsRU5ybObKW5pKc8cpR0kcgd6rwgJPvCdnYUZyIG
eDpCMi4O4oHW7usvpn9koFWtHr8S3NPGqXbmF2PiIDb0aK8qkaUafqLWNgb/vI5T
xcTs1XpOF1SW3IB6LnrVtwjk9j9iCeQ67Uu1JdEa9o6e8d84CnMbYBiealLA4f5V
UunvG+QZ/vCXzPks4+Q2u9k9FBGj68ED723xJILw743+JLa3Czu4JXT+SPLsC33D
9THMkP38eaWpothKivyE8aNWzG9vSidi3R12apLHCisg54MuWRWNYygD3t5QEvpb
Ca8ZBXZy665M7TOkfrfayNtgWi39zNI7TJabFgH7OAa/InPlGKGtdMepgd1a3+EF
ZPhItdhgzwy221a80W2NtEyzxXnA3cWY0JBumvWA0P1HY6PIkAAe24rY5Zu25dyk
Nj3dBfg9LV/6cSSEJqIdZyWJ0/dPSeMDzejzFWwRGgF/gX4bpyYAhotHXcf1CcBY
CYtzu5vy
=l6KP
-----END PGP SIGNATURE-----

Timestamp of file with hash 08eeaa12e1f73cc25bec71f7f0ba83ae3ad3bc6225f47932f8a0d313daf8ffd8 -

Copy link
Member

@jonatack jonatack left a 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

@promag
Copy link
Contributor

promag commented Aug 24, 2020

Code review ACK daed542.

@fanquake fanquake merged commit 4fefd80 into bitcoin:master Aug 24, 2020
@jnewbery jnewbery deleted the 2020-07-process-message-plv branch August 24, 2020 14:04
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Aug 24, 2020
…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
fanquake added a commit that referenced this pull request Aug 26, 2020
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
fanquake added a commit that referenced this pull request Aug 26, 2020
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
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Aug 26, 2020
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
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Aug 26, 2020
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
maflcko pushed a commit to bitcoin-core/gui that referenced this pull request Sep 7, 2020
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
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Jan 6, 2021
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
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Jan 6, 2021
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
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants