File tree Expand file tree Collapse file tree 2 files changed +15
-5
lines changed Expand file tree Collapse file tree 2 files changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ use crate::io;
22
22
use crate :: io:: Cursor ;
23
23
use crate :: ln:: channelmanager:: PaymentId ;
24
24
use crate :: ln:: onion_utils;
25
- use crate :: onion_message:: packet:: ControlTlvs ;
25
+ use crate :: onion_message:: packet:: { ControlTlvs , LengthTlvs } ;
26
26
use crate :: sign:: { NodeSigner , Recipient } ;
27
27
use crate :: crypto:: streams:: ChaChaPolyReadAdapter ;
28
28
use crate :: util:: ser:: { FixedLengthReader , LengthReadableArgs , Writeable , Writer } ;
@@ -153,7 +153,7 @@ pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
153
153
. max ( )
154
154
. unwrap_or ( 0 ) ;
155
155
156
- let length_tlvs = tlvs. map ( |tlv| ( max_length, tlv ) ) ;
156
+ let length_tlvs = tlvs. map ( |tlvs| LengthTlvs { max_length, tlvs } ) ;
157
157
158
158
utils:: construct_blinded_hops ( secp_ctx, pks, length_tlvs, session_priv)
159
159
}
Original file line number Diff line number Diff line change @@ -314,6 +314,16 @@ pub(crate) enum ControlTlvs {
314
314
Receive ( ReceiveTlvs ) ,
315
315
}
316
316
317
+ /// A wrapper struct that stores the largest packet length in the given [`BlindedPath`].
318
+ /// This helps us calculate the appropriate padding size for the [`ControlTlvs`] at the time
319
+ /// of writing them.
320
+ pub ( crate ) struct LengthTlvs {
321
+ /// Length of the packet with the largest size in the [`BlindedPath`].
322
+ pub ( crate ) max_length : usize ,
323
+ /// The current packet's TLVs.
324
+ pub ( crate ) tlvs : ControlTlvs ,
325
+ }
326
+
317
327
impl Readable for ControlTlvs {
318
328
fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
319
329
_init_and_read_tlv_stream ! ( r, {
@@ -361,15 +371,15 @@ impl Writeable for ControlTlvs {
361
371
}
362
372
}
363
373
364
- impl Writeable for ( usize , ControlTlvs ) {
374
+ impl Writeable for LengthTlvs {
365
375
fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , io:: Error > {
366
- let length = self . 0 - self . 1 . serialized_length ( ) ;
376
+ let length = self . max_length - self . tlvs . serialized_length ( ) ;
367
377
let padding = Some ( Padding :: new ( length) ) ;
368
378
369
379
encode_tlv_stream ! ( writer, {
370
380
( 1 , padding, option)
371
381
} ) ;
372
382
373
- self . 1 . write ( writer)
383
+ self . tlvs . write ( writer)
374
384
}
375
385
}
You can’t perform that action at this time.
0 commit comments