-
Notifications
You must be signed in to change notification settings - Fork 38.7k
net: use std::chrono throughout maxOutbound logic #20253
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
Conversation
|
Concept ACK |
theStack
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.
Concept ACK
Note that the functions SetMaxOutbound{Target,Timeframe} are also used in the fuzz test test/fuzz/connman.cpp, hence the uses should also be removed there.
Thanks. I've dropped them from the fuzz tests now. |
788a945 to
3c84c6d
Compare
|
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 |
|
🐙 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". |
3c84c6d to
803212c
Compare
|
Rebased for #20408 and fixed an oversight in the fuzz changes. |
803212c to
2404f78
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.
Concept ACK, especially cleaning up init.
Longer term, it'd be nice to move initialization of some of these CConnman parameters into the constructor and make them const. That clarifies the initialization and means that they don't need to be guarded by a mutex.
2404f78 to
79d8998
Compare
|
I've rebased this, cherry-picked in fa11110 from 20602 and updated some std::chrono usage to use literals as suggested. |
79d8998 to
832fc10
Compare
jonatack
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 832fc10e9e45abf92a4f04012c918156d92a3649
with some optional style ideas below
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.
832fc10e9e45abf92a perhaps use explicit typing here, const, and universal initialization to check for narrowing
- std::chrono::seconds cycleEndTime = nMaxOutboundCycleStartTime + MAX_UPLOAD_TIMEFRAME;
- auto now = GetTime<std::chrono::seconds>();
+ const std::chrono::seconds cycleEndTime{nMaxOutboundCycleStartTime + MAX_UPLOAD_TIMEFRAME};
+ const std::chrono::seconds now{GetTime<std::chrono::seconds>()};
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.
832fc10e9e45abf92a4f04012c918156 maybe prefer to be explicit about types and narrowing conversions in the net code
- std::chrono::seconds timeLeftInCycle = GetMaxOutboundTimeLeftInCycle();
- uint64_t buffer = timeLeftInCycle / std::chrono::minutes{10} * MAX_BLOCK_SERIALIZED_SIZE;
+ const std::chrono::seconds timeLeftInCycle{GetMaxOutboundTimeLeftInCycle()};
+ const uint64_t buffer{timeLeftInCycle / std::chrono::minutes{10} * static_cast<uint64_t>(MAX_BLOCK_SERIALIZED_SIZE)};
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.
832fc10e9e45abf9 const and maybe explicit typing + narrowing check
| auto now = GetTime<std::chrono::seconds>(); | |
| const std::chrono::seconds now{GetTime<std::chrono::seconds>()}; |
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 std::chrono::seconds twice on the same line is pretty verbose. I'd like to think we can just use auto here because the type is clear from the call to GetTime<>().
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.
Yes, the reason for the comment here was constness.
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.
Note that existing code in the same file specifies the type explicitly, line 1646: const std::chrono::seconds now = GetTime<std::chrono::seconds>(); introduced in commit b24a17f
src/net.h
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.
Since this is only used internally in net, it could now be moved to the implementation cpp file to avoid exporting this symbol to other translation units.
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.
Done in the latest push.
jnewbery
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.
utACK 832fc10e9e
In case you touch this branch again: In commit net: remove nMaxOutboundTimeframe from connection options I think you need to change "DEFAULT_MAX_UPLOAD_TARGET is a compile time constant." to "DEFAULT_MAX_UPLOAD_TIMEFRAME is a compile time constant."
It's not actually possible to change this value, so remove the indirection of it being a conn option. DEFAULT_MAX_UPLOAD_TIMEFRAME is a compile time constant.
DEFAULT_MAX_UPLOAD_TARGET is a compile time constant.
832fc10 to
0475c8b
Compare
|
Rebased & addressed some comments.
I've fixed the commit message. |
maflcko
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.
review ACK 0475c8b 🎭
Show signature and timestamp
Signature:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
review ACK 0475c8ba4d10dce79092361bc4c23c11dadba39a 🎭
-----BEGIN PGP SIGNATURE-----
iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUjthwwAzVabd9gXhamR9ER43crYv/VUAp95aBP6//eaBjC5dwfvq8UzeJtoP9aF
NiVZ14+MDWyLQyUBZF+DYU3veWMHYgaIGSpOQ+ZlgVYCva2ZmkhqnlCk4de4jjcL
1WMJV9zxauGhITHd+AVqy2SyKd/6ljAMWn3v89KYqDApw7zzEIe5Jpbfq7f7kbbh
6d9X1XqQoSCNS+SwCouEu192Y9f+44jAo08FupUshCHMUMV+MZs87Hs3rD+N4DsX
95AZV1gO48HgDldPvUC7LZIieTIJFBpI4Y7dr/Re186h1csWc++8FbXOTLN12gg2
+KR4/XgqYVBNKBhv/X60Hc113MReXc3gbGqXtFMu1vVXRJnEXM5E/bk9qxYzsdFX
n5D97DMHOotQh1W61f7Mqlqk9N+qP28P2BfJwxamyVC1DQ4PiLvlY79kxm3UkWGx
BzFD1qqn7M67Twm2z1SO0nBgQZCXMPsmFI0dR+abUT4o5jUXMIovVef26reBTS8v
ReieyZiR
=+TOK
-----END PGP SIGNATURE-----
Timestamp of file with hash 963300e8377971b0f423721ee34e6ab50d44d071f41bb4f7f3598935d178a88d -
|
utACK 0475c8b |
Summary: ``` Switch to using std::chrono types for the max outbound related logic. Removes some unnecessary code from init. ``` Backport of [[bitcoin/bitcoin#20253 | core#20253]]. Depends on D10901. Ref T1696. Test Plan: ninja all check-all Reviewers: #bitcoin_abc, PiRK Reviewed By: #bitcoin_abc, PiRK Maniphest Tasks: T1696 Differential Revision: https://reviews.bitcoinabc.org/D10902
Switch to using
std::chronotypes for the max outbound related logic.Removes some unnecessary code from init.