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 {
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`
233239pub ( crate ) struct BlindedPathWithPadding < T : Writeable > {
234240 pub ( crate ) tlvs : T ,
@@ -237,11 +243,13 @@ pub(crate) struct BlindedPathWithPadding<T: Writeable> {
237243
238244impl < 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) ,
You can’t perform that action at this time.
0 commit comments