Skip to content
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

refactor: Pass Peer& to Misbehaving() #25144

Merged
merged 1 commit into from
Jun 27, 2022

Conversation

maflcko
Copy link
Member

@maflcko maflcko commented May 16, 2022

Misbehaving has several coding related issues (ignoring the conceptual issues here for now):

  • It is public, but it is not supposed to be called from outside of net_processing. Fix that by making it private and creating a public UnitTestMisbehaving method for unit testing only.
  • It doesn't do anything if a nullptr is passed. It would be less confusing to just skip the call instead. Fix that by passing Peer& to Misbehaving().
  • It calls GetPeerRef, causing !m_peer_mutex lock annotations to be propagated. This is harmless, but verbose. Fix it by removing the no longer needed call to GetPeerRef and the no longer needed lock annotations.

switch (state.GetResult()) {
case TxValidationResult::TX_RESULT_UNSET:
break;
// The node is providing invalid data:
case TxValidationResult::TX_CONSENSUS:
Misbehaving(nodeid, 100, message);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the MaybePunish* calls could accept a Peer& (and CNodeState&) as well, and also not be called when the peer is already disconnected?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but only because the message happens to be empty() in cases where the peer might be nullptr/disconnected. I wasn't sure if we want to enforce this correlation.

@DrahtBot
Copy link
Contributor

DrahtBot commented May 16, 2022

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #25454 (p2p, refactor: Avoid multiple getheaders messages in flight to the same peer by sdaftuar)
  • #25321 (p2p: Stop treating message size as misbehavior by MarcoFalke)
  • #24571 (p2p: Prevent block index fingerprinting by sending additional getheaders messages by dergoegge)

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
Contributor

@vasild vasild left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK fa825d1

The commit message is rather scarce. It is better if it contains all the info from the PR description. The latter is not part of the immutable git history and may be harder to access, especially if we move away from github at some point.

src/net_processing.cpp Outdated Show resolved Hide resolved
`Misbehaving` has several coding related issues (ignoring the conceptual
issues here for now):
* It is public, but it is not supposed to be called from outside of
  net_processing. Fix that by making it private and creating a public
  `UnitTestMisbehaving` method for unit testing only.
* It doesn't do anything if a `nullptr` is passed. It would be less
  confusing to just skip the call instead. Fix that by passing `Peer&`
  to `Misbehaving()`.
* It calls `GetPeerRef`, causing `!m_peer_mutex` lock annotations to be
  propagated. This is harmless, but verbose. Fix it by removing the no
  longer needed call to `GetPeerRef` and the no longer needed lock
  annotations.
Copy link
Contributor

@vasild vasild left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK fa8aa0a

@laanwj
Copy link
Member

laanwj commented Jun 21, 2022

LGTM, otherwise, but did only cursory code review.

Copy link
Contributor

@w0xlt w0xlt 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 fa8aa0a

@maflcko maflcko merged commit 50a3921 into bitcoin:master Jun 27, 2022
@maflcko maflcko deleted the 2205-mis-peer-🛥 branch June 27, 2022 10:28
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jun 27, 2022
@bitcoin bitcoin locked and limited conversation to collaborators Jun 27, 2023
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.

8 participants