File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed
lightning/src/blinded_path Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -201,6 +201,12 @@ impl Writeable for BlindedPathPadding {
201
201
}
202
202
}
203
203
204
+ /// Padding storage requires two extra bytes:
205
+ /// - One byte for the type.
206
+ /// - One byte for the padding length.
207
+ /// This constant accounts for that overhead.
208
+ const TLV_OVERHEAD : usize = 2 ;
209
+
204
210
/// A generic struct that applies padding to blinded path TLVs, rounding their size off to `round_off`
205
211
pub ( crate ) struct BlindedPathWithPadding < T : Writeable > {
206
212
pub ( crate ) tlvs : T ,
@@ -209,10 +215,13 @@ pub(crate) struct BlindedPathWithPadding<T: Writeable> {
209
215
210
216
impl < T : Writeable > Writeable for BlindedPathWithPadding < T > {
211
217
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;
218
+ let tlv_length = self . tlvs . serialized_length ( ) ;
219
+ let total_length = tlv_length + TLV_OVERHEAD ;
220
+
221
+ let padding_length = ( total_length + self . round_off - 1 ) / self . round_off * self . round_off
222
+ - total_length;
214
223
215
- let padding = Some ( BlindedPathPadding :: new ( padding_length) ) ;
224
+ let padding = BlindedPathPadding :: new ( padding_length) . into ( ) ;
216
225
217
226
encode_tlv_stream ! ( writer, {
218
227
( 1 , padding, option) ,
You can’t perform that action at this time.
0 commit comments