-
Notifications
You must be signed in to change notification settings - Fork 37.7k
p2p, rpc, test: expose tried and refcount in getnodeaddresses, update/improve tests #23035
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, rpc, test: expose tried and refcount in getnodeaddresses, update/improve tests #23035
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. 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. |
Concept ACK, approach NACK. I don't think it makes sense to add this addrman-specific data into the
I don't think we want to do (2) either. In general, we're trying to encapsulate addrman more. I think the best way to do this is update |
Thanks @jnewbery. I agree the two approaches aren't ideal. Will have a look at your suggested approach. |
A vector of |
Good point, though I'm not sure we want to depend on that coupling. (Ideally I'll try to use a struct as it's nicer to work with.) |
0cb526f
to
f6b5878
Compare
I'm curious why that is. I would have thought that using structured bindings to unpack a returned tuple would be just as easy: https://en.cppreference.com/w/cpp/language/structured_binding#Case_2:_binding_a_tuple-like_type. Another possible approach would be to add a new public method |
Pushed an update that doesn't touch CAddress or CAddrInfo while attempting to be clear and simple. |
I don't think there would be much logic coupling with a clearly documented function that returns pairs of <
I like the idea of minimizing impact to the p2p code paths for this test-only functionality. |
Hm, this isn't urgent, so it might be an idea to try the new public method variant based on/built on #22950 to be sure it's compatible. |
As long as you're just adding a new public method, it's compatible. @amitiuttarwar will need to update the header file to include that public method in the interface class declaration if this gets merged first, but I don't think that's any more/less work than merging the pimpl refactor first and then adding the public method. I'm happy to have a first attempt at implementing my suggestion if that'd be helpful to you. |
Rebased after merge of #22831. Structs/classes: I guess I like the friendly, readable built-in access to members via named methods, and their flexibility and adaptability to changing future requirements, like adding/removing members.
SGTM! can pull it in. With that alternative, maybe we could also remove the std::optional network arg from the existing GetAddr/GetAddresses functions. |
f6b5878
to
3378ec8
Compare
Here you go: https://github.com/jnewbery/bitcoin/tree/2021-09-getaddrwithrefcount. The first two commits add the new
Great idea! I added that as the final commit in the branch above. |
Thanks! That is helpful. I see that I was misreading the previous suggestion. |
🐙 This pull request conflicts with the target branch and needs rebase. Want to unsubscribe from rebase notifications on this pull request? Just convert this pull request to a "draft". |
I'm uncertain about this concept (adding table & refcount in
So overall, I think the biggest benefit to this added functionality would be for superusers or clients using the RPC interface to observe or build on addrman. Additionally, there seems to be some marginal benefit for the functional tests. I am uncertain if these benefits outweigh the maintenance costs of the code. Many thanks to @mzumsande for collaborating to form these thoughts :) |
for GetAddr(), CConnMan::GetAddresses() and RPC getnodeaddresses
with the new getnodeaddresses "tried" and "reference_count" fields
3378ec8
to
ad3c725
Compare
It may also be handy for |
This overlaps with #23826. It's not completely redundant, since that PR doesn't expose the tried/new and multiplicity through a public API, but it does add a method to fetch that data that can be used by the unit tests. I think that's probably enough, since addrman is now well-contained enough that it can be fully tested through the unit tests. WDYT @jonatack? |
What is the state of this change? It seems like it could have been (at least somewhat) obsoleted by other now-merged changes. |
Will update or close after reviewing the changes. |
Feel free to reopen once you've gotten a chance to look at this again. |
Based on #22831, this pull implements the suggestion in #22831 (comment) to extend RPC getnodeaddresses to return whether the address is in the tried or new table, and if it's in the new table, its refcount. Doing so allows us to better test the contents of the addrman using a public interface instead of relying on assert_debug_log in the functional tests. The pull then updates the getnodeaddresses and addpeeraddress test coverage, followed by improving the relevant asmap test coverage.
Credit to John Newbery for the idea.