@@ -43,6 +43,7 @@ pub struct ForwardNode {
43
43
44
44
/// TLVs to encode in an intermediate onion message packet's hop data. When provided in a blinded
45
45
/// route, they are encoded into [`BlindedHop::encrypted_payload`].
46
+ #[ derive( Clone ) ]
46
47
pub ( crate ) struct ForwardTlvs {
47
48
/// The next hop in the onion message's path.
48
49
pub ( crate ) next_hop : NextMessageHop ,
@@ -52,6 +53,7 @@ pub(crate) struct ForwardTlvs {
52
53
}
53
54
54
55
/// Similar to [`ForwardTlvs`], but these TLVs are for the final node.
56
+ #[ derive( Clone ) ]
55
57
pub ( crate ) struct ReceiveTlvs {
56
58
/// If `context` is `Some`, it is used to identify the blinded path that this onion message is
57
59
/// 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>(
136
138
) -> Result < Vec < BlindedHop > , secp256k1:: Error > {
137
139
let pks = intermediate_nodes. iter ( ) . map ( |node| & node. node_id )
138
140
. chain ( core:: iter:: once ( & recipient_node_id) ) ;
139
- let tlvs: Vec < ControlTlvs > = pks. clone ( )
141
+ let tlvs = pks. clone ( )
140
142
. skip ( 1 ) // The first node's TLVs contains the next node's pubkey
141
143
. zip ( intermediate_nodes. iter ( ) . map ( |node| node. short_channel_id ) )
142
144
. map ( |( pubkey, scid) | match scid {
143
145
Some ( scid) => NextMessageHop :: ShortChannelId ( scid) ,
144
146
None => NextMessageHop :: NodeId ( * pubkey) ,
145
147
} )
146
148
. 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) } ) ) ) ;
149
150
150
- let max_length = tlvs. iter ( )
151
+ let max_length = tlvs. clone ( )
151
152
. max_by_key ( |c| c. serialized_length ( ) )
152
153
. map ( |c| c. serialized_length ( ) )
153
154
. unwrap_or ( 0 ) ;
154
155
155
- let length_tlvs = tlvs. into_iter ( ) . map ( move |tlv| ( max_length, tlv) ) ;
156
+ let length_tlvs = tlvs. map ( |tlv| ( max_length, tlv) ) ;
156
157
157
158
utils:: construct_blinded_hops ( secp_ctx, pks, length_tlvs, session_priv)
158
159
}
0 commit comments