Skip to content

Conversation

vasild
Copy link
Contributor

@vasild vasild commented Feb 11, 2024

Turn the std::vector to std::array because it is cheaper and allows us to have the number of the messages as a compile time constant: ALL_NET_MESSAGE_TYPES.size() which can be used in future code to build other std::arrays with that size.


This change is part of #29418 but it makes sense on its own and would be good to have it, regardless of the fate of #29418. Also, if this is merged, that would reduce the size of #29418, thus the current standalone PR.

@DrahtBot
Copy link
Contributor

DrahtBot commented Feb 11, 2024

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

Code Coverage

For detailed information about the code coverage, see the test coverage report.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK jonatack, maflcko, willcl-ark, achow101
Concept ACK epiccurious, Empact

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #29418 (rpc: provide per message stats for global traffic via new RPC 'getnetmsgstats' by vasild)

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.

@DrahtBot DrahtBot added the P2P label Feb 11, 2024
@epiccurious
Copy link
Contributor

Concept ACK 2e312ea.

Copy link
Member

@willcl-ark willcl-ark left a comment

Choose a reason for hiding this comment

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

ACK 2e312ea

This is a clean tidy-up, and as mentioned useful for #29418 but stands on it's own (as a smalle improvement) too.

Left one req for comment update if touched again.

@vasild vasild force-pushed the message_types_compile_constant branch from 2e312ea to 808fe4e Compare February 14, 2024 16:45
@vasild
Copy link
Contributor Author

vasild commented Feb 14, 2024

2e312ea909...808fe4ef80: update comment, see #29421 (comment)

@vasild vasild force-pushed the message_types_compile_constant branch from 808fe4e to c29350f Compare February 15, 2024 14:47
@Empact
Copy link
Contributor

Empact commented Feb 27, 2024

Concept ACK

@maflcko
Copy link
Member

maflcko commented Feb 28, 2024

Seems fine, but NACK on the approach. This switches a vector of std::string objects (which is type-safe) to an array of raw pointers (not type-safe). This has already lead to a bug in this pull request, and is asking for more bugs to happen in the future, so I don't think it is worth it as-is.

@vasild vasild force-pushed the message_types_compile_constant branch from c7c613c to fd6a481 Compare February 28, 2024 14:37
@vasild
Copy link
Contributor Author

vasild commented Feb 28, 2024

c7c613c414...fd6a481995: rename g_all_net_message_types to ALL_NET_MESSAGE_TYPES as per #29421 (comment)

@vasild vasild force-pushed the message_types_compile_constant branch from fd6a481 to 546d132 Compare February 28, 2024 16:57
@vasild
Copy link
Contributor Author

vasild commented Feb 28, 2024

@maflcko good point! Changed from const char* to std::string in fd6a481995...546d13274d (can't have constexpr with std::string, thus dropped the constexpr, it was never the point of this PR).

Turn the `std::vector` to `std::array` because it is cheaper and
allows us to have the number of the messages as a compile time
constant: `ALL_NET_MESSAGE_TYPES.size()` which can be used in
future code to build other `std::array`s with that size.
As a side effect the names of the constants do not have to be
repeated in `src/protocol.cpp`.
@vasild vasild force-pushed the message_types_compile_constant branch from 546d132 to b3efb48 Compare February 28, 2024 17:04
@vasild
Copy link
Contributor Author

vasild commented Feb 28, 2024

546d13274d...b3efb48673: remove now unnecessary explicit conversion to std::string in SimulationTest().

@vasild
Copy link
Contributor Author

vasild commented Mar 8, 2024

@maflcko, this has a NACK from you and I have addressed your concern. If not ACK, it would be nice if you can at least remove your NACK. Thanks for the review so far!

@vasild
Copy link
Contributor Author

vasild commented May 2, 2024

ping @maflcko

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 b3efb48

@DrahtBot DrahtBot requested review from willcl-ark and Empact May 16, 2024 19:29
@@ -7,87 +7,6 @@

#include <common/system.h>

#include <atomic>
Copy link
Member

Choose a reason for hiding this comment

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

unrelated change, but looks fine

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.

Sorry for missing the ping. Now it looks good, because the only change is vector->array and some style fixups.

utACK b3efb48 🎊

Show signature

Signature:

untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
trusted comment: utACK b3efb486732f3caf8b8a8e9d744e6d20ae4255ef 🎊
SkLePLuDXM+ymjKH3KbyoYmBU/CTns4Bd4K8JycRF2zRDl2t3QMwQrGtZcNnOZ88NGBjgAWuIpsGTMsQzwHKBw==

Copy link
Member

@willcl-ark willcl-ark left a comment

Choose a reason for hiding this comment

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

ACK b3efb48

Based on range diff from previous ACK, all looks good!
range-diff 2e312ea...b3efb48

@achow101
Copy link
Member

ACK b3efb48

@achow101 achow101 merged commit 6c13b13 into bitcoin:master May 21, 2024
/**
* The version message provides information about the transmitting node to the
* receiving node at the beginning of a connection.
*/
extern const char* VERSION;
inline constexpr const char* VERSION{"version"};
Copy link
Member

Choose a reason for hiding this comment

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

Might as well make these std::string? Or is there still a good reason that these are char*? (it used to be that the message-making functions took char*, but i don't think that's the case anymore)

Copy link
Member

Choose a reason for hiding this comment

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

IIRC this was left because constexpr std::string was not available, but perhaps it is now in c++20?

Copy link
Member

Choose a reason for hiding this comment

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

i mean it's defining an array of std::string constexpr below it, so i would expect single std::strings to be possible too, i haven't tried it though

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, it could make sense to switch this from brittle raw pointers literals to type-safe string_view or string in a follow-up.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, IIRC string_view was tried in this pull and needed more patches, so it was left for a follow-up what to do here.

Copy link
Contributor Author

@vasild vasild May 28, 2024

Choose a reason for hiding this comment

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

This was tried: #29421 (comment)

Here is a draft that changes to std::string_view the following:

  • NetMsgType::*
  • ALL_NET_MESSAGE_TYPES
  • CMessageHeader:pchCommand (renamed to CMessageHeader:m_command)
  • CNetMessage::m_type
  • V2_MESSAGE_IDS
  • V2MessageMap::m_map
  • V2Transport::m_send_type

and the functions that handle message types.

The scope of this can be reduced by converting the std::string_view to std::string at some point. The previous code uses std::string (or char*) everywhere.

https://github.com/vasild/bitcoin/commits/NetMsgType_string_view/

@vasild vasild deleted the message_types_compile_constant branch May 24, 2024 14:54
@bitcoin bitcoin locked and limited conversation to collaborators May 28, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants