@@ -17,7 +17,7 @@ use bitcoin::secp256k1::{self, PublicKey, Secp256k1, SecretKey};
1717use crate :: prelude:: * ;
1818
1919use crate :: blinded_path:: { BlindedHop , BlindedPath , IntroductionNode , NextMessageHop , NodeIdLookUp } ;
20- use crate :: blinded_path:: utils:: { self , WithPadding } ;
20+ use crate :: blinded_path:: utils:: { self , Padding } ;
2121use crate :: io;
2222use crate :: io:: Cursor ;
2323use crate :: ln:: channelmanager:: PaymentId ;
@@ -46,6 +46,8 @@ pub struct ForwardNode {
4646/// route, they are encoded into [`BlindedHop::encrypted_payload`].
4747#[ derive( Clone ) ]
4848pub ( crate ) struct ForwardTlvs {
49+ /// The padding data used to make all packets of a Blinded Path of same size
50+ pub ( crate ) padding : Option < Padding > ,
4951 /// The next hop in the onion message's path.
5052 pub ( crate ) next_hop : NextMessageHop ,
5153 /// Senders to a blinded path use this value to concatenate the route they find to the
@@ -56,6 +58,8 @@ pub(crate) struct ForwardTlvs {
5658/// Similar to [`ForwardTlvs`], but these TLVs are for the final node.
5759#[ derive( Clone ) ]
5860pub ( crate ) struct ReceiveTlvs {
61+ /// The padding data used to make all packets of a Blinded Path of same size
62+ pub ( crate ) padding : Option < Padding > ,
5963 /// If `context` is `Some`, it is used to identify the blinded path that this onion message is
6064 /// sending to. This is useful for receivers to check that said blinded path is being used in
6165 /// the right context.
@@ -69,6 +73,7 @@ impl Writeable for ForwardTlvs {
6973 NextMessageHop :: ShortChannelId ( scid) => ( None , Some ( scid) ) ,
7074 } ;
7175 encode_tlv_stream ! ( writer, {
76+ ( 1 , self . padding, option) ,
7277 ( 2 , short_channel_id, option) ,
7378 ( 4 , next_node_id, option) ,
7479 ( 8 , self . next_blinding_override, option)
@@ -80,6 +85,7 @@ impl Writeable for ForwardTlvs {
8085impl Writeable for ReceiveTlvs {
8186 fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , io:: Error > {
8287 encode_tlv_stream ! ( writer, {
88+ ( 1 , self . padding, option) ,
8389 ( 65537 , self . context, option) ,
8490 } ) ;
8591 Ok ( ( ) )
@@ -184,15 +190,15 @@ pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
184190 Some ( scid) => NextMessageHop :: ShortChannelId ( scid) ,
185191 None => NextMessageHop :: NodeId ( * pubkey) ,
186192 } )
187- . map ( |next_hop| ControlTlvs :: Forward ( ForwardTlvs { next_hop, next_blinding_override : None } ) )
188- . chain ( core:: iter:: once ( ControlTlvs :: Receive ( ReceiveTlvs { context : Some ( context) } ) ) ) ;
193+ . map ( |next_hop| ControlTlvs :: Forward ( ForwardTlvs { padding : None , next_hop, next_blinding_override : None } ) )
194+ . chain ( core:: iter:: once ( ControlTlvs :: Receive ( ReceiveTlvs { padding : None , context : Some ( context) } ) ) ) ;
189195
190196 let max_length = tlvs. clone ( )
191197 . map ( |tlv| tlv. serialized_length ( ) )
192198 . max ( )
193199 . unwrap_or ( 0 ) ;
194200
195- let length_tlvs = tlvs. map ( |tlvs| WithPadding { max_length, tlvs } ) ;
201+ let length_tlvs = tlvs. map ( |tlv| tlv . pad_to_length ( max_length) ) ;
196202
197203 utils:: construct_blinded_hops ( secp_ctx, pks, length_tlvs, session_priv)
198204}
@@ -216,7 +222,7 @@ where
216222 let mut reader = FixedLengthReader :: new ( & mut s, encrypted_control_tlvs. len ( ) as u64 ) ;
217223 match ChaChaPolyReadAdapter :: read ( & mut reader, rho) {
218224 Ok ( ChaChaPolyReadAdapter {
219- readable : ControlTlvs :: Forward ( ForwardTlvs { next_hop, next_blinding_override } )
225+ readable : ControlTlvs :: Forward ( ForwardTlvs { padding : _ , next_hop, next_blinding_override } )
220226 } ) => {
221227 let next_node_id = match next_hop {
222228 NextMessageHop :: NodeId ( pubkey) => pubkey,
0 commit comments