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: Favor peers from addrman over fetching seednodes #29605

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

sr-gi
Copy link
Member

@sr-gi sr-gi commented Mar 8, 2024

This is a follow-up of #28016 motivated by #28016 (review) and #28016 (comment).

The current behavior of seednode fetching is pretty eager: we do it as the first step under ThreadOpenNetworkConnections even if some peers may be queryable from our addrman. This poses two potential issues:

  • First, if permanently set (e.g. running with seednode in a config file) we'd be signaling such seed every time we restart our node
  • Second, we will be giving the seed node way too much influence over our addrman, populating the latter with data from the former even when unnecessary

This changes the behavior to only add seednodes to m_addr_fetch if our addrman is empty, or little by little after we've spent some time trying addresses from our addrman. Also, seednodes are added to m_addr_fetch in random order, to avoid signaling the same node in case more than one seed is added and we happen to try them over multiple restarts

@DrahtBot
Copy link
Contributor

DrahtBot commented Mar 8, 2024

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 cbergqvist

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)
  • #26114 (net: Make AddrFetch connections to fixed seeds by mzumsande)

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.

@sr-gi sr-gi changed the title 2024 04 07 seednode addrman net: give seednode priority over dnsseed if both are provided Mar 8, 2024
@DrahtBot DrahtBot added the P2P label Mar 8, 2024
@sr-gi sr-gi changed the title net: give seednode priority over dnsseed if both are provided net: Favor peers from addrman over fetching seednodes Mar 8, 2024
@DrahtBot DrahtBot changed the title net: Favor peers from addrman over fetching seednodes net: Favor peers from addrman over fetching seednodes Mar 8, 2024
@sr-gi sr-gi force-pushed the 2024-04-07-seednode-addrman branch from 4755a28 to 403a919 Compare March 8, 2024 21:43
@sr-gi
Copy link
Member Author

sr-gi commented Mar 8, 2024

This is currently dependent on #28016, given it redefines a local constexpr into a global one, but it could be reworked to add that functionality here if the previous PR doesn't get merged

@DrahtBot
Copy link
Contributor

DrahtBot commented Mar 8, 2024

🚧 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/22454758070

@sr-gi sr-gi force-pushed the 2024-04-07-seednode-addrman branch 2 times, most recently from 8e72300 to e45522c Compare March 8, 2024 22:09
@DrahtBot DrahtBot removed the CI failed label Mar 8, 2024
@sr-gi sr-gi force-pushed the 2024-04-07-seednode-addrman branch from e45522c to 8914d52 Compare March 11, 2024 14:40
@sr-gi
Copy link
Member Author

sr-gi commented Mar 11, 2024

Addressed @brunoerg comment, plus slightly reworked the approach to make sure seednodes are not queried if we reach an acceptable number of peers.

Before this, we would have queried them after the timer went off anyway

@sr-gi
Copy link
Member Author

sr-gi commented Mar 15, 2024

Rebased to fix CI due to #29610

Copy link
Contributor

@cbergqvist cbergqvist 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 f809817.

Glad you agreed something like this was worth doing!

src/net.h Outdated Show resolved Hide resolved
src/net.cpp Show resolved Hide resolved
@sr-gi
Copy link
Member Author

sr-gi commented Apr 22, 2024

Rebased to fix merge conflicts

@sr-gi
Copy link
Member Author

sr-gi commented Apr 25, 2024

Moving this to draft given it is dependant on #28016

@sr-gi sr-gi marked this pull request as draft April 25, 2024 20:13
@sr-gi sr-gi force-pushed the 2024-04-07-seednode-addrman branch from 27781fe to fa9a0de Compare May 1, 2024 02:39
@sr-gi sr-gi marked this pull request as ready for review May 1, 2024 03:30
@sr-gi
Copy link
Member Author

sr-gi commented May 1, 2024

Moving out from drat given #28016 was recently merged.

This comment is still outstanding, and I'd love some feedback on it: #29605 (comment)

@sr-gi sr-gi force-pushed the 2024-04-07-seednode-addrman branch from fa9a0de to 4342d73 Compare May 1, 2024 03:37
@DrahtBot
Copy link
Contributor

DrahtBot commented May 1, 2024

🚧 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/24455108062

src/net.cpp Outdated Show resolved Hide resolved
@sr-gi sr-gi force-pushed the 2024-04-07-seednode-addrman branch from 4342d73 to 33ddd1b Compare May 1, 2024 12:28
@DrahtBot DrahtBot removed the CI failed label May 1, 2024
Copy link
Contributor

@cbergqvist cbergqvist left a comment

Choose a reason for hiding this comment

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

Re-tested 33ddd1b. Bumping of timeout seems blocking.

src/net.cpp Outdated Show resolved Hide resolved
src/net.h Outdated Show resolved Hide resolved
test/functional/p2p_seednode.py Outdated Show resolved Hide resolved
The current behavior of seednode fetching is pretty eager: we do it as the first
step under `ThreadOpenNetworkConnections` even if some peers may be queryable
from our addrman. This poses two potential issues:

- First, if permanently set (e.g. running with seednode in a config file) we'd
be signaling such seed every time we restart our node
- Second, we will be giving the seed node way too much influence over our addrman,
populating the latter even with data from the former even when unnecessary

This changes the behavior to only add seednodes to `m_addr_fetch` if our addrman
is empty, or little by little after we've spent some time trying addresses from
our addrman. Also, seednodes are added to `m_addr_fetch` in random order, to avoid
signaling the same node in case more than one seed is added and we happen to try
them over multiple restarts
@sr-gi sr-gi force-pushed the 2024-04-07-seednode-addrman branch 2 times, most recently from ecded92 to 138a2e2 Compare May 8, 2024 15:55
@sr-gi sr-gi force-pushed the 2024-04-07-seednode-addrman branch from 138a2e2 to 1ed818a Compare May 8, 2024 20:32
@sr-gi sr-gi force-pushed the 2024-04-07-seednode-addrman branch from 1ed818a to f3c4c4b Compare May 10, 2024 14:19
Copy link
Contributor

@cbergqvist cbergqvist 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 f3c4c4b

Ran test/functional/p2p_seednode.py 15 times to confirm robustness against timeouts.
Also ran functional tests with -extended --exclude=feature_dbcrash with no failures.

Still urge you to do something like f9bfc58 from #29605 (comment) (still cherry-picks cleanly). Narrowing state carried around to when it is actually used is cleaner and more respectful to others reading through CConnman, so they don't have to figure out where that extra m_seed_nodes-member is accessed (+ to RAM that no longer needs to make room for unused state). Maybe it looks a bit more messy around your current change, but it reduces cognitive load/complexity for the rest of the code by reducing "live state". It's a bit like leaving a local variable mutable instead of const at the top of a long function even though it is never changed after initialization.

cbergqvist and others added 2 commits May 13, 2024 10:08
Avoids bloating CConnman with state that is only used during startup.
Adds functional tests to test the interaction between seednode and the AddrMan
@sr-gi sr-gi force-pushed the 2024-04-07-seednode-addrman branch from f3c4c4b to b41bbd5 Compare May 13, 2024 14:08
@sr-gi
Copy link
Member Author

sr-gi commented May 13, 2024

@cbergqvist I took your suggestion from #29605 (comment)

Copy link
Contributor

@cbergqvist cbergqvist 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 b41bbd5

Passed functional tests (with --extended --exclude=feature_dbcrash).

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

5 participants