-
Notifications
You must be signed in to change notification settings - Fork 411
Making message size limit an exportable constant #623
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
Conversation
concept ACK :) i don't know the code base well enough to give actual ACK although it looks right to me |
Codecov Report
@@ Coverage Diff @@
## master #623 +/- ##
========================================
Coverage 91.26% 91.26%
========================================
Files 35 35
Lines 21229 20787 -442
========================================
- Hits 19375 18972 -403
+ Misses 1854 1815 -39
Continue to review full report at Codecov.
|
lightning/src/ln/wire.rs
Outdated
@@ -16,6 +16,13 @@ | |||
use ln::msgs; | |||
use util::ser::{Readable, Writeable, Writer}; | |||
|
|||
/// Maximum Lightning message data length according to | |||
/// [BOLT-8](https://github.com/lightningnetwork/lightning-rfc/blob/v1.0/08-transport.md#lightning-message-specification): | |||
/// "The maximum size of any Lightning message MUST NOT exceed 65535 bytes. |
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.
Not sure the quote adds much value, but it takes readers' attention.
Keeping a number is also not useful, because it's already in the field.
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.
You mean quotation marks or the quoted text?
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.
I mean the text. I think it's enough to say:
" /// Maximum Lightning message data length according to BOLT-8"
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.
I've used spec referencing model from c-lightning, where they directly cite a part of the spec right in the code — and it works really good for code reading
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.
Never read c-lightning, but big files generally want me to close the tab all the time. And this seems like a path to get there. Maybe you are right.
Anyway, I don't have the energy to argue about this, feel free to do whatever :)
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.
The counter argument is that the spec changes, so quoting it can lead to the code comment getting out of sync with the spec as it evolves. It is also mentioned in BOLT 1:
The size of the message is required by the transport layer to fit into a 2-byte unsigned int; therefore, the maximum possible size is 65535 bytes.
My preference would be to reference the spec but leave out the quote.
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.
In general, we tend to never quote the spec - the spec can be confusing, and docs should be self-contained - users should be able to read them and figure out what's going on without having to flip to another reference.
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.
Done
@@ -373,7 +374,7 @@ impl PeerChannelEncryptor { | |||
/// Encrypts the given message, returning the encrypted version | |||
/// panics if msg.len() > 65535 or Noise handshake has not finished. |
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.
You deliberately leave "65535" in the comments or you just missed it? I actually don't know what is better. Probably you're right and the number works fine for a doc reader.
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.
Deliberately. Constant is unreadable in text, you have to look up for the value; while integer literal allow to check what value the constant must have and understand on which conditions the code will fail.
lightning/src/ln/wire.rs
Outdated
@@ -16,6 +16,13 @@ | |||
use ln::msgs; | |||
use util::ser::{Readable, Writeable, Writer}; | |||
|
|||
/// Maximum Lightning message data length according to | |||
/// [BOLT-8](https://github.com/lightningnetwork/lightning-rfc/blob/v1.0/08-transport.md#lightning-message-specification): |
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.
I mean, its more because the length is encoded with two bytes than because the spec says so :p.
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.
or the spec uses two byte length encoding to enforce the message size limitation :)
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.
Done
lightning/src/ln/wire.rs
Outdated
@@ -16,6 +16,13 @@ | |||
use ln::msgs; | |||
use util::ser::{Readable, Writeable, Writer}; | |||
|
|||
/// Maximum Lightning message data length according to | |||
/// [BOLT-8](https://github.com/lightningnetwork/lightning-rfc/blob/v1.0/08-transport.md#lightning-message-specification): | |||
/// "The maximum size of any Lightning message MUST NOT exceed 65535 bytes. |
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.
The counter argument is that the spec changes, so quoting it can lead to the code comment getting out of sync with the spec as it evolves. It is also mentioned in BOLT 1:
The size of the message is required by the transport layer to fit into a 2-byte unsigned int; therefore, the maximum possible size is 65535 bytes.
My preference would be to reference the spec but leave out the quote.
lightning/src/ln/wire.rs
Outdated
/// "The maximum size of any Lightning message MUST NOT exceed 65535 bytes. | ||
/// A maximum size of 65535 simplifies testing, makes memory management easier, | ||
/// and helps mitigate memory-exhaustion attacks." | ||
pub const LN_MAX_MSG_LEN: usize = 65535; |
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.
Given the spec references the transport layer, would it be more appropriate to define this constant there (i.e. where it is used)? Especially given #494 refactors that code but seems to have missed this restriction. It would be easily caught if defined there, IMHO. It may have not been caught in the review since the old code has not (yet) been removed in that PR.
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.
Done
lightning/src/ln/wire.rs
Outdated
/// "The maximum size of any Lightning message MUST NOT exceed 65535 bytes. | ||
/// A maximum size of 65535 simplifies testing, makes memory management easier, | ||
/// and helps mitigate memory-exhaustion attacks." | ||
pub const LN_MAX_MSG_LEN: usize = 65535; |
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.
Could we simply use std::u16::MAX
given the intention given in BOLT 1?
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.
I agree, it makes more sense to define the constant here. 65535
is more convenient to the reader though, so perhaps just std::u16::MAX; // 65535
for optimal legibility
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.
Done
72d1b37
to
f186ae8
Compare
With new force-push I have matched all questions, rebased to the current master, added test cases + fixed some of the issues with the existing panic messages and test cases, related to message encryption/decryption. Each of these changes is done as a separate commit to make review easier. |
f10e46a
to
a4c92dc
Compare
90d2c3a
to
fc74130
Compare
fc74130
to
4bb5955
Compare
Thanks! |
It's always better to have all magic numbers defined in specs in form of global constants rather than in-code literals