Skip to content

Conversation

shaavan
Copy link
Contributor

@shaavan shaavan commented Jan 24, 2022

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.

@hebasto
Copy link
Member

hebasto commented Jan 24, 2022

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

@prusnak
Copy link
Contributor

prusnak commented Jan 24, 2022

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: eb04bad

@hebasto
Copy link
Member

hebasto commented Jan 24, 2022

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

Another example -- c4a31ca -- with git grep --files-with-matches usage.

@RandyMcMillan
Copy link
Contributor

RandyMcMillan commented Jan 24, 2022

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

#!/bin/bash -e

function s1() { git grep -l "$1" src/net* | xargs sed -i .old "s/$1/$2/g"; }

 s1 'mapSendBytesPerMsgCmd' 'mapSendBytesPerMsg'
 s1 'NET_MESSAGE_COMMAND_OTHER' 'NET_MESSAGE_OTHER'
 s1 'mapRecvBytesPerMsgCmd' 'mapRecvBytesPerMsg'
 s1 'mapMsgCmdSize' 'mapMsgSize'
 s1 'sendPerMsgCmd' 'sendPerMsg'
 s1 'mapSendBytesPerMsgCmd' 'mapSendBytesPerMsg'
 s1 'recvPerMsgCmd' 'recvPerMsg'

function s2() { git grep -l "$1" src/rpc/net* | xargs sed -i .old "s/$1/$2/g"; }

 s2 'mapSendBytesPerMsgCmd' 'mapSendBytesPerMsg'
 s2 'NET_MESSAGE_COMMAND_OTHER' 'NET_MESSAGE_OTHER'
 s2 'mapRecvBytesPerMsgCmd' 'mapRecvBytesPerMsg'
 s2 'mapMsgCmdSize' 'mapMsgSize'
 s2 'sendPerMsgCmd' 'sendPerMsg'
 s2 'mapSendBytesPerMsgCmd' 'mapSendBytesPerMsg'
 s2 'recvPerMsgCmd' 'recvPerMsg'

@RandyMcMillan
Copy link
Contributor

Concept ACK

Copy link
Contributor

@w0xlt w0xlt left a comment

Choose a reason for hiding this comment

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

Approach ACK

src/net.cpp Outdated
@@ -102,7 +102,7 @@ enum BindFlags {
// The sleep time needs to be small to avoid new sockets stalling
static const uint64_t SELECT_TIMEOUT_MILLISECONDS = 50;

const std::string NET_MESSAGE_COMMAND_OTHER = "*other*";
const std::string NET_MESSAGE_OTHER = "*other*";
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't NET_MESSAGE_COMMAND_OTHER be renamed to NET_MESSAGE_TYPE_OTHER?

@RandyMcMillan
Copy link
Contributor

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

namespace NetMsgType {

&

namespace NetMsgType {

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

@DrahtBot
Copy link
Contributor

DrahtBot commented Jan 24, 2022

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.

@shaavan
Copy link
Contributor Author

shaavan commented Jan 25, 2022

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.

Copy link
Contributor

@w0xlt w0xlt left a comment

Choose a reason for hiding this comment

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

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.

@RandyMcMillan
Copy link
Contributor

@w0xlt - Interesting nuance to scripted diffs - thanks for the insight. 😄 - basically each change needs its own commit in incremental steps.

@shaavan
Copy link
Contributor Author

shaavan commented Jan 29, 2022

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.

@shaavan
Copy link
Contributor Author

shaavan commented Jan 29, 2022

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.

Copy link
Contributor

@w0xlt w0xlt left a comment

Choose a reason for hiding this comment

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

reACK d077901

@maflcko
Copy link
Member

maflcko commented Jan 30, 2022

Does each commit compile on its own?

@shaavan
Copy link
Contributor Author

shaavan commented Jan 31, 2022

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

Changes:

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

Thanks, @MarcoFalke, for catching it.

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

Some more candidates for the second commit:

diff --git a/src/net.cpp b/src/net.cpp
index f3ae11ce1..04d9b318d 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -748,7 +748,7 @@ CNetMessage V1TransportDeserializer::GetMessage(const std::chrono::microseconds
     // decompose a single CNetMessage from the TransportDeserializer
     CNetMessage msg(std::move(vRecv));

-    // store command string, time, and sizes
+    // store message type string, time, and sizes
     msg.m_type = hdr.GetCommand();
     msg.m_time = time;
     msg.m_message_size = hdr.nMessageSize;
@@ -759,7 +759,7 @@ CNetMessage V1TransportDeserializer::GetMessage(const std::chrono::microseconds
     // We just received a message off the wire, harvest entropy from the time (and the message checksum)
     RandAddEvent(ReadLE32(hash.begin()));

-    // Check checksum and header command string
+    // Check checksum and header message type string
     if (memcmp(hash.begin(), hdr.pchChecksum, CMessageHeader::CHECKSUM_SIZE) != 0) {
         LogPrint(BCLog::NET, "Header error: Wrong checksum (%s, %u bytes), expected %s was %s, peer=%d\n",
                  SanitizeString(msg.m_type), msg.m_message_size,
diff --git a/src/net.h b/src/net.h
index b1a19bcc4..62d23f6c4 100644
--- a/src/net.h
+++ b/src/net.h
@@ -298,7 +298,7 @@ public:

 /** The TransportDeserializer takes care of holding and deserializing the
  * network receive buffer. It can deserialize the network buffer into a
- * transport protocol agnostic CNetMessage (command & payload)
+ * transport protocol agnostic CNetMessage (message type & payload)
  */
 class TransportDeserializer {
 public:
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index cc23876af..3bcf2d1b1 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -4078,8 +4078,8 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
         return;
     }

-    // Ignore unknown commands for extensibility
-    LogPrint(BCLog::NET, "Unknown command \"%s\" from peer=%d\n", SanitizeString(msg_type), pfrom.GetId());
+    // Ignore unknown messages types for extensibility
+    LogPrint(BCLog::NET, "Unknown message type \"%s\" from peer=%d\n", SanitizeString(msg_type), pfrom.GetId());
     return;
 }

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

@shaavan
Copy link
Contributor Author

shaavan commented Mar 7, 2022

Updated from ec50abf to 15eb7b9 (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.

@shaavan shaavan requested a review from theStack March 8, 2022 07:49
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.

Code-review ACK 15eb7b9

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?

@maflcko
Copy link
Member

maflcko commented Mar 8, 2022

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:

    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-

@laanwj
Copy link
Member

laanwj commented Apr 6, 2022

Concept ACK

@maflcko
Copy link
Member

maflcko commented Apr 6, 2022

Are you still working on this? #24141 (comment)

-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-
@shaavan
Copy link
Contributor Author

shaavan commented Apr 7, 2022

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.

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.

ACK

src/net.h Outdated
extern const std::string NET_MESSAGE_COMMAND_OTHER;
typedef std::map<std::string, uint64_t> mapMsgCmdSize; //command, total bytes
extern const std::string NET_MESSAGE_TYPE_OTHER;
typedef std::map<std::string, uint64_t> mapMsgTypeSize; //message, total bytes
Copy link
Member

Choose a reason for hiding this comment

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

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

Suggested change
typedef std::map<std::string, uint64_t> mapMsgTypeSize; //message, total bytes
using mapMsgTypeSize = std::map</* msg type */ std::string, /* total bytes */ uint64_t>;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

-            // to prevent a memory DOS, only allow valid commands
+            // 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.

@shaavan
Copy link
Contributor Author

shaavan commented Apr 8, 2022

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.

src/net.cpp Outdated
// Store received bytes per message command
// to prevent a memory DOS, only allow valid commands
// Store received bytes per message type
// to prevent a memory DOS, only allow valid messages
Copy link
Member

@maflcko maflcko Apr 8, 2022

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

@jonatack
Copy link
Member

jonatack commented Apr 8, 2022

Approach ACK

…files

Co-authored-by: Sebastian Falbesoner <sebastian.falbesoner@gmail.com>
@shaavan
Copy link
Contributor Author

shaavan commented Apr 16, 2022

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.

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 e71c51b 💥

Show signature

Signature:

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

review ACK e71c51b27d420fbd6cc0a36f62e63e190e13473a 💥
-----BEGIN PGP SIGNATURE-----

iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUhJ/Qv+KgTz8htAqBuJ6FnTHQdjyLswJvYHXukDceneF5E72Gifx7MaJw439PKt
MjVpE6s1VCZIliOhSojkNrINaL07pLQu+MoDNSkdOHexfm6xlsDg29nBdba0ocLq
meTNnDW+f+uUibpz+6NxY7Fur8YIpyz+Ney8X0EkOa73F01Dcy9rjAzRZRjCI/gk
X9i7kWzByG7uTzAAvuNxV+F1Kg1qVX2GgMOtxmYj+qpbx2kVCd7YA2pUjYbLeuPL
9/SWmNdYnjFPznUUhby0HcSY0wwZ5urKIhWPgVeXpQgnQJu4WCNYum+ckBIThhor
uS1IkAtylgZfwcEU4m8unW4dUoQkeCFyN8xVSsQztL1TinM3CmzKnsgZq1LkU2El
i1HTy5qxZCybGh2y3R/bUuygFelDw9PZY2Qm/AtvCaf1rsowGAG6Xq0gAsKwON9V
co1M/Qgh9fbizx5PJx3uIWRM3SwD0QEojRkLSikmnwdrc08OA2Eo3zN9kNzfpDaS
CfbI81Qr
=u23E
-----END PGP SIGNATURE-----

@maflcko maflcko merged commit 0d080a1 into bitcoin:master May 5, 2022
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request May 5, 2022
… src/rpc/net.cpp

e71c51b refactor: rename command -> message type in comments in the src/net* files (Shashwat)
2b09593 scripted-diff: Rename message command to message type (Shashwat)

Pull request description:

  This PR is a follow-up to bitcoin#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 bitcoin#24078 and does similar changes in the `src/rpc/net.cpp` file.

ACKs for top commit:
  MarcoFalke:
    review ACK e71c51b 💥

Tree-SHA512: 24015d132c00f15239e5d3dc7aedae904ae3103a90920bb09e984ff57723402763f697d886322f78e42a0cb46808cb6bc9d4905561dc6ddee9961168f8324b05
@bitcoin bitcoin locked and limited conversation to collaborators May 5, 2023
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.

10 participants