Skip to content

Conversation

@fanquake
Copy link
Member

Switch to using std::chrono types for the max outbound related logic.
Removes some unnecessary code from init.

@practicalswift
Copy link
Contributor

Concept ACK

Copy link
Contributor

@theStack theStack left a 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.

@fanquake
Copy link
Member Author

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.

@DrahtBot
Copy link
Contributor

DrahtBot commented Nov 17, 2020

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, 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.

@jnewbery
Copy link
Contributor

Concept ACK

@DrahtBot
Copy link
Contributor

🐙 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".

@fanquake
Copy link
Member Author

Rebased for #20408 and fixed an oversight in the fuzz changes.

@fanquake fanquake force-pushed the net_unused_outbound branch from 803212c to 2404f78 Compare November 23, 2020 03:47
Copy link
Contributor

@jnewbery jnewbery left a 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.

@fanquake
Copy link
Member Author

fanquake commented Dec 9, 2020

I've rebased this, cherry-picked in fa11110 from 20602 and updated some std::chrono usage to use literals as suggested.

Copy link
Member

@jonatack jonatack left a 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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

@jonatack jonatack Dec 9, 2020

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

Suggested change
auto now = GetTime<std::chrono::seconds>();
const std::chrono::seconds now{GetTime<std::chrono::seconds>()};

Copy link
Member Author

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<>().

Copy link
Member

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.

Copy link
Member

@jonatack jonatack Dec 13, 2020

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
Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Contributor

@jnewbery jnewbery left a 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."

This has been unused since f3552da.
This was introduced in 872fee3 and it's unclear
if it's ever been used.
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.
@fanquake fanquake force-pushed the net_unused_outbound branch from 832fc10 to 0475c8b Compare December 13, 2020 03:44
@fanquake
Copy link
Member Author

Rebased & addressed some comments.

In case you touch this branch again:

I've fixed the commit message.

Copy link
Member

@maflcko maflcko left a 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 -

@jnewbery
Copy link
Contributor

utACK 0475c8b

@fanquake fanquake merged commit f1f2418 into bitcoin:master Dec 15, 2020
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Dec 15, 2020
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Jan 26, 2022
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
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
@fanquake fanquake deleted the net_unused_outbound branch November 9, 2022 16:31
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants