Skip to content

Commit c45c3a7

Browse files
committed
Use constant for buffer size in OM functional_tests.rs
In 3c3e93e we ran rustfmt blindly on `lightning/src/onion_message/functional_tests.rs`. This left the file with a handful of warts that really should have been cleaned up as we went. Here we take the opportunity to clean up the `peer_buffer_full` test which used a constant for the number of messages we can push before the buffer fills, rather than calculating the amount based on the buffer size constant, also removing a comment that got moved by rustfmt into a place where it was no longer understandable.
1 parent f8a5ef5 commit c45c3a7

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

lightning/src/onion_message/functional_tests.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -765,8 +765,7 @@ fn peer_buffer_full() {
765765
let destination = Destination::Node(nodes[1].node_id);
766766
let instructions = MessageSendInstructions::WithoutReplyPath { destination };
767767

768-
for _ in 0..188 {
769-
// Based on MAX_PER_PEER_BUFFER_SIZE in OnionMessenger
768+
for _ in 0..super::messenger::MAX_PER_PEER_BUFFER_SIZE / 1401 + 1 {
770769
nodes[0].messenger.send_onion_message(test_msg.clone(), instructions.clone()).unwrap();
771770
}
772771
let err = nodes[0].messenger.send_onion_message(test_msg, instructions.clone()).unwrap_err();

lightning/src/onion_message/messenger.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,11 +1661,12 @@ where
16611661
}
16621662
}
16631663

1664+
const MAX_TOTAL_BUFFER_SIZE: usize = (1 << 20) * 128;
1665+
pub(super) const MAX_PER_PEER_BUFFER_SIZE: usize = (1 << 10) * 256;
1666+
16641667
fn outbound_buffer_full(
16651668
peer_node_id: &PublicKey, buffer: &HashMap<PublicKey, OnionMessageRecipient>,
16661669
) -> bool {
1667-
const MAX_TOTAL_BUFFER_SIZE: usize = (1 << 20) * 128;
1668-
const MAX_PER_PEER_BUFFER_SIZE: usize = (1 << 10) * 256;
16691670
let mut total_buffered_bytes = 0;
16701671
let mut peer_buffered_bytes = 0;
16711672
for (pk, peer_buf) in buffer {

0 commit comments

Comments
 (0)