Skip to content
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

Merged
merged 3 commits into from
Oct 15, 2016

Conversation

laanwj
Copy link
Member

@laanwj laanwj commented Oct 4, 2016

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

laanwj added 2 commits October 4, 2016 11:11
Also move the enum to the top, and remove a deceptive TODO
comment.
Copy link
Contributor

@dcousens dcousens left a comment

Choose a reason for hiding this comment

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

utACK

@sipa
Copy link
Member

sipa commented Oct 4, 2016

utACK

@@ -48,17 +56,6 @@ class CMessageHeader
READWRITE(FLATDATA(pchChecksum));
}

// TODO: make private (improves encapsulation)
Copy link
Contributor

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?

Copy link
Member Author

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).

@paveljanik
Copy link
Contributor

utACK

1 similar comment
@btcdrak
Copy link
Contributor

btcdrak commented Oct 4, 2016

utACK

@@ -29,6 +27,16 @@
class CMessageHeader
{
public:
enum {
MESSAGE_START_SIZE = 4,
Copy link
Member

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.

@theuni
Copy link
Member

theuni commented Oct 4, 2016

utACK 2c09a52

@@ -29,6 +27,16 @@
class CMessageHeader
{
public:
enum {
MESSAGE_START_SIZE = 4,
Copy link
Member Author

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.

Copy link
Member Author

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?

Copy link
Member

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.

@laanwj
Copy link
Member Author

laanwj commented Oct 4, 2016

Added another commit:

  • protocol.h: Make enums in GetDataMsg concrete values: 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 MSG_CMPCT_BLOCK enum value is already in use #8500).

MSG_TX,
MSG_BLOCK,
MSG_TX = 1,
MSG_BLOCK = 2,
MSG_TYPE_MAX = MSG_BLOCK,
Copy link
Contributor

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...

Copy link
Member Author

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).
@laanwj
Copy link
Member Author

laanwj commented Oct 5, 2016

Got rid of the awkward MSG_TYPE_MAX leftover in between the enum values (and squashed). Thanks @paveljanik for noticing.

@sipa
Copy link
Member

sipa commented Oct 5, 2016 via email

@laanwj
Copy link
Member Author

laanwj commented Oct 5, 2016

The MSG_TYPE_MAX is a leftover from earlier code that got refactored in thesegwit PR.

OK, in historical context it makes sense, it just looks weird now.

Copy link
Contributor

@jonasschnelli jonasschnelli left a comment

Choose a reason for hiding this comment

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

utACK 1df3111

Copy link
Contributor

@paveljanik paveljanik left a comment

Choose a reason for hiding this comment

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

ACK 1df3111

@laanwj laanwj merged commit 1df3111 into bitcoin:master Oct 15, 2016
laanwj added a commit that referenced this pull request Oct 15, 2016
1df3111 protocol.h: Make enums in GetDataMsg concrete values (Wladimir J. van der Laan)
2c09a52 protocol.h: Move MESSAGE_START_SIZE into CMessageHeader (Wladimir J. van der Laan)
f9bd92d version.h: s/shord/short/ in comment (Wladimir J. van der Laan)
codablock pushed a commit to codablock/dash that referenced this pull request Jan 12, 2018
…Header

1df3111 protocol.h: Make enums in GetDataMsg concrete values (Wladimir J. van der Laan)
2c09a52 protocol.h: Move MESSAGE_START_SIZE into CMessageHeader (Wladimir J. van der Laan)
f9bd92d version.h: s/shord/short/ in comment (Wladimir J. van der Laan)
hypo-test pushed a commit to hypo-test/BitcoinBips-713993353 that referenced this pull request Nov 25, 2018
andvgal pushed a commit to energicryptocurrency/gen2-energi that referenced this pull request Jan 6, 2019
…Header

1df3111 protocol.h: Make enums in GetDataMsg concrete values (Wladimir J. van der Laan)
2c09a52 protocol.h: Move MESSAGE_START_SIZE into CMessageHeader (Wladimir J. van der Laan)
f9bd92d version.h: s/shord/short/ in comment (Wladimir J. van der Laan)
zkbot added a commit to zcash/zcash that referenced this pull request Aug 17, 2021
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
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
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.

7 participants