Skip to content

Commit 4bb5955

Browse files
committed
Moving LN_MAX_MSG_LEN const to the actual use place
1 parent 0e5dfad commit 4bb5955

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

lightning/src/ln/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ mod chanmon_update_fail_tests;
3636
#[cfg(test)]
3737
mod reorg_tests;
3838

39-
pub use self::wire::LN_MAX_MSG_LEN;
39+
pub use self::peer_channel_encryptor::LN_MAX_MSG_LEN;

lightning/src/ln/peer_channel_encryptor.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use ln::msgs::LightningError;
22
use ln::msgs;
3-
use ln::wire::LN_MAX_MSG_LEN;
43

54
use bitcoin::hashes::{Hash, HashEngine, Hmac, HmacEngine};
65
use bitcoin::hashes::sha256::Hash as Sha256;
@@ -13,6 +12,11 @@ use bitcoin::secp256k1;
1312
use util::chacha20poly1305rfc::ChaCha20Poly1305RFC;
1413
use util::byte_utils;
1514

15+
/// Maximum Lightning message data length according to
16+
/// [BOLT-8](https://github.com/lightningnetwork/lightning-rfc/blob/v1.0/08-transport.md#lightning-message-specification)
17+
/// and [BOLT-1](https://github.com/lightningnetwork/lightning-rfc/blob/master/01-messaging.md#lightning-message-format):
18+
pub const LN_MAX_MSG_LEN: usize = ::std::u16::MAX as usize; // Must be equal to 65535
19+
1620
// Sha256("Noise_XK_secp256k1_ChaChaPoly_SHA256")
1721
const NOISE_CK: [u8; 32] = [0x26, 0x40, 0xf5, 0x2e, 0xeb, 0xcd, 0x9e, 0x88, 0x29, 0x58, 0x95, 0x1c, 0x79, 0x42, 0x50, 0xee, 0xdb, 0x28, 0x00, 0x2c, 0x05, 0xd7, 0xdc, 0x2e, 0xa0, 0xf1, 0x95, 0x40, 0x60, 0x42, 0xca, 0xf1];
1822
// Sha256(NOISE_CK || "lightning")
@@ -698,6 +702,12 @@ mod tests {
698702
}
699703
}
700704

705+
#[test]
706+
fn max_msg_len_limit_value() {
707+
assert_eq!(LN_MAX_MSG_LEN, 65535);
708+
assert_eq!(LN_MAX_MSG_LEN, ::std::u16::MAX as usize);
709+
}
710+
701711
#[test]
702712
#[should_panic(expected = "Attempted to encrypt message longer than 65535 bytes!")]
703713
fn max_message_len_encryption() {

lightning/src/ln/wire.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@
1616
use ln::msgs;
1717
use util::ser::{Readable, Writeable, Writer};
1818

19-
/// Maximum Lightning message data length according to
20-
/// [BOLT-8](https://github.com/lightningnetwork/lightning-rfc/blob/v1.0/08-transport.md#lightning-message-specification)
21-
/// and [BOLT-1](https://github.com/lightningnetwork/lightning-rfc/blob/master/01-messaging.md#lightning-message-format):
22-
pub const LN_MAX_MSG_LEN: usize = std::u16::MAX as usize; // Must be equal to 65535
23-
2419
/// A Lightning message returned by [`read`] when decoding bytes received over the wire. Each
2520
/// variant contains a message from [`ln::msgs`] or otherwise the message type if unknown.
2621
///
@@ -316,12 +311,6 @@ mod tests {
316311
// Big-endian wire encoding of Pong message (type = 19, byteslen = 2).
317312
const ENCODED_PONG: [u8; 6] = [0u8, 19u8, 0u8, 2u8, 0u8, 0u8];
318313

319-
#[test]
320-
fn max_msg_len() {
321-
assert_eq!(LN_MAX_MSG_LEN, 65535);
322-
assert_eq!(LN_MAX_MSG_LEN, std::u16::MAX as usize);
323-
}
324-
325314
#[test]
326315
fn read_empty_buffer() {
327316
let buffer = [];

0 commit comments

Comments
 (0)