Rename message_command variables in src/net* and src/rpc/net.cpp #24141

pull shaavan wants to merge 2 commits into bitcoin:master from shaavan:220124-message changing 3 files +32 −32
  1. shaavan commented at 5:05 pm on January 24, 2022: contributor

    This PR is a follow-up to #24078.

    a message is not a command, but simply a message of some type

    The first commit covers the message_command variable name and comments not addressed in the original PR in src/net* files. The second commit goes beyond the original src/net* limit of #24078 and does similar changes in the src/rpc/net.cpp file.

  2. hebasto commented at 5:15 pm on January 24, 2022: member
    Concept ACK. Making rename commits a “scripted-diff” will simplify reviewing a lot.
  3. DrahtBot added the label P2P on Jan 24, 2022
  4. DrahtBot added the label RPC/REST/ZMQ on Jan 24, 2022
  5. prusnak commented at 6:55 pm on January 24, 2022: contributor

    Concept ACK. Making rename commits a “scripted-diff” will simplify reviewing a lot.

    Link to documentation how to use scripted-diff https://github.com/bitcoin/bitcoin/blob/master/doc/developer-notes.md#scripted-diffs and random commit showing how the commit message should look like: eb04badcd6108e17c8ec78e9c316775c334030cb

  6. hebasto commented at 7:33 pm on January 24, 2022: member

    … and random commit showing how the commit message should look like: eb04bad

    Another example – c4a31ca267f74bff76a43878177d05d22825a203 – with git grep --files-with-matches usage.

  7. RandyMcMillan commented at 9:12 pm on January 24, 2022: contributor

    I ran this script against your PR - https://raw.githubusercontent.com/shaavan/bitcoin/dd720d20d994bcac9974ca12db849baaff5adabe/24141-scripted-diff.sh

     0#!/bin/bash -e
     1
     2function s1() { git grep -l "$1" src/net* | xargs sed -i .old "s/$1/$2/g"; }
     3
     4 s1 'mapSendBytesPerMsgCmd' 'mapSendBytesPerMsg'
     5 s1 'NET_MESSAGE_COMMAND_OTHER' 'NET_MESSAGE_OTHER'
     6 s1 'mapRecvBytesPerMsgCmd' 'mapRecvBytesPerMsg'
     7 s1 'mapMsgCmdSize' 'mapMsgSize'
     8 s1 'sendPerMsgCmd' 'sendPerMsg'
     9 s1 'mapSendBytesPerMsgCmd' 'mapSendBytesPerMsg'
    10 s1 'recvPerMsgCmd' 'recvPerMsg'
    11
    12function s2() { git grep -l "$1" src/rpc/net* | xargs sed -i .old "s/$1/$2/g"; }
    13
    14 s2 'mapSendBytesPerMsgCmd' 'mapSendBytesPerMsg'
    15 s2 'NET_MESSAGE_COMMAND_OTHER' 'NET_MESSAGE_OTHER'
    16 s2 'mapRecvBytesPerMsgCmd' 'mapRecvBytesPerMsg'
    17 s2 'mapMsgCmdSize' 'mapMsgSize'
    18 s2 'sendPerMsgCmd' 'sendPerMsg'
    19 s2 'mapSendBytesPerMsgCmd' 'mapSendBytesPerMsg'
    20 s2 'recvPerMsgCmd' 'recvPerMsg'
    
  8. RandyMcMillan commented at 9:15 pm on January 24, 2022: contributor
    Concept ACK
  9. in src/rpc/net.cpp:159 in e80330bfc0 outdated
    155@@ -156,7 +156,7 @@ static RPCHelpMan getpeerinfo()
    156                         {RPCResult::Type::NUM, "msg", "The total bytes received aggregated by message type\n"
    157                                                       "When a message type is not listed in this json object, the bytes received are 0.\n"
    158                                                       "Only known message types can appear as keys in the object and all bytes received\n"
    159-                                                      "of unknown message types are listed under '"+NET_MESSAGE_COMMAND_OTHER+"'."}
    


    w0xlt commented at 9:30 pm on January 24, 2022:
    Shouldn’t this be in the previous commit?

    shaavan commented at 1:42 pm on January 25, 2022:
    This change is done in src/rpc/net.cpp file. The first commit makes changes to src/net.cpp and src/net.h files.
  10. in src/net.cpp:608 in e80330bfc0 outdated
    604@@ -605,12 +605,12 @@ void CNode::CopyStats(CNodeStats& stats)
    605     X(m_bip152_highbandwidth_from);
    606     {
    607         LOCK(cs_vSend);
    608-        X(mapSendBytesPerMsgCmd);
    609+        X(mapSendBytesPerMsg);
    


    w0xlt commented at 9:32 pm on January 24, 2022:
    Shouldn’t mapSendBytesPerMsgCmd be renamed to mapSendBytesPerMsgType?

    shaavan commented at 1:43 pm on January 25, 2022:

    I think this would be a better naming convention for the variables.

    Addressed this and the following comments in 8f31aadd25ad434536ba0d166b81324a18180acb

  11. in src/net.cpp:105 in e80330bfc0 outdated
    101@@ -102,7 +102,7 @@ enum BindFlags {
    102 // The sleep time needs to be small to avoid new sockets stalling
    103 static const uint64_t SELECT_TIMEOUT_MILLISECONDS = 50;
    104 
    105-const std::string NET_MESSAGE_COMMAND_OTHER = "*other*";
    106+const std::string NET_MESSAGE_OTHER = "*other*";
    


    w0xlt commented at 9:32 pm on January 24, 2022:
    Shouldn’t NET_MESSAGE_COMMAND_OTHER be renamed to NET_MESSAGE_TYPE_OTHER?
  12. in src/net.cpp:613 in e80330bfc0 outdated
    610         X(nSendBytes);
    611     }
    612     {
    613         LOCK(cs_vRecv);
    614-        X(mapRecvBytesPerMsgCmd);
    615+        X(mapRecvBytesPerMsg);
    


    w0xlt commented at 9:33 pm on January 24, 2022:
    Shouldn’t mapRecvBytesPerMsgCmd be renamed to mapRecvBytesPerMsgType?
  13. in src/net.h:237 in 7085b8d93e outdated
    232@@ -233,8 +233,8 @@ struct LocalServiceInfo {
    233 extern Mutex g_maplocalhost_mutex;
    234 extern std::map<CNetAddr, LocalServiceInfo> mapLocalHost GUARDED_BY(g_maplocalhost_mutex);
    235 
    236-extern const std::string NET_MESSAGE_COMMAND_OTHER;
    237-typedef std::map<std::string, uint64_t> mapMsgCmdSize; //command, total bytes
    238+extern const std::string NET_MESSAGE_OTHER;
    239+typedef std::map<std::string, uint64_t> mapMsgSize; //command, total bytes
    


    w0xlt commented at 9:35 pm on January 24, 2022:
    Shouldn’t mapMsgCmdSize be renamed to mapMsgTypeSize ?
  14. in src/rpc/net.cpp:253 in e80330bfc0 outdated
    254-        obj.pushKV("bytessent_per_msg", sendPerMsgCmd);
    255+        obj.pushKV("bytessent_per_msg", sendPerMsg);
    256 
    257-        UniValue recvPerMsgCmd(UniValue::VOBJ);
    258-        for (const auto& i : stats.mapRecvBytesPerMsgCmd) {
    259+        UniValue recvPerMsg(UniValue::VOBJ);
    


    w0xlt commented at 9:38 pm on January 24, 2022:
    Shouldn’t recvPerMsgCmd be renamed to recvPerMsgType ?
  15. in src/rpc/net.cpp:246 in e80330bfc0 outdated
    242@@ -243,19 +243,19 @@ static RPCHelpMan getpeerinfo()
    243         obj.pushKV("permissions", permissions);
    244         obj.pushKV("minfeefilter", ValueFromAmount(stats.minFeeFilter));
    245 
    246-        UniValue sendPerMsgCmd(UniValue::VOBJ);
    247-        for (const auto& i : stats.mapSendBytesPerMsgCmd) {
    248+        UniValue sendPerMsg(UniValue::VOBJ);
    


    w0xlt commented at 9:38 pm on January 24, 2022:
    Shouldn’t sendPerMsgCmd be renamed to sendPerMsgType ?
  16. w0xlt commented at 9:38 pm on January 24, 2022: contributor
    Approach ACK
  17. RandyMcMillan commented at 11:29 pm on January 24, 2022: contributor

    After some consideration - I generally agree with @w0xlt - the values held in the string are defined in

    https://github.com/bitcoin/bitcoin/blob/9ec3991ad3b2ae91997c696a4c2f187fe538eff0/src/protocol.h#L64

    &

    https://github.com/bitcoin/bitcoin/blob/9ec3991ad3b2ae91997c696a4c2f187fe538eff0/src/protocol.cpp#L12

    The Cmd part of the naming convention seems to be taken from COMMAND_SIZE originally defined here -> https://github.com/bitcoin/bitcoin/blame/c729dbb6d2b63d9c0b32e3937be0ebf528d4c753/src/protocol.h#L52

  18. DrahtBot commented at 11:49 pm on January 24, 2022: member

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

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #23233 (BIP324: Add encrypted p2p transport {de}serializer by dhruv)

    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.

  19. shaavan force-pushed on Jan 25, 2022
  20. shaavan commented at 1:41 pm on January 25, 2022: contributor

    Updated from e80330b to 8f31aad (pr24141.01 -> pr24141.02) Addressed @hebasto @w0xlt suggestions.

    Changes:

    • Renamed commit message to a scripted-diff message.
    • Renamed variables from message_command -> message_type instead of message_command -> message.

    Thanks, @prusnak and @hebasto, for the scripted-diff example and documentation. And thanks, @RandyMacmillian, for the script message, which I have used as an inspiration for the commit message.

  21. w0xlt approved
  22. w0xlt commented at 2:15 pm on January 28, 2022: contributor

    ACK 8f31aad

    Lint is failing because the changed comments do not match the pattern of the sed command.

    Change the comments in another commit and this CI error will be fixed.

  23. RandyMcMillan commented at 5:52 pm on January 28, 2022: contributor
    @w0xlt - Interesting nuance to scripted diffs - thanks for the insight. 😄 - basically each change needs its own commit in incremental steps.
  24. shaavan commented at 1:17 pm on January 29, 2022: contributor

    Lint is failing because the changed comments do not match the pattern of the sed command.

    Nice catch, @w0xlt! I reckoned the comment change is relatively small and wouldn’t require a separate commit. But let’s keep the lint intact. Let me update the PR with separating comment changes in a new commit.

  25. shaavan force-pushed on Jan 29, 2022
  26. shaavan commented at 5:37 pm on January 29, 2022: contributor

    Updated from 8f31aad to d077901 (pr24141.02 -> pr24141.03) Addressed @w0xlt suggestion.

    Changes:

    • Separated comment changes in a separate commit, allowing lint test to pass successfully on scripted-diff commits.
  27. w0xlt approved
  28. w0xlt commented at 3:31 pm on January 30, 2022: contributor
    reACK d077901
  29. MarcoFalke commented at 4:26 pm on January 30, 2022: member
    Does each commit compile on its own?
  30. shaavan force-pushed on Jan 31, 2022
  31. shaavan commented at 10:32 am on January 31, 2022: contributor

    Updated from d077901 to ec50abf (pr24141.03 -> pr24141.04) Addressed @MarcoFalke comment.

    Changes:

    • Merged scripted diff commits (commit f85a0fca0e41260ac43f6e093b63f49084ba335a and d077901f4d4b4b7e6477ef4326c76aebdeba4a46) together. This was done to make the individual commits compilable.

    Thanks, @MarcoFalke, for catching it.

  32. theStack commented at 12:28 pm on February 2, 2022: member

    Concept ACK

    Some more candidates for the second commit:

     0diff --git a/src/net.cpp b/src/net.cpp
     1index f3ae11ce1..04d9b318d 100644
     2--- a/src/net.cpp
     3+++ b/src/net.cpp
     4@@ -748,7 +748,7 @@ CNetMessage V1TransportDeserializer::GetMessage(const std::chrono::microseconds
     5     // decompose a single CNetMessage from the TransportDeserializer
     6     CNetMessage msg(std::move(vRecv));
     7
     8-    // store command string, time, and sizes
     9+    // store message type string, time, and sizes
    10     msg.m_type = hdr.GetCommand();
    11     msg.m_time = time;
    12     msg.m_message_size = hdr.nMessageSize;
    13@@ -759,7 +759,7 @@ CNetMessage V1TransportDeserializer::GetMessage(const std::chrono::microseconds
    14     // We just received a message off the wire, harvest entropy from the time (and the message checksum)
    15     RandAddEvent(ReadLE32(hash.begin()));
    16
    17-    // Check checksum and header command string
    18+    // Check checksum and header message type string
    19     if (memcmp(hash.begin(), hdr.pchChecksum, CMessageHeader::CHECKSUM_SIZE) != 0) {
    20         LogPrint(BCLog::NET, "Header error: Wrong checksum (%s, %u bytes), expected %s was %s, peer=%d\n",
    21                  SanitizeString(msg.m_type), msg.m_message_size,
    
     0diff --git a/src/net.h b/src/net.h
     1index b1a19bcc4..62d23f6c4 100644
     2--- a/src/net.h
     3+++ b/src/net.h
     4@@ -298,7 +298,7 @@ public:
     5
     6 /** The TransportDeserializer takes care of holding and deserializing the
     7  * network receive buffer. It can deserialize the network buffer into a
     8- * transport protocol agnostic CNetMessage (command & payload)
     9+ * transport protocol agnostic CNetMessage (message type & payload)
    10  */
    11 class TransportDeserializer {
    12 public:
    
     0diff --git a/src/net_processing.cpp b/src/net_processing.cpp
     1index cc23876af..3bcf2d1b1 100644
     2--- a/src/net_processing.cpp
     3+++ b/src/net_processing.cpp
     4@@ -4078,8 +4078,8 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
     5         return;
     6     }
     7
     8-    // Ignore unknown commands for extensibility
     9-    LogPrint(BCLog::NET, "Unknown command \"%s\" from peer=%d\n", SanitizeString(msg_type), pfrom.GetId());
    10+    // Ignore unknown messages types for extensibility
    11+    LogPrint(BCLog::NET, "Unknown message type \"%s\" from peer=%d\n", SanitizeString(msg_type), pfrom.GetId());
    12     return;
    13 }
    

    (Though changing a log message is not a refactor strictly speaking, so not sure if it’s appropriate in this PR.)

  33. shaavan force-pushed on Mar 7, 2022
  34. shaavan commented at 4:35 am on March 7, 2022: contributor

    Updated from https://github.com/bitcoin/bitcoin/commit/ec50abf1d0666706093a004773cbfa5229c6f618 to 15eb7b94965827bb4e1ac11af9fc61fcbf044cd5 (pr24141.04pr24141.05, diff)

    Addressed @theStack comments.

    Included the suggestions suggested by @theStack here.

    About the Log message: I thought about adding it in the 2nd commit, but then I inclined against it for the following reason:

    1. This will not strictly be a refactoring change
    2. This changes a file (net_processing.cpp) untouched in this PR.

    But I think changing the log message would be essential to make it consistent with the other changes done in this PR. So I would require other reviewers’ suggestions on this matter, on whether it is better to edit the log message or not.

  35. shaavan requested review from theStack on Mar 8, 2022
  36. theStack approved
  37. theStack commented at 9:40 am on March 8, 2022: member

    Code-review ACK 15eb7b94965827bb4e1ac11af9fc61fcbf044cd5

    About the Log message: I thought about adding it in the 2nd commit, but then I inclined against it for the following reason:

    1. This will not strictly be a refactoring change
    2. This changes a file (net_processing.cpp) untouched in this PR.

    But I think changing the log message would be essential to make it consistent with the other changes done in this PR. So I would require other reviewers’ suggestions on this matter, on whether it is better to edit the log message or not.

    Probably it could be done with another follow-up (final) PR which replaces the remaining occurences of the “message command” terminology in src/protocol.{h,cpp} and src/net_processing.cpp?

  38. MarcoFalke removed the label RPC/REST/ZMQ on Mar 8, 2022
  39. MarcoFalke removed the label P2P on Mar 8, 2022
  40. MarcoFalke added the label Refactoring on Mar 8, 2022
  41. MarcoFalke commented at 2:26 pm on March 8, 2022: member

    Not sure about the scripted diff. It seems a bit bloated and throws errors (https://cirrus-ci.com/task/6681881558122496?logs=lint#L842). Try something like:

     0    scripted-diff: Rename message command to message type
     1    
     2    -BEGIN VERIFY SCRIPT-
     3    
     4     s1() { sed -i "s/$1/$2/g" $(git grep -l "$1" ./); }
     5    
     6     s1 'NET_MESSAGE_COMMAND_OTHER' 'NET_MESSAGE_TYPE_OTHER'
     7     s1 'mapMsgCmdSize' 'mapMsgTypeSize'
     8     s1 'mapRecvBytesPerMsgCmd' 'mapRecvBytesPerMsgType'
     9     s1 'mapSendBytesPerMsgCmd' 'mapSendBytesPerMsgType'
    10     s1 'recvPerMsgCmd' 'recvPerMsgType'
    11     s1 'sendPerMsgCmd' 'sendPerMsgType'
    12    
    13    -END VERIFY SCRIPT-
    
  42. laanwj commented at 11:25 am on April 6, 2022: member
    Concept ACK
  43. MarcoFalke commented at 11:29 am on April 6, 2022: member
    Are you still working on this? #24141 (comment)
  44. scripted-diff: Rename message command to message type
    -BEGIN VERIFY SCRIPT-
    
     s1() { sed -i "s/$1/$2/g" $(git grep -l "$1" ./); }
    
     s1 'NET_MESSAGE_COMMAND_OTHER' 'NET_MESSAGE_TYPE_OTHER'
     s1 'mapMsgCmdSize' 'mapMsgTypeSize'
     s1 'mapRecvBytesPerMsgCmd' 'mapRecvBytesPerMsgType'
     s1 'mapSendBytesPerMsgCmd' 'mapSendBytesPerMsgType'
     s1 'recvPerMsgCmd' 'recvPerMsgType'
     s1 'sendPerMsgCmd' 'sendPerMsgType'
    
    -END VERIFY SCRIPT-
    2b09593bdd
  45. shaavan force-pushed on Apr 7, 2022
  46. shaavan commented at 12:05 pm on April 7, 2022: contributor

    Updated from pr24141.05pr24141.06

    Changes:

    • Used the scripted-diff commit message as suggested by @MarcoFalke in this comment.

    Thanks, @MarcoFalke, for the script suggestion. Using your suggested script, I resolved the sed: no input files warning. I tried to add you as the Co-author of this commit; however, I could not find your public email ID, so I was unable to do so.

    The current and the last version of the PR are identical (see the diff), except for the script used to create those changes, so I think it should be easy to review this update.

  47. in src/net.h:237 in 07ecabf738 outdated
    232@@ -233,8 +233,8 @@ struct LocalServiceInfo {
    233 extern Mutex g_maplocalhost_mutex;
    234 extern std::map<CNetAddr, LocalServiceInfo> mapLocalHost GUARDED_BY(g_maplocalhost_mutex);
    235 
    236-extern const std::string NET_MESSAGE_COMMAND_OTHER;
    237-typedef std::map<std::string, uint64_t> mapMsgCmdSize; //command, total bytes
    238+extern const std::string NET_MESSAGE_TYPE_OTHER;
    239+typedef std::map<std::string, uint64_t> mapMsgTypeSize; //message, total bytes
    


    MarcoFalke commented at 12:15 pm on April 7, 2022:

    nit: Second commit s/message/message type/. Or:

    0using mapMsgTypeSize = std::map</* msg type */ std::string, /* total bytes */ uint64_t>;
    

    shaavan commented at 11:57 am on April 8, 2022:

    Thanks, @MarcoFalke, for taking another look. As per your suggestion, I was able to identify one more place in the second commit where your suggestion could be implemented.

    0-            // to prevent a memory DOS, only allow valid commands
    1+            // to prevent a memory DOS, only allow valid messages
    

    But I opted against changing the above from messages to message types, as that would have decreased the sentence’s logical soundness IMO.

  48. MarcoFalke approved
  49. MarcoFalke commented at 12:15 pm on April 7, 2022: member
    ACK
  50. shaavan force-pushed on Apr 8, 2022
  51. shaavan commented at 11:53 am on April 8, 2022: contributor

    Updated from pr24141.06pr24141.07

    Addressed @MarcoFalke suggestion.

    Changes:

    • Replaced usage of typedef with using in defining mapMsgTypeSize.
    • Replaced message with message type in the comment defining the above.
  52. in src/net.cpp:661 in 26b7f9f83c outdated
    659             }
    660 
    661-            // Store received bytes per message command
    662-            // to prevent a memory DOS, only allow valid commands
    663+            // Store received bytes per message type
    664+            // to prevent a memory DOS, only allow valid messages
    


    MarcoFalke commented at 12:26 pm on April 8, 2022:

    I think this should say “known message types”?

    For example, a reject message might be valid according to BIP 61, but the type is unknown to this version of Bitcoin Core.


    shaavan commented at 11:20 am on April 16, 2022:
    Thanks for seeing it. I think you are right. Using “known message types” would be a better wording for this sentence. Let me address it by updating the second commit.
  53. jonatack commented at 12:41 pm on April 8, 2022: member
    Approach ACK
  54. refactor: rename command -> message type in comments in the src/net* files
    Co-authored-by: Sebastian Falbesoner <sebastian.falbesoner@gmail.com>
    e71c51b27d
  55. shaavan force-pushed on Apr 16, 2022
  56. shaavan commented at 11:37 am on April 16, 2022: contributor

    Update from pr24141.07pr24141.08, diff

    Addressed suggestion by @MarcoFalke

    Changes:

    • Change the wording of the comment from “allow valid messages” to “allow known message types” as some of the messages (like reject, as pointed out by @MarcoFalke, may be valid but yet unknown to the current version of bitcoin core)
    • Also did some punctuation corrections to make the comment grammatically sound.
  57. MarcoFalke approved
  58. MarcoFalke commented at 6:37 am on May 5, 2022: member

    review ACK e71c51b27d420fbd6cc0a36f62e63e190e13473a 💥

    Signature:

     0-----BEGIN PGP SIGNED MESSAGE-----
     1Hash: SHA512
     2
     3review ACK e71c51b27d420fbd6cc0a36f62e63e190e13473a 💥
     4-----BEGIN PGP SIGNATURE-----
     5
     6iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
     7pUhJ/Qv+KgTz8htAqBuJ6FnTHQdjyLswJvYHXukDceneF5E72Gifx7MaJw439PKt
     8MjVpE6s1VCZIliOhSojkNrINaL07pLQu+MoDNSkdOHexfm6xlsDg29nBdba0ocLq
     9meTNnDW+f+uUibpz+6NxY7Fur8YIpyz+Ney8X0EkOa73F01Dcy9rjAzRZRjCI/gk
    10X9i7kWzByG7uTzAAvuNxV+F1Kg1qVX2GgMOtxmYj+qpbx2kVCd7YA2pUjYbLeuPL
    119/SWmNdYnjFPznUUhby0HcSY0wwZ5urKIhWPgVeXpQgnQJu4WCNYum+ckBIThhor
    12uS1IkAtylgZfwcEU4m8unW4dUoQkeCFyN8xVSsQztL1TinM3CmzKnsgZq1LkU2El
    13i1HTy5qxZCybGh2y3R/bUuygFelDw9PZY2Qm/AtvCaf1rsowGAG6Xq0gAsKwON9V
    14co1M/Qgh9fbizx5PJx3uIWRM3SwD0QEojRkLSikmnwdrc08OA2Eo3zN9kNzfpDaS
    15CfbI81Qr
    16=u23E
    17-----END PGP SIGNATURE-----
    
  59. MarcoFalke merged this on May 5, 2022
  60. MarcoFalke closed this on May 5, 2022

  61. sidhujag referenced this in commit aebd7a230d on May 5, 2022
  62. DrahtBot locked this on May 5, 2023

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-10-30 00:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me