File tree Expand file tree Collapse file tree 1 file changed +11
-3
lines changed
lightning/src/blinded_path Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -229,6 +229,12 @@ impl Writeable for BlindedPathPadding {
229
229
}
230
230
}
231
231
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
+
232
238
/// A generic struct that applies padding to blinded path TLVs, rounding their size off to `round_off`
233
239
pub ( crate ) struct BlindedPathWithPadding < T : Writeable > {
234
240
pub ( crate ) tlvs : T ,
@@ -237,11 +243,13 @@ pub(crate) struct BlindedPathWithPadding<T: Writeable> {
237
243
238
244
impl < T : Writeable > Writeable for BlindedPathWithPadding < T > {
239
245
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
+
241
249
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 ;
243
251
244
- let padding = Some ( BlindedPathPadding :: new ( padding_length) ) ;
252
+ let padding = BlindedPathPadding :: new ( padding_length) . into ( ) ;
245
253
246
254
encode_tlv_stream ! ( writer, {
247
255
( 1 , padding, option) ,
You can’t perform that action at this time.
0 commit comments