-
Notifications
You must be signed in to change notification settings - Fork 35.5k
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: cleanup LookupIntern
, Lookup
and LookupHost
#26261
Conversation
Wouldn't a |
Given my experience in #26078, I'm not sure about using
I agree, I'd planned to do it in a follow-up (tried to keep this PR simple/easy to review) but could do it here, no problem. |
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.
Not sure about the benefits and code quality here.
I think you're right. At first sight it looked like in the current implementation there was the need to distinguish between invalid parameters (!ContainsNoNUL(name)
) and a name that just wouldn't resolve to any addresses (empty vector), but upon further inspection that seems to not be true.
but could do it here, no problem.
I think the main benefit of doing them all together is to ensure they all adhere to the same consistent interface. From a review point of view, that's most efficient too, and it shouldn't be a huge change anyway.
You're right, I am gonna turn this PR to draft to work on it. |
312415f
to
4a41b3a
Compare
std::vector<CNetAddr>
in LookupIntern
LookupIntern
, Lookup
and LookupHost
55829ab
to
2e9a2f7
Compare
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. |
f912a99
to
e4e03e9
Compare
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. Left a few comments and nits - a lot of the std::optional
comments recur in many different places in this PR, I didn't necessarily always point them all out.
e4e03e9
to
fc656d2
Compare
fc656d2
to
0bb44b5
Compare
Thanks @stickies-v for your valuable review, just addressed your suggestions! Ready for review! |
Thanks, @stickies-v for your review. Will address your latest suggestions in a follow-up PR. |
a699ef0
to
4eee95e
Compare
I had to touch Addressed: |
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.
re-ACK 4eee95e
Verified that the only changes are a refactoring to bench
, removing now unnecessary helper functions ResolveIP
and ResolveService
, and incorporating my previous outstanding review comments.
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 4eee95e
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.
re-ACK 4eee95e
Left two comments below, one nit and one "thinking out loud what could happen in the worst case", both no stoppers.
@brunoerg are you going to address nits or leave as is? I'd really like to get this merged asap to prevent further rebase conflicts. Happy to quickly re-ack nits too, though. |
@stickies-v I'm addressing them at this moment, will push soon. |
4eee95e
to
5c832c3
Compare
Force-pushed addressing:
Maybe done with nits, and we can have it merged? |
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.
re-ACK 5c832c3 - just addressing two nits, no other changes
git range-diff 8b59231641845f71df37e163bf5b8157fb197d05 4eee95e57bb6f773bcaeb405bca949f158a62134 5c832c3820253affc65c0ed490e26e5b0a4d5c9b
1: c0cf3d70e = 1: 5c1774a56 p2p, refactor: return `std::vector<CNetAddr>` in `LookupIntern`
2: 94b5edbf6 = 2: 7799eb125 p2p, refactor: return `std::vector<CNetAddr>` in `LookupHost`
3: 617bc481e ! 3: 34bcdfc6a p2p, refactor: return vector/optional<CService> in `Lookup`
@@ src/bench/addrman.cpp: static void AddrManSelectFromAlmostEmpty(benchmark::Bench
- CService addr = ResolveService("250.3.1.1", 8333);
- addrman.Add({CAddress(addr, NODE_NONE)}, ResolveService("250.3.1.1", 8333));
+ CService addr = Lookup("250.3.1.1", 8333, false).value();
-+ addrman.Add({CAddress(addr, NODE_NONE)}, Lookup("250.3.1.1", 8333, false).value());
++ addrman.Add({CAddress(addr, NODE_NONE)}, addr);
bench.run([&] {
(void)addrman.Select();
4: 4eee95e57 ! 4: 5c832c382 p2p, refactor: return `std::optional<CNetAddr>` in `LookupHost`
@@ src/rpc/net.cpp: static RPCHelpMan setban()
- CNetAddr resolved;
- LookupHost(request.params[0].get_str(), resolved, false);
- netAddr = resolved;
-+ const std::optional<CNetAddr> addr = LookupHost(request.params[0].get_str(), false);
++ const std::optional<CNetAddr> addr{LookupHost(request.params[0].get_str(), false)};
+ if (addr.has_value()) {
+ netAddr = addr.value();
+ }
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 5c832c3 |
…pHost` 5c832c3 p2p, refactor: return `std::optional<CNetAddr>` in `LookupHost` (brunoerg) 34bcdfc p2p, refactor: return vector/optional<CService> in `Lookup` (brunoerg) 7799eb1 p2p, refactor: return `std::vector<CNetAddr>` in `LookupHost` (brunoerg) 5c1774a p2p, refactor: return `std::vector<CNetAddr>` in `LookupIntern` (brunoerg) Pull request description: Continuation of bitcoin#26078. To improve readability instead of returning a bool and passing stuff by reference, this PR changes: - `LookupHost` to return `std::vector<CNetAddr>` - `LookupHost` to return `std::optional<CNetAddr>` - `Lookup` to return `std::vector<CService>` - `Lookup` to return `std::optional<CService>`. - `LookupIntern` to return `std::vector<CNetAddr>` As discussed in bitcoin#26078, it would be better to avoid using `optional` in some cases, but for specific `Lookup` and `LookupHost` functions it's necessary to use `optional` to verify if they were able to catch some data from their overloaded function. ACKs for top commit: achow101: ACK 5c832c3 stickies-v: re-ACK 5c832c3 - just addressing two nits, no other changes theStack: re-ACK 5c832c3 Tree-SHA512: ea346fdc54463999646269bd600cd4a1590ef958001d2f0fc2be608ca51e1b4365efccca76dd4972b023e12fcc6e67d226608b0df7beb901bdeadd19948df840
Continuation of #26078.
To improve readability instead of returning a bool and passing stuff by reference, this PR changes:
LookupHost
to returnstd::vector<CNetAddr>
LookupHost
to returnstd::optional<CNetAddr>
Lookup
to returnstd::vector<CService>
Lookup
to returnstd::optional<CService>
.LookupIntern
to returnstd::vector<CNetAddr>
As discussed in #26078, it would be better to avoid using
optional
in some cases, but for specificLookup
andLookupHost
functions it's necessary to useoptional
to verify if they were able to catch some data from their overloaded function.