@@ -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;
20+ use crate :: blinded_path:: utils:: { self , WithPadding } ;
2121use crate :: io;
2222use crate :: io:: Cursor ;
2323use crate :: ln:: channelmanager:: PaymentId ;
@@ -44,6 +44,7 @@ pub struct ForwardNode {
4444
4545/// TLVs to encode in an intermediate onion message packet's hop data. When provided in a blinded
4646/// route, they are encoded into [`BlindedHop::encrypted_payload`].
47+ #[ derive( Clone ) ]
4748pub ( crate ) struct ForwardTlvs {
4849 /// The next hop in the onion message's path.
4950 pub ( crate ) next_hop : NextMessageHop ,
@@ -53,6 +54,7 @@ pub(crate) struct ForwardTlvs {
5354}
5455
5556/// Similar to [`ForwardTlvs`], but these TLVs are for the final node.
57+ #[ derive( Clone ) ]
5658pub ( crate ) struct ReceiveTlvs {
5759 /// If `context` is `Some`, it is used to identify the blinded path that this onion message is
5860 /// sending to. This is useful for receivers to check that said blinded path is being used in
@@ -66,7 +68,6 @@ impl Writeable for ForwardTlvs {
6668 NextMessageHop :: NodeId ( pubkey) => ( Some ( pubkey) , None ) ,
6769 NextMessageHop :: ShortChannelId ( scid) => ( None , Some ( scid) ) ,
6870 } ;
69- // TODO: write padding
7071 encode_tlv_stream ! ( writer, {
7172 ( 2 , short_channel_id, option) ,
7273 ( 4 , next_node_id, option) ,
@@ -78,7 +79,6 @@ impl Writeable for ForwardTlvs {
7879
7980impl Writeable for ReceiveTlvs {
8081 fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , io:: Error > {
81- // TODO: write padding
8282 encode_tlv_stream ! ( writer, {
8383 ( 65537 , self . context, option) ,
8484 } ) ;
@@ -187,7 +187,14 @@ pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
187187 . map ( |next_hop| ControlTlvs :: Forward ( ForwardTlvs { next_hop, next_blinding_override : None } ) )
188188 . chain ( core:: iter:: once ( ControlTlvs :: Receive ( ReceiveTlvs { context : Some ( context) } ) ) ) ;
189189
190- utils:: construct_blinded_hops ( secp_ctx, pks, tlvs, session_priv)
190+ let max_length = tlvs. clone ( )
191+ . map ( |tlv| tlv. serialized_length ( ) )
192+ . max ( )
193+ . unwrap_or ( 0 ) ;
194+
195+ let length_tlvs = tlvs. map ( |tlvs| WithPadding { max_length, tlvs } ) ;
196+
197+ utils:: construct_blinded_hops ( secp_ctx, pks, length_tlvs, session_priv)
191198}
192199
193200// Advance the blinded onion message path by one hop, so make the second hop into the new
0 commit comments