@@ -43,6 +43,7 @@ pub struct ForwardNode {
4343
4444/// TLVs to encode in an intermediate onion message packet's hop data. When provided in a blinded
4545/// route, they are encoded into [`BlindedHop::encrypted_payload`].
46+ #[ derive( Clone ) ]
4647pub ( crate ) struct ForwardTlvs {
4748 /// The next hop in the onion message's path.
4849 pub ( crate ) next_hop : NextMessageHop ,
@@ -52,6 +53,7 @@ pub(crate) struct ForwardTlvs {
5253}
5354
5455/// Similar to [`ForwardTlvs`], but these TLVs are for the final node.
56+ #[ derive( Clone ) ]
5557pub ( crate ) struct ReceiveTlvs {
5658 /// If `context` is `Some`, it is used to identify the blinded path that this onion message is
5759 /// sending to. This is useful for receivers to check that said blinded path is being used in
@@ -65,7 +67,6 @@ impl Writeable for ForwardTlvs {
6567 NextMessageHop :: NodeId ( pubkey) => ( Some ( pubkey) , None ) ,
6668 NextMessageHop :: ShortChannelId ( scid) => ( None , Some ( scid) ) ,
6769 } ;
68- // TODO: write padding
6970 encode_tlv_stream ! ( writer, {
7071 ( 2 , short_channel_id, option) ,
7172 ( 4 , next_node_id, option) ,
@@ -77,7 +78,6 @@ impl Writeable for ForwardTlvs {
7778
7879impl Writeable for ReceiveTlvs {
7980 fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , io:: Error > {
80- // TODO: write padding
8181 encode_tlv_stream ! ( writer, {
8282 ( 65537 , self . context, option) ,
8383 } ) ;
@@ -148,7 +148,14 @@ pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
148148 . map ( |next_hop| ControlTlvs :: Forward ( ForwardTlvs { next_hop, next_blinding_override : None } ) )
149149 . chain ( core:: iter:: once ( ControlTlvs :: Receive ( ReceiveTlvs { context : Some ( context) } ) ) ) ;
150150
151- utils:: construct_blinded_hops ( secp_ctx, pks, tlvs, session_priv)
151+ let max_length = tlvs. clone ( )
152+ . max_by_key ( |c| c. serialized_length ( ) )
153+ . map ( |c| c. serialized_length ( ) )
154+ . unwrap_or ( 0 ) ;
155+
156+ let length_tlvs = tlvs. map ( |tlv| ( max_length, tlv) ) ;
157+
158+ utils:: construct_blinded_hops ( secp_ctx, pks, length_tlvs, session_priv)
152159}
153160
154161// Advance the blinded onion message path by one hop, so make the second hop into the new
0 commit comments