-
Notifications
You must be signed in to change notification settings - Fork 37.7k
net, refactor: remove unneeded exports, use helpers over low-level code, use optional #28078
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, refactor: remove unneeded exports, use helpers over low-level code, use optional #28078
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. |
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.
Concept ACK but I think some changes are unnecessary churn
0496b12
to
5d7188e
Compare
Thank you for the excellent review @stickies-v -- updated to take your feedback. |
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 5d7188e
5d7188e
to
c69a742
Compare
I thought we were going to avoid unproductive refactors? |
I'm unaware of the context behind that comment but see similar refactoring in many pull requests and, in general, there are good reasons for them; in this case, removing unneeded exports and simplifying and removing code. (If you'd like to review a pull that fixes something, may I re-review beg for #27231 that was updated to take your feedback? Thanks!) |
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 c69a742
Good changes, easy to review. Thanks!
About the commit messages:
Move IsPeerAddrLocalGood() from header to implementation
it was in the .cpp
file before (it was not in the header file). Better: make IsPeerAddrLocalGood() private in net.cpp since it is not used outside of that file
. Same for
Move CaptureMessageToFile() from header to implementation
and
Move GetLocal() from header to implementation
.
Co-authored-by: Jon Atack <jon@atack.com>
c69a742
to
8d66cf7
Compare
Updated to take all feedback by @stickies-v and @vasild -- thank you! |
8d66cf7
to
8a5952a
Compare
Co-authored-by: Vasil Dimov <vd@FreeBSD.org>
rather than low-level comparisons with Network enum values.
Co-authored-by: stickies-v <stickies-v@protonmail.com>
and make them nodiscard. Member functions containing a few lines of code are usually inlined, either implicitly by defining them in the declaration as done here, or declared inline. References https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-inline https://google.github.io/styleguide/cppguide#Inline_Functions https://www.ibm.com/docs/en/i/7.1?topic=only-inline-member-functions-c
8a5952a
to
4ecfd3e
Compare
I think some of the changes here are fine, but seem to be done somewhat verbosely. There are 3 commits (5ba73cd, df48856, 5316ae5) that independently change/refactor Speaking generally, not sure about the addition of |
I can see the desire to enforce it everywhere, but then it should be done via clang-tidy or a clang-tidy plugin. Ideally without modifying the source code at all. |
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 4ecfd3e
I am also ok to add new functions in the same commit in which they are going to be used.
offtopic There are 3 classes of functions wrt
I guess |
Re
In this case, the changes have only two lines of diff in common out of a few dozen, so there's little redundancy. They are different kinds of changes that make more sense separately and are easier to review that way -- which I strive for, like the comment above: "Good changes, easy to review. Thanks!" (Thanks!) |
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 4ecfd3e
That said:
- I was ~0 on the
[[nodiscard]]
changes before, but am now in favour of removing all the ones in this PR. The only place where it made sense, imo, was in 5ba73cd for[[nodiscard]] static bool GetLocal(CService& addr, const CNode& peer)
where it's dangerous to use the out-parameter without checking the return value. Now, in all cases, the functions are entirely self explanatory and I don't really see any footguns. Keeping[[nodiscard]]
for (potentially) dangerous places and catching inefficiences with clang-tidy e.a. seems like a much more productive way over filling up the codebase with[[nodiscard]]
statements that mostly just make it less legible. - I'd prefer dropping the last commit 4ecfd3e, it doesn't really add anything and could be considered arbitrary (for new code I'd slightly prefer inlining it as done in this PR, but I can see other people preferring the current, and then it's not worth the churn imo)
~0 I don't think that PRs like this are a good use of reviewers' time, especially since this conflicts with a priority project. Minor refactors such as this cause code churn, conflict with other high priority PRs, and really only clean up the code style. It does not seem to meaningfully contribute to larger projects/goals of this project. |
ACK 4ecfd3e Merging as the 324 PRs need rebasing anyways. However I don't think we should have PRs like this in the future. |
…ers over low-level code, use optional
This change is the cause of: node0 stderr ==75935== Thread 25 b-msghand:
==75935== Conditional jump or move depends on uninitialised value(s)
==75935== at 0x1955B8: _M_reset (optional:313)
==75935== by 0x1955B8: ~_Optional_payload (optional:437)
==75935== by 0x1955B8: ~_Optional_base (optional:508)
==75935== by 0x1955B8: GetLocalAddress(CNode const&) (???:220)
==75935== by 0x1956A3: GetLocalAddrForPeer(CNode&) (net.cpp:240)
==75935== by 0x1D091F: MaybeSendAddr (net_processing.cpp:5259)
==75935== by 0x1D091F: (anonymous namespace)::PeerManagerImpl::SendMessages(CNode*) (???:5453)
==75935== by 0x1AA183: CConnman::ThreadMessageHandler() (net.cpp:2886)
==75935== by 0x750627: operator() (std_function.h:591)
==75935== by 0x750627: util::TraceThread(std::basic_string_view<char, std::char_traits<char> >, std::function<void ()>) (???:21)
==75935== by 0x1B290F: __invoke_impl<void, void (*)(std::basic_string_view<char, std::char_traits<char> >, std::function<void ()>), const char *, (lambda at net.cpp:3231:71)> (invoke.h:61)
==75935== by 0x1B290F: __invoke<void (*)(std::basic_string_view<char, std::char_traits<char> >, std::function<void ()>), const char *, (lambda at net.cpp:3231:71)> (invoke.h:96)
==75935== by 0x1B290F: _M_invoke<0UL, 1UL, 2UL> (std_thread.h:292)
==75935== by 0x1B290F: operator() (std_thread.h:299)
==75935== by 0x1B290F: std::thread::_State_impl<std::thread::_Invoker<std::tuple<void (*)(std::basic_string_view<char, std::char_traits<char> >, std::function<void ()>), char const*, CConnman::Start(CScheduler&, CConnman::Options const&)::$_5> > >::_M_run() (std_thread.h:244)
==75935== by 0x4C501BF: execute_native_thread_routine (thread.cc:104)
==75935== by 0x4F85E37: start_thread (pthread_create.c:447)
==75935== by 0x4FF0E5B: thread_start (clone.S:79)
==75935==
{
<insert_a_suppression_name_here>
Memcheck:Cond
fun:_M_reset
fun:~_Optional_payload
fun:~_Optional_base
fun:_Z15GetLocalAddressRK5CNode
fun:_Z19GetLocalAddrForPeerR5CNode
fun:MaybeSendAddr
fun:_ZN12_GLOBAL__N_115PeerManagerImpl12SendMessagesEP5CNode
fun:_ZN8CConnman20ThreadMessageHandlerEv
fun:operator()
fun:_ZN4util11TraceThreadESt17basic_string_viewIcSt11char_traitsIcEESt8functionIFvvEE
fun:__invoke_impl<void, void (*)(std::basic_string_view<char, std::char_traits<char> >, std::function<void ()>), const char *, (lambda at net.cpp:3231:71)>
fun:__invoke<void (*)(std::basic_string_view<char, std::char_traits<char> >, std::function<void ()>), const char *, (lambda at net.cpp:3231:71)>
fun:_M_invoke<0UL, 1UL, 2UL>
fun:operator()
fun:_ZNSt6thread11_State_implINS_8_InvokerISt5tupleIJPFvSt17basic_string_viewIcSt11char_traitsIcEESt8functionIFvvEEEPKcZN8CConnman5StartER10CSchedulerRKNSE_7OptionsEE3$_5EEEEE6_M_runEv
fun:execute_native_thread_routine
fun:start_thread
fun:thread_start
}
==75935==
==75935== Exit program on first error (--exit-on-first-error=yes) which currently happens when using Clang 17 on aarch64 with Valgrind 3.22.0. May be similar to #27741, however that is with GCC 12 on x86_64. |
At a cursory look the code seems ok 🙄 #27741 looks unrelated, or at least is a problem that happens somewhere else in the code. |
This version, up until current master.
No. I compiled and ran tests locally.
I looked at the error, and then bisected based on who had recently changed this line. The commit prior to this PR being merged does not produce any error.
Yes. Compile using Clang 17.0.6 and run the functional tests under --valgrind (3.22.0). It may require being on an aarch64. |
Thanks, continued the discussion at #29635 |
and other improvements noticed while reviewing #27411.
Addresses #27411 (comment) and #27411 (comment).
See commit messages for details.