Skip to content

Commit 5d7fac2

Browse files
committed
f: Introduce TLV_OVERHEAD
1 parent b8735c4 commit 5d7fac2

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
@@ -201,6 +201,11 @@ impl Writeable for BlindedPathPadding {
201201
}
202202
}
203203

204+
/// The constant size added to unencrypted TLV length,
205+
/// due to the addition of Padding Type (2 bytes) and
206+
/// encryption data (16 bytes).
207+
const TLV_OVERHEAD: usize = 18;
208+
204209
/// A generic struct that applies padding to blinded path TLVs, rounding their size off to `round_off`
205210
pub(crate) struct BlindedPathWithPadding<T: Writeable> {
206211
pub(crate) tlvs: T,
@@ -209,10 +214,13 @@ pub(crate) struct BlindedPathWithPadding<T: Writeable> {
209214

210215
impl<T:Writeable> Writeable for BlindedPathWithPadding<T> {
211216
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
212-
let length = self.tlvs.serialized_length();
213-
let padding_length = (length + self.round_off - 1) / self.round_off * self.round_off - length;
217+
let tlv_length = self.tlvs.serialized_length();
218+
let total_length = tlv_length + TLV_OVERHEAD;
219+
220+
let padding_length = (total_length + self.round_off - 1) / self.round_off * self.round_off
221+
- total_length;
214222

215-
let padding = Some(BlindedPathPadding::new(padding_length));
223+
let padding = BlindedPathPadding::new(padding_length).into();
216224

217225
encode_tlv_stream!(writer, {
218226
(1, padding, option),

0 commit comments

Comments
 (0)