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

net: attempts to connect to all resolved addresses when connecting to a node #28834

Merged
merged 1 commit into from Apr 25, 2024

Conversation

sr-gi
Copy link
Member

@sr-gi sr-gi commented Nov 9, 2023

This is a follow-up of #28155 motivated by #28155 (comment)

Rationale

Prior to this, when establishing a network connection via CConnman::ConnectNode, if the connection needed address resolution, a single address would be picked at random from the resolved addresses and our node would try to connect to it. However, this would lead to the behavior of ConnectNode being unpredictable when the address was resolved to various ips (e.g. the address resolving to IPv4 and IPv6, but we only support one of them).

This patches the aforementioned behavior by going over all resolved IPs until a valid one is found or until we
exhaust them.

@DrahtBot
Copy link
Contributor

DrahtBot commented Nov 9, 2023

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

Code Coverage

For detailed information about the code coverage, see the test coverage report.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK vasild, mzumsande, achow101
Concept ACK naumenkogs

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #29415 (Broadcast own transactions only via short-lived Tor or I2P connections by vasild)
  • #29231 (logging: Update to new logging API by ajtowns)

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.

@maflcko
Copy link
Member

maflcko commented Nov 13, 2023

CI failed

@sr-gi
Copy link
Member Author

sr-gi commented Nov 15, 2023

There was an issue with the interaction of the change and using a proxy. It should be fixed now

@sr-gi sr-gi force-pushed the addnode-tryall branch 2 times, most recently from 7029960 to 8efc4c3 Compare November 15, 2023 18:03
Copy link
Contributor

@mzumsande mzumsande left a comment

Choose a reason for hiding this comment

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

Concept ACK, will review soon.

src/net.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@mzumsande mzumsande left a comment

Choose a reason for hiding this comment

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

Would be good to adjust the title / commit message to be more general:
The solution doesn't specifically address addnode but changes OpenNetworkConnection / ConnectNode and therefore all callers that use it with pszDest set (-connect, -seednode, test-only -addconnection) are affected by the change.

@sr-gi sr-gi changed the title net: Attempts to connect to all resolved addresses on addnode net: attempts to connect to all resolved addresses when connecting to a node Dec 20, 2023
@sr-gi
Copy link
Member Author

sr-gi commented Dec 20, 2023

Would be good to adjust the title / commit message to be more general: The solution doesn't specifically address addnode but changes OpenNetworkConnection / ConnectNode and therefore all callers that use it with pszDest set (-connect, -seednode, test-only -addconnection) are affected by the change.

Updated both commit message/title and PR title/desciption

@sr-gi
Copy link
Member Author

sr-gi commented Jan 29, 2024

Rebased to fix CI

@naumenkogs
Copy link
Member

Concept ACK

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.

Approach ACK 494c732, just a naming nit below.

src/net.cpp Outdated Show resolved Hide resolved
src/net.cpp Outdated Show resolved Hide resolved
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 ba02108

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 a75975e

@sr-gi sr-gi force-pushed the addnode-tryall branch 2 times, most recently from 518019b to 216efd6 Compare March 15, 2024 21:03
@DrahtBot
Copy link
Contributor

🚧 At least one of the CI tasks failed. Make sure to run all tests locally, according to the
documentation.

Possibly this is due to a silent merge conflict (the changes in this pull request being
incompatible with the current code in the target branch). If so, make sure to rebase on the latest
commit of the target branch.

Leave a comment here, if you need help tracking down a confusing failure.

Debug: https://github.com/bitcoin/bitcoin/runs/22724110270

@sr-gi
Copy link
Member Author

sr-gi commented Mar 15, 2024

Rebased to address merge conflicts

@sr-gi
Copy link
Member Author

sr-gi commented Mar 21, 2024

@vasild @mzumsande @naumenkogs would you mind re-checking this? It feels like it's been ready for a while but it keeps being 1 ack short

Copy link
Contributor

@mzumsande mzumsande left a comment

Choose a reason for hiding this comment

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

Looks like something went wrong with the rebase, there are two commits with rust code that don't seem related.

@sr-gi
Copy link
Member Author

sr-gi commented Mar 22, 2024

Looks like something went wrong with the rebase, there are two commits with rust code that don't seem related.

Not really sure what happened here 🤔 but should be fixed now

Copy link
Contributor

@mzumsande mzumsande left a comment

Choose a reason for hiding this comment

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

re-ACK ae7afa5

@DrahtBot DrahtBot requested a review from vasild March 26, 2024 16:49
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 ae7afa5

src/net.cpp Outdated Show resolved Hide resolved
… a node

Prior to this, when establishing a network connection via CConnman::ConnectNode,
if the connection needed address resolution, a single address would be picked
at random from the resolved addresses and our node will try to connect to it. However,
this would lead to the behavior of ConnectNode being unpredictable when the address
was resolved to various ips (e.g. the address resolving to IPv4 and IPv6, but we only
support one of them).

This patches the aforementioned behavior by going over all resolved IPs until we find one
we can connect to or until we exhaust them.
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 fd81a37

@mzumsande
Copy link
Contributor

re-ACK fd81a37 (just looked at diff, only small logging change)

@achow101
Copy link
Member

ACK fd81a37

@achow101 achow101 merged commit 2eff198 into bitcoin:master Apr 25, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants