-
Notifications
You must be signed in to change notification settings - Fork 36.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
protocol.h: Move MESSAGE_START_SIZE into CMessageHeader #8880
Conversation
Also move the enum to the top, and remove a deceptive TODO comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK
utACK |
@@ -48,17 +56,6 @@ class CMessageHeader | |||
READWRITE(FLATDATA(pchChecksum)); | |||
} | |||
|
|||
// TODO: make private (improves encapsulation) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment removed. Is it OK?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See OP
and remove a deceptive TODO comment (this is just a dumb data structure describing the protocol and there's nothing to be gained from encapsulation at that level).
utACK |
1 similar comment
utACK |
@@ -29,6 +27,16 @@ | |||
class CMessageHeader | |||
{ | |||
public: | |||
enum { | |||
MESSAGE_START_SIZE = 4, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: could make these constexprs instead while we're at it. No real reason other than cosmetic, though.
utACK 2c09a52 |
@@ -29,6 +27,16 @@ | |||
class CMessageHeader | |||
{ | |||
public: | |||
enum { | |||
MESSAGE_START_SIZE = 4, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh yes now I look at it again using an enum here is a somewhat of a strange use of the C++ language.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though it looks like we use this kind of constant declaration in many places, and so does leveldb:
arith_uint256.h: enum { WIDTH=BITS/32 };
chain.h: enum { nMedianTimeSpan=11 };
leveldb/db/skiplist.h: enum { kMaxHeight = 12 };
leveldb/helpers/memenv/memenv.cc: enum { kBlockSize = 8 * 1024 };
...
So I suppose it's somewhat acceptable in some cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@laanwj Looks like several of those are hold-overs from c++03. In the case where there's no actual grouping and we're just using them as constants, I think constexpr's would be fine, but the enum is ofc acceptable as well.
Nevermind for here, we can discuss in a separate style guide PR.
Added another commit:
|
463786a
to
f5d3f0f
Compare
MSG_TX, | ||
MSG_BLOCK, | ||
MSG_TX = 1, | ||
MSG_BLOCK = 2, | ||
MSG_TYPE_MAX = MSG_BLOCK, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MSG_TYPE_MAX is not used at all in the sources and looks strange in the middle...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HUH. That's a good catch. How could I have missed that one.
This concretizes the numbers and adds a comment to make it clear that these numbers are fixed by the protocol, and may avoid people forgetting to claim numbers in the future (e.g. issue bitcoin#8500). Also gets rid of a weird unused `MSG_TYPE_MAX` in the middle of the enumeration (thanks @paveljanik for noticing).
f5d3f0f
to
1df3111
Compare
Got rid of the awkward MSG_TYPE_MAX leftover in between the enum values (and squashed). Thanks @paveljanik for noticing. |
The MSG_TYPE_MAX is a leftover from earlier code that got refactored in the
segwit PR. It delimited the maximum msg type that could be seen in an inv
(as opposed to the next ones, which can only be seen in getdata).
|
OK, in historical context it makes sense, it just looks weird now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK 1df3111
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 1df3111
…TNESS_BLOCK Found these missing while working on bitcoin/bitcoin#8880 .
ZIP 239 preparations 3 Cherry-picked from the following upstream PRs: - bitcoin/bitcoin#8080 - bitcoin/bitcoin#8082 - bitcoin/bitcoin#8126 - bitcoin/bitcoin#7910 - This is the unsquashed version of bitcoin/bitcoin#8149 - We take three cleanup commits to the protocol / `CInv` code. - bitcoin/bitcoin#8822 - bitcoin/bitcoin#8880 - Excluding the first commit (we don't have the comment it fixes yet). - bitcoin/bitcoin#19322
This moves all the header sizes together. Also move the enum to the top, and remove a deceptive TODO comment (this is just a dumb data structure describing the protocol and there's nothing to be gained from encapsulation at that level).
Other commit fixes a silly typo in
version.h