Skip to content

Commit 2318caf

Browse files
committed
f: Introduce TLV_OVERHEAD
1 parent d613d02 commit 2318caf

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

lightning/src/blinded_path/utils.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,12 @@ impl Writeable for BlindedPathPadding {
229229
}
230230
}
231231

232+
/// Padding storage requires two extra bytes:
233+
/// - One byte for the type.
234+
/// - One byte for the padding length.
235+
/// This constant accounts for that overhead.
236+
const TLV_OVERHEAD: usize = 2;
237+
232238
/// A generic struct that applies padding to blinded path TLVs, rounding their size off to `round_off`
233239
pub(crate) struct BlindedPathWithPadding<T: Writeable> {
234240
pub(crate) tlvs: T,
@@ -237,11 +243,13 @@ pub(crate) struct BlindedPathWithPadding<T: Writeable> {
237243

238244
impl<T: Writeable> Writeable for BlindedPathWithPadding<T> {
239245
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
240-
let length = self.tlvs.serialized_length();
246+
let tlv_length = self.tlvs.serialized_length();
247+
let total_length = tlv_length + TLV_OVERHEAD;
248+
241249
let padding_length =
242-
(length + self.round_off - 1) / self.round_off * self.round_off - length;
250+
(total_length + self.round_off - 1) / self.round_off * self.round_off - total_length;
243251

244-
let padding = Some(BlindedPathPadding::new(padding_length));
252+
let padding = BlindedPathPadding::new(padding_length).into();
245253

246254
encode_tlv_stream!(writer, {
247255
(1, padding, option),

0 commit comments

Comments
 (0)