Skip to content

Conversation

@jnewbery
Copy link
Contributor

@jnewbery jnewbery commented Nov 3, 2020

Currently, the logic around whether we called CAddrMan::Connected() for
a peer is spread between verack processing (where we discard inbound
peers) and FinalizeNode (where we discard misbehaving and
block-relay-only peers). Consolidate that logic to a single place.

Also remove the CNode.fCurrentlyConnected bool, which is now
redundant. We can rely on CNode.fSuccessfullyConnected, since the two
bools were only ever flipped to true in the same place.

Currently, the logic around whether we called CAddrMan::Connected() for
a peer is spread between verack processing (where we discard inbound
peers) and FinalizeNode (where we discard misbehaving and
block-relay-only peers). Consolidate that logic to a single place.

Also remove the CNode.fCurrentlyConnected bool, which is now
redundant. We can rely on CNode.fSuccessfullyConnected, since the two
bools were only ever flipped to true in the same place.
@fanquake fanquake added the P2P label Nov 3, 2020
@jnewbery
Copy link
Contributor Author

jnewbery commented Nov 3, 2020

I originally suggested this as a follow up to #20187: #20187 (comment)

cc @mzumsande @amitiuttarwar @sdaftuar

@DrahtBot
Copy link
Contributor

DrahtBot commented Nov 3, 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.

@mzumsande
Copy link
Contributor

Concept ACK.

How about adding a commit to rename CAddrMan::Connected (which is only ever called during disconnection) and correct the documentation, as suggested in #20187 (comment) and #20187 (review) ?

@jnewbery
Copy link
Contributor Author

jnewbery commented Nov 4, 2020

How about adding a commit to rename CAddrMan::Connected (which is only ever called during disconnection) and correct the documentation

I haven't changed the name, but I've updated the documentation, so at least it should be obvious to readers what the function is doing. I think we need to reconsider our whole approach to nTime/nLastSuccess, and potentially remove nTime for addr messages altogether (see https://github.com/bitcoin-core/bitcoin-devwiki/wiki/P2P-IRC-meetings#20-oct-2020). For now, I think updating the function comment is enough.

@practicalswift
Copy link
Contributor

Concept ACK

Copy link
Contributor

@amitiuttarwar amitiuttarwar 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 0bfce9d. nice tidy, and bonus that we get to remove an unnecessary call to cs_main

one slightly tangential question- when looking for other touch points of nTime, I came across this comment:

bitcoin/src/addrman.h

Lines 206 to 208 in c772f4c

// find an entry, creating it if necessary.
// nTime and nServices of found node is updated, if necessary.
CAddrInfo* Create(const CAddress &addr, const CNetAddr &addrSource, int *pnId = NULL);

but from reading the function definition, I don't understand how. can it really update the existing nTime of a CAddress? looks like both the header comment and function were added in 5fee401, so seems likely I'm misunderstanding the code.

@jnewbery
Copy link
Contributor Author

jnewbery commented Nov 6, 2020

one slightly tangential question- when looking for other touch points of nTime, I came across this comment:

// find an entry, creating it if necessary.
// nTime and nServices of found node is updated, if necessary.
CAddrInfo* Create(const CAddress &addr, const CNetAddr &addrSource, int *pnId = NULL);

but from reading the function definition, I don't understand how. can it really update the existing nTime of a CAddress? looks like both the header comment and function were added in 5fee401, so seems likely I'm misunderstanding the code.

No, you're not misunderstanding. That comment is just plain wrong. It doesn't find the entry, it always creates it. And it doesn't update the nTime and nServices. I think it's probably vestigial from when the code was being written. Perhaps logic was moved around (what it's describing is closer to what the Add_() function does), but it's inaccurate now.

Copy link
Contributor

@mjdietzx mjdietzx left a comment

Choose a reason for hiding this comment

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

ack 0bfce9d

@mzumsande
Copy link
Contributor

Code review ACK 0bfce9d

@fanquake fanquake requested a review from sdaftuar November 11, 2020 09:43
@maflcko maflcko merged commit 884bde5 into bitcoin:master Nov 19, 2020
@jnewbery jnewbery deleted the 2020-11-consolidate-addrman-connect branch November 19, 2020 15:37
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Nov 19, 2020
…:Connected()

0bfce9d [addrman] Fix Connected() comment (John Newbery)
eefe194 [net] Consolidate logic around calling CAddrMan::Connected() (John Newbery)

Pull request description:

  Currently, the logic around whether we called CAddrMan::Connected() for
  a peer is spread between verack processing (where we discard inbound
  peers) and FinalizeNode (where we discard misbehaving and
  block-relay-only peers). Consolidate that logic to a single place.

  Also remove the CNode.fCurrentlyConnected bool, which is now
  redundant. We can rely on CNode.fSuccessfullyConnected, since the two
  bools were only ever flipped to true in the same place.

ACKs for top commit:
  mzumsande:
    Code review ACK 0bfce9d
  amitiuttarwar:
    code review ACK 0bfce9d. nice tidy, and bonus that we get to remove an unnecessary call to `cs_main`

Tree-SHA512: 1ab74dae3bc12a6846da57c853033e546bb4f91caa39f4c50bf0cf7eca59cb917bdb2ef795da55363e7e9f70949cb28bb3be004cb3afa4389f970d2fe097d932
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Dec 21, 2021
Summary:
Currently, the logic around whether we called `CAddrMan::Connected()` for
a peer is spread between verack processing (where we discard inbound
peers) and `FinalizeNode` (where we discard misbehaving and
block-relay-only peers). Consolidate that logic to a single place.

Also remove the `CNode.fCurrentlyConnected` bool, which is now
redundant. We can rely on `CNode.fSuccessfullyConnected`, since the two
bools were only ever flipped to true in the same place.

This is a backport of [[bitcoin/bitcoin#20291 | core#20291]] [1/2]
bitcoin/bitcoin@eefe194

Depends on D10697

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D10698
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Dec 21, 2021
Summary:
This is a backport of [[bitcoin/bitcoin#20291 | core#20291]] [2/2]
bitcoin/bitcoin@0bfce9d

Depends on D10698

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Subscribers: Fabien

Differential Revision: https://reviews.bitcoinabc.org/D10699
@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