Skip to content

Commit 7869de2

Browse files
committed
f: Improve comment & introduce debug_assert!()
1 parent 811dd78 commit 7869de2

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

lightning/src/blinded_path/utils.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,24 +179,25 @@ impl Writeable for Padding {
179179
}
180180

181181

182-
/// A wrapper struct that stores the largest packet size for the given [`BlindedPath`].
182+
/// A wrapper struct that stores the largest packet size for a [`BlindedPath`].
183183
/// This helps us calculate the appropriate padding size for the tlvs when writing them.
184-
pub struct WithPadding<T: Writeable> {
184+
pub(super) struct WithPadding<T: Writeable> {
185185
/// Length of the packet with the largest size in the [`BlindedPath`].
186-
pub(crate) max_length: usize,
186+
pub(super) max_length: usize,
187187
/// The current packet's TLVs.
188-
pub(crate) tlvs: T,
188+
pub(super) tlvs: T,
189189
}
190190

191191
impl<T: Writeable> Writeable for WithPadding<T> {
192192
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
193-
let length = self.max_length.saturating_sub(self.tlvs.serialized_length());
194-
let padding = Some(Padding::new(length));
193+
let length = self.max_length.checked_sub(self.tlvs.serialized_length());
194+
debug_assert!(length.is_some(), "Size of this packet should not be larger than the size of largest packet.");
195+
let padding = Some(Padding::new(length.unwrap()));
195196

196197
encode_tlv_stream!(writer, {
197198
(1, padding, option)
198199
});
199200

200201
self.tlvs.write(writer)
201202
}
202-
}
203+
}

0 commit comments

Comments
 (0)