@@ -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
@@ -136,23 +138,22 @@ pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
136138) -> Result < Vec < BlindedHop > , secp256k1:: Error > {
137139 let pks = intermediate_nodes. iter ( ) . map ( |node| & node. node_id )
138140 . chain ( core:: iter:: once ( & recipient_node_id) ) ;
139- let tlvs: Vec < ControlTlvs > = pks. clone ( )
141+ let tlvs = pks. clone ( )
140142 . skip ( 1 ) // The first node's TLVs contains the next node's pubkey
141143 . zip ( intermediate_nodes. iter ( ) . map ( |node| node. short_channel_id ) )
142144 . map ( |( pubkey, scid) | match scid {
143145 Some ( scid) => NextMessageHop :: ShortChannelId ( scid) ,
144146 None => NextMessageHop :: NodeId ( * pubkey) ,
145147 } )
146148 . map ( |next_hop| ControlTlvs :: Forward ( ForwardTlvs { next_hop, next_blinding_override : None } ) )
147- . chain ( core:: iter:: once ( ControlTlvs :: Receive ( ReceiveTlvs { context : Some ( context) } ) ) )
148- . collect ( ) ;
149+ . chain ( core:: iter:: once ( ControlTlvs :: Receive ( ReceiveTlvs { context : Some ( context) } ) ) ) ;
149150
150- let max_length = tlvs. iter ( )
151+ let max_length = tlvs. clone ( )
151152 . max_by_key ( |c| c. serialized_length ( ) )
152153 . map ( |c| c. serialized_length ( ) )
153154 . unwrap_or ( 0 ) ;
154155
155- let length_tlvs = tlvs. into_iter ( ) . map ( move |tlv| ( max_length, tlv) ) ;
156+ let length_tlvs = tlvs. map ( |tlv| ( max_length, tlv) ) ;
156157
157158 utils:: construct_blinded_hops ( secp_ctx, pks, length_tlvs, session_priv)
158159}
0 commit comments