@@ -65,7 +65,6 @@ impl Writeable for ForwardTlvs {
65
65
NextMessageHop :: NodeId ( pubkey) => ( Some ( pubkey) , None ) ,
66
66
NextMessageHop :: ShortChannelId ( scid) => ( None , Some ( scid) ) ,
67
67
} ;
68
- // TODO: write padding
69
68
encode_tlv_stream ! ( writer, {
70
69
( 2 , short_channel_id, option) ,
71
70
( 4 , next_node_id, option) ,
@@ -77,7 +76,6 @@ impl Writeable for ForwardTlvs {
77
76
78
77
impl Writeable for ReceiveTlvs {
79
78
fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , io:: Error > {
80
- // TODO: write padding
81
79
encode_tlv_stream ! ( writer, {
82
80
( 65537 , self . context, option) ,
83
81
} ) ;
@@ -138,17 +136,25 @@ pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
138
136
) -> Result < Vec < BlindedHop > , secp256k1:: Error > {
139
137
let pks = intermediate_nodes. iter ( ) . map ( |node| & node. node_id )
140
138
. chain ( core:: iter:: once ( & recipient_node_id) ) ;
141
- let tlvs = pks. clone ( )
139
+ let tlvs: Vec < ControlTlvs > = pks. clone ( )
142
140
. skip ( 1 ) // The first node's TLVs contains the next node's pubkey
143
141
. zip ( intermediate_nodes. iter ( ) . map ( |node| node. short_channel_id ) )
144
142
. map ( |( pubkey, scid) | match scid {
145
143
Some ( scid) => NextMessageHop :: ShortChannelId ( scid) ,
146
144
None => NextMessageHop :: NodeId ( * pubkey) ,
147
145
} )
148
146
. map ( |next_hop| ControlTlvs :: Forward ( ForwardTlvs { next_hop, next_blinding_override : None } ) )
149
- . chain ( core:: iter:: once ( ControlTlvs :: Receive ( ReceiveTlvs { context : Some ( context) } ) ) ) ;
147
+ . chain ( core:: iter:: once ( ControlTlvs :: Receive ( ReceiveTlvs { context : Some ( context) } ) ) )
148
+ . collect ( ) ;
150
149
151
- utils:: construct_blinded_hops ( secp_ctx, pks, tlvs, session_priv)
150
+ let max_length = tlvs. iter ( )
151
+ . max_by_key ( |c| c. serialized_length ( ) )
152
+ . map ( |c| c. serialized_length ( ) )
153
+ . unwrap_or ( 0 ) ;
154
+
155
+ let length_tlvs = tlvs. into_iter ( ) . map ( move |tlv| ( max_length, tlv) ) ;
156
+
157
+ utils:: construct_blinded_hops ( secp_ctx, pks, length_tlvs, session_priv)
152
158
}
153
159
154
160
// Advance the blinded onion message path by one hop, so make the second hop into the new
0 commit comments