@@ -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
@@ -65,7 +67,6 @@ impl Writeable for ForwardTlvs {
65
67
NextMessageHop :: NodeId ( pubkey) => ( Some ( pubkey) , None ) ,
66
68
NextMessageHop :: ShortChannelId ( scid) => ( None , Some ( scid) ) ,
67
69
} ;
68
- // TODO: write padding
69
70
encode_tlv_stream ! ( writer, {
70
71
( 2 , short_channel_id, option) ,
71
72
( 4 , next_node_id, option) ,
@@ -77,7 +78,6 @@ impl Writeable for ForwardTlvs {
77
78
78
79
impl Writeable for ReceiveTlvs {
79
80
fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , io:: Error > {
80
- // TODO: write padding
81
81
encode_tlv_stream ! ( writer, {
82
82
( 65537 , self . context, option) ,
83
83
} ) ;
@@ -148,7 +148,14 @@ pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
148
148
. map ( |next_hop| ControlTlvs :: Forward ( ForwardTlvs { next_hop, next_blinding_override : None } ) )
149
149
. chain ( core:: iter:: once ( ControlTlvs :: Receive ( ReceiveTlvs { context : Some ( context) } ) ) ) ;
150
150
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)
152
159
}
153
160
154
161
// Advance the blinded onion message path by one hop, so make the second hop into the new
0 commit comments