Skip to content

net, rpc: return NET_UNROUTABLE as not_publicly_routable, automate helps#20965

Merged
maflcko merged 4 commits intobitcoin:masterfrom
jonatack:update-network-info
Feb 15, 2021
Merged

net, rpc: return NET_UNROUTABLE as not_publicly_routable, automate helps#20965
maflcko merged 4 commits intobitcoin:masterfrom
jonatack:update-network-info

Conversation

@jonatack
Copy link
Copy Markdown
Member

@jonatack jonatack commented Jan 19, 2021

per the IRC discussion today at http://www.erisian.com.au/bitcoin-core-dev/log-2021-01-19.html#l-87

  • return a more helpful string name for Network::NET_UNROUTABLE: "not_publicly_routable" instead of "unroutable"
  • update the RPC getpeerinfo "network" help, and automate it and the getnetworkinfo "network#name" and the -onlynet help doc generation

Copy link
Copy Markdown
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.

ACK d9ca41964dae2bc58ed8f9639847951beb0f3453

@jonatack jonatack force-pushed the update-network-info branch from d9ca419 to 181fe06 Compare January 29, 2021 01:20
@DrahtBot
Copy link
Copy Markdown
Contributor

DrahtBot commented Jan 29, 2021

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.

@jonatack jonatack force-pushed the update-network-info branch from b0ed5b1 to 355ca86 Compare January 29, 2021 15:05
@jonatack
Copy link
Copy Markdown
Member Author

Updated per review feedback by @MarcoFalke and @theStack and added an optional commit to use named casts (can be dropped if preferred).

Copy link
Copy Markdown
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.

light re-ACK 4c97ff24eef77bde3c27258f93e8d216caac9cc8 🦉

Reviewed the second commit via --color-moved=dimmed-zebra to verify that the changes involving GetNetworksInfo were move-only (apart from taking advantage of C++11 initializer list at one place) .
Changes LGTM, also replacing C-style casts with named casts is a good idea to enable compile time checks. My reason for only "light"-ACKing: I'm not 100% sure how dynamic the generation of RPC help texts is allowed to be, other uses of Join(...) in RPC help texts seem only to use constants:

