-
Notifications
You must be signed in to change notification settings - Fork 38.8k
p2p: give seednodes time before falling back to fixed seeds #27577
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
p2p: give seednodes time before falling back to fixed seeds #27577
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. ConflictsReviewers, 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. |
sr-gi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tACK 01c7fb6
I think it makes sense to prioritize nodes provided via seednode over fixed seeds. However, this makes me think whether we'd like to do the same over dnsseed.
The proposed changes LGTM. Replacing the m_addr_fetch.empty() by use_seednodes doesn't seem to have any side effects, given m_addr_fetch is only populated by addresses provided via seednode and by ThreadDNSAddressSeed. In the former, it means that it cannot be the case that m_addr_fetch is empty if use_seednodes is set. Whereas for the latter, this only triggers provided dnsseed is enabled, so it won't matterfor our case.
There are a couple of things I realized that may be simplifiable even though they are not directly modified by this PR, but are part of the logic around it, check comments inline.
src/net.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cannot add_fixed_seeds_now be defined here, outside the while loop?
As this is currently defined it could be the case that the flag is re-defined multiple times while waiting for start + std::chrono::minutes{1}) to trigger, while there shouldn't be a need for that. The flag should never go from false to true, so I miss the point of having it within the loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having variables defined over a shorter scope is better than a longer one; it gives the compiler better opportunities to optimise the code and to reuse the variable's memory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'd prefer to leave add_fixed_seeds_now within the current scope, especially because my plan is to follow up by moving the entire fixed seed logic out of ThreadOpenConnections into what is currently ThreadDNSAddressSeed (#26114). One reason for opening this PR is so that the move into another thread can be more of a refactor and doesn't change timing behavior noticeably.
ajtowns
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approach ACK 01c7fb639f72f12e3d1ed3aa3da9b86ce1279e81
Before, we'd remove a seednode from the list right after connecting to it, leading to a race with loading the fixed seed and connecting to them.
01c7fb6 to
3077812
Compare
|
01c7fb6 to 3077812: Addressed suggestions by @sr-gi and @ajtowns
I agree that it could make sense to not query |
dergoegge
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code review ACK 3077812
sr-gi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 3077812 with a tiny nit, feel free to ignore it
| add_fixed_seeds_now = true; | ||
| LogPrintf("Adding fixed seeds as 60 seconds have passed and addrman is empty for at least one reachable network\n"); | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: maybe remove this line between the if/else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'll remove it in a follow-up #26114 unless I need retouch for another reason.
Agreed that this should be part of a separate PR. |
|
utACK 3077812 |
|
ACK 3077812 Code looks good and a manual test showed that there is now a 1 minute wait after attempting a seednode before the fixed seeds are added. |
…fixed seeds 3077812 net: Give seednodes time before falling back to fixed seeds (Martin Zumsande) Pull request description: `-seednode` is an alternative bootstrap mechanism - when choosing it, we make a `AddrFetch` connection to the specified peer, gather addresses from them, and then disconnect. Presumably, if users specify a seednode they prefer addresses from that node over fixed seeds. However, when disabling dns seeds and specifiying `-seednode`, `CConnman::ProcessAddrFetch()` immediately removes the entry from `m_addr_fetches` (before the seednode could give us addresses) - and once `m_addr_fetches` is empty, `ThreadOpenConnections` will add fixed seeds, resulting in a "race" between the fixed seeds and seednodes filling up AddrMan. This PR suggests to check for any provided `-seednode` arg instead of using the size of `m_addr_fetches`, thus delaying the querying of fixed seeds for 1 minute when specifying any seednode (as we already do for `addnode` peers). That way, we actually give the seednodes a chance for to provide us with addresses before falling back to fixed seeds. This can be tested with `bitcoind -debug=net -dnsseed=0 -seednode=(...)` on a node without `peers.dat` and observing the debug log. ACKs for top commit: ajtowns: utACK 3077812 achow101: ACK 3077812 dergoegge: Code review ACK 3077812 sr-gi: ACK [3077812](bitcoin@3077812) with a tiny nit, feel free to ignore it Tree-SHA512: 96446eb34c0805f10ee158a00a3001a07029e795ac40ad5638228d426e30e9bb836c64ac05d145f2f9ab23ec5a528f3a416e3d52ecfdfb0b813bd4b1ebab3c01
Before, we'd remove a seednode from the list right after connecting to it, leading to a race with loading the fixed seed and connecting to them. Github-Pull: bitcoin#27577 Rebased-From: 3077812
…rovided 82f41d7 Added seednode prioritization message to help output (tdb3) 3120a46 Gives seednode priority over dnsseed if both are provided (Sergi Delgado Segura) Pull request description: This is a follow-up of #27577 If both `seednode` and `dnsseed` are provided, the node will start a race between them in order to fetch data to feed the `addrman`. This PR gives priority to `seednode` over `dnsseed` so if some nodes are provided as seeds, they can be tried before defaulting to the `dnsseeds` ACKs for top commit: davidgumberg: untested reACK 82f41d7 itornaza: tested re-ACK 82f41d7 achow101: ACK 82f41d7 cbergqvist: ACK 82f41d7 Tree-SHA512: 4e39e10a7449af6cd9b8f9f6878f846b94bca11baf89ff2d4fbcd4f28293978a6ed71a3a86cea36d49eca891314c834e32af93f37a09c2cc698a878f84d31c62
-seednodeis an alternative bootstrap mechanism - when choosing it, we make aAddrFetchconnection to the specified peer, gather addresses from them, and then disconnect. Presumably, if users specify a seednode they prefer addresses from that node over fixed seeds.However, when disabling dns seeds and specifiying
-seednode,CConnman::ProcessAddrFetch()immediately removes the entry fromm_addr_fetches(before the seednode could give us addresses) - and oncem_addr_fetchesis empty,ThreadOpenConnectionswill add fixed seeds, resulting in a "race" between the fixed seeds and seednodes filling up AddrMan.This PR suggests to check for any provided
-seednodearg instead of using the size ofm_addr_fetches, thus delaying the querying of fixed seeds for 1 minute when specifying any seednode (as we already do foraddnodepeers).That way, we actually give the seednodes a chance for to provide us with addresses before falling back to fixed seeds.
This can be tested with
bitcoind -debug=net -dnsseed=0 -seednode=(...)on a node withoutpeers.datand observing the debug log.