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;
2222use crate :: io:: Cursor ;
2323use crate :: ln:: channelmanager:: PaymentId ;
2424use crate :: ln:: onion_utils;
25- use crate :: onion_message:: packet:: ControlTlvs ;
25+ use crate :: onion_message:: packet:: { ControlTlvs , LengthTlvs } ;
2626use crate :: sign:: { NodeSigner , Recipient } ;
2727use crate :: crypto:: streams:: ChaChaPolyReadAdapter ;
2828use crate :: util:: ser:: { FixedLengthReader , LengthReadableArgs , Writeable , Writer } ;
@@ -153,7 +153,7 @@ pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
153153 . max ( )
154154 . unwrap_or ( 0 ) ;
155155
156- let length_tlvs = tlvs. map ( |tlv| ( max_length, tlv ) ) ;
156+ let length_tlvs = tlvs. map ( |tlvs| LengthTlvs { max_length, tlvs } ) ;
157157
158158 utils:: construct_blinded_hops ( secp_ctx, pks, length_tlvs, session_priv)
159159}
Original file line number Diff line number Diff line change @@ -314,6 +314,16 @@ pub(crate) enum ControlTlvs {
314314 Receive ( ReceiveTlvs ) ,
315315}
316316
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+
317327impl Readable for ControlTlvs {
318328 fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
319329 _init_and_read_tlv_stream ! ( r, {
@@ -361,15 +371,15 @@ impl Writeable for ControlTlvs {
361371 }
362372}
363373
364- impl Writeable for ( usize , ControlTlvs ) {
374+ impl Writeable for LengthTlvs {
365375 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 ( ) ;
367377 let padding = Some ( Padding :: new ( length) ) ;
368378
369379 encode_tlv_stream ! ( writer, {
370380 ( 1 , padding, option)
371381 } ) ;
372382
373- self . 1 . write ( writer)
383+ self . tlvs . write ( writer)
374384 }
375385}
You can’t perform that action at this time.
0 commit comments