$ git grep RPC.*Join
src/rpc/net.cpp:                            {RPCResult::Type::STR, "network", "Network (" + Join(GetNetworkNames(), ", ") + ")"},
src/rpc/net.cpp:                                {RPCResult::Type::STR, "permission_type", Join(NET_PERMISSIONS_DOC, ",\n") + ".\n"},
src/rpc/net.cpp:                            {RPCResult::Type::STR, "connection_type", "Type of connection: \n" + Join(CONNECTION_TYPE_DOC, ",\n") + ".\n"
src/rpc/net.cpp:                                {RPCResult::Type::STR, "name", "network (" + Join(GetNetworkNames(), ", ") + ")"},

@jonatack
Copy link
Copy Markdown
Member Author

jonatack commented Jan 30, 2021

@theStack thanks for having a look--I asked myself the same question and decided to start with proposing dynamic generation because returning the help doc isn't a perf hotspot and, unlike the two existing cases, this one can be generated automatically (the functional tests enforce a sanity check on any upstream updates).

@maflcko
Copy link
Copy Markdown
Member

maflcko commented Jan 31, 2021

replacing C-style casts with named casts is a good idea to enable compile time checks

What is an example for a compile time check that is enabled when using those for numeric types? I am only aware of compile time checks that are enabled for pointers. Static casts for numeric values are just overly verbose for no reason and I'd prefer not to change existing code.

@theStack
Copy link
Copy Markdown
Contributor

What is an example for a compile time check that is enabled when using those for numeric types?

If the destination type is numeric, the named cast asserts at compile time that also the source type is numeric, while a c-style cast doesn't in all cases:

long foo = (long)some_pointer; // compiles happily
long bar = static_cast<long>some_pointer; // "error: invalid ‘static_cast’ from type ‘char*’ to type ‘long int’"

Also note that modern C++ coding guidelines discourage the use of C casts:
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Res-casts-named
https://google.github.io/styleguide/cppguide.html#Casting

That said, I'm happy to re-ACK this PR also without the third commit.

Copy link
Copy Markdown
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.

ok, fair enough on the static_cast, but changing existing code (especially one that is about to get removed) might not be worth it.

@jonatack jonatack force-pushed the update-network-info branch from 4c97ff2 to 23299de Compare January 31, 2021 19:54
@jonatack
Copy link
Copy Markdown
Member Author

Yup, dropped the last commit, it's not related to this change and can be done later when the relevant lines are touched. Thanks for reviewing!

Copy link
Copy Markdown
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.

re-ACK 23299def6acda0c07d14274c605dbd4c9d23fe56 🍏

Copy link
Copy Markdown
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.

left some feedback on 23299def6acda0c07d14274c605dbd4c9d23fe56 🔌

Show signature and timestamp

Signature:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

left some feedback  on 23299def6acda0c07d14274c605dbd4c9d23fe56 🔌
-----BEGIN PGP SIGNATURE-----

iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUipnAv/YQrIj8eF8B2E2U0kCmbK1ftlsNowtsHgXUIHRB+1Ow8i3c7ZsjYnQp7Z
CfdGVWgiQ/4UkWIXlimM+8IBkQnkggupIQN4w4/3Gm7i9R3HlC4AMQV+Qov7Jhpn
qPRf2jbt9sUJCYt0tW7sH/TvwZTjJrOkM9wy6PseK8u06bTTWdVWRGjl/bZ7cCt5
RZ0sJ01AQ4y7dDCMgbKPx/t120RdzPwFT/blSLXi0/SIWZNtfX7oXQ+nlKEJ5bIa
jeg/z5P88QkfWsbMbSERycZW3WbFA13o7Um39P/tSdzBzOa8ykXA/fHdJo7g8oC/
SOQk8oqSJuDsL7jEkM78JrBt4AIiIOSuIXnafb0nvZ1ZA9tDoRrxsK7bNV2HZ9nr
fKuy++V7LJsMwRzn6jLeZARkHGDT8RNpTnpDYOiCC5dGfCgxJhwQ/hZ0mcVDrTZd
nGRo63Fe7O3zKnnenNZRHB5m+yfuq0rslIveDgNCeRdmusGrc+UnGAYcxQO++z5J
8PopnI7e
=tod6
-----END PGP SIGNATURE-----

Timestamp of file with hash 27f463ade22a48024739db23d1039da56bed75cd5631f55b35e5df1c8ebcbea7 -

@jonatack jonatack force-pushed the update-network-info branch 2 times, most recently from fbc694a to bbb07d1 Compare February 1, 2021 11:23
@jonatack
Copy link
Copy Markdown
Member Author

jonatack commented Feb 1, 2021

Updated per git diff 23299de bbb07d1 for @MarcoFalke's feedback (thanks!)

@jonatack jonatack force-pushed the update-network-info branch from bbb07d1 to 96635e6 Compare February 1, 2021 23:19
@jonatack
Copy link
Copy Markdown
Member Author

jonatack commented Feb 1, 2021

Realized that -onlynet in src/init.cpp should use GetNetworkNames() too. Rebased, as -onlynet was just changed, and updated.

@jonatack jonatack changed the title net, rpc: return NET_UNROUTABLE as not_publicly_routable, update rpc helps net, rpc: return NET_UNROUTABLE as not_publicly_routable, automate helps Feb 1, 2021
Copy link
Copy Markdown
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.

re-ACK 96635e6 🌳
Note that the exact string listing in parantheses changes slightly now, as the "or" part is not there anymore, but I think we can perfectly live with that.

@jonatack
Copy link
Copy Markdown
Member Author

Note that the exact string listing in parantheses changes slightly now, as the "or" part is not there anymore, but I think we can perfectly live with that.

Indeed. I hesitated to do something like

names.emplace_back("or " + GetNetworkName(NET_UNROUTABLE));

Copy link
Copy Markdown
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 96635e6 🐗

Show signature and timestamp

Signature:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

review ACK 96635e61777add29b6a34d47767a63f43b2919af 🐗
-----BEGIN PGP SIGNATURE-----

iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUi1nAv8Co9dfz7Kuxi/uUXJ3ob+y0mhUj0d023QFAyW/2Wh/C+QKZu6HRs8Q8Qh
PG+LNvgT+xfvEZb3bYPUUalSmODqU4OkgkulK1YPCr4zxquExcSFkSFkJL8gZzRu
CyduWAzAfGf2I0lGopqgsHMpfs6Q7SYeoEyXRHjztEzZu2FWZMQEuU5APep5e4q9
tw9Qkw1cfScc0rhROs+GbRj6N8AxA0B+GvvKWvc7Y16RfCIaWlP4vKzwN0s18Lzb
JPKRTTKmasfGHkIgnPCKmR2nlu5z8PekfGtvo5wMrRC5fVsFxedgTrtVuaRBk/Jc
IOM7qdVHvp/ClMvbu78Dm9kTwPTs2yFvg9/XcN57vTNQb4Qme9DJiMzOtELvwgaE
xM3xbwskCTldH6CPwMU7QJtmJxHnsNuO0VmtD7BX4QdCpyGXVXwjoYVpN6yn+/BJ
Ad9EKVDN/OCiC+jXiidgQvy6aiUoev1CEH23zvk3RRLXp+HbqNQfLzJfk6deQ5uF
GAJxcJlJ
=v5MP
-----END PGP SIGNATURE-----

Timestamp of file with hash 946105e795bca254ed011a4ffce2cf299168c362a6c99aed2702782f5738dc7f -

@maflcko maflcko merged commit 489030f into bitcoin:master Feb 15, 2021
@jonatack jonatack deleted the update-network-info branch February 15, 2021 14:39
std::vector<std::string> names;
for (int n = 0; n < NET_MAX; ++n) {
const enum Network network{static_cast<Network>(n)};
if (network == NET_UNROUTABLE || network == NET_I2P || network == NET_CJDNS || network == NET_INTERNAL) continue;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vasild you may want to update this line to remove NET_I2P (and add it to the rpc_net.py tests) in #20685 (if you're inclined to do it there)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 433d9a9f1e416c5518f832b4ca9402c8807877bc net: Do not skip the I2P network from GetNetworkNames(), thanks for the notice!

sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Feb 15, 2021
…routable, automate helps

96635e6 init: use GetNetworkNames() in -onlynet help (Jon Atack)
0dbde70 rpc: use GetNetworkNames() in getnetworkinfo and getpeerinfo helps (Jon Atack)
1c3af37 net: create GetNetworkNames() (Jon Atack)
b45eae4 net: update NET_UNROUTABLE to not_publicly_routable in GetNetworkName() (Jon Atack)

Pull request description:

  per the IRC discussion today at http://www.erisian.com.au/bitcoin-core-dev/log-2021-01-19.html#l-87

  - return a more helpful string name for `Network::NET_UNROUTABLE`: "not_publicly_routable" instead of "unroutable"
  - update the RPC getpeerinfo "network" help, and automate it and the getnetworkinfo "network#name" and the -onlynet help doc generation

ACKs for top commit:
  theStack:
    re-ACK 96635e6 🌳
  MarcoFalke:
    review ACK 96635e6 🐗

Tree-SHA512: 511a7d987126b48a7a090739aa7c4964b6186a3ff8f5f7eec9233dd816c6b7a6dc91b3ea6b824aa68f218a8a3ebdc6ffd214e9a88af38f2bf23f3257c4284c3a
@jonatack
Copy link
Copy Markdown
Member Author

@shesek done, per your original IRC issue getpeerinfo's network field returns (and documents in the help) the Network::NET_UNROUTABLE type as "not_publicly_routable" (master/v22.0)

Copy link
Copy Markdown

@trongham trongham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tr

luke-jr pushed a commit to bitcoinknots/bitcoin that referenced this pull request Jun 27, 2021
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Feb 15, 2022
Summary:
> net: update NET_UNROUTABLE to not_publicly_routable in GetNetworkName()

> net: create GetNetworkNames()

> rpc: use GetNetworkNames() in getnetworkinfo and getpeerinfo helps

> init: use GetNetworkNames() in -onlynet help

This is a backport of [[bitcoin/bitcoin#20965 | core#20965]]

Depends on D11030

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Subscribers: Fabien

Differential Revision: https://reviews.bitcoinabc.org/D11036
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 18, 2022
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.

6 participants