@@ -17,7 +17,7 @@ use bitcoin::secp256k1::{self, PublicKey, Secp256k1, SecretKey};
17
17
use crate :: prelude:: * ;
18
18
19
19
use crate :: blinded_path:: { BlindedHop , BlindedPath , IntroductionNode , NextMessageHop , NodeIdLookUp } ;
20
- use crate :: blinded_path:: utils;
20
+ use crate :: blinded_path:: utils:: { self , WithPadding } ;
21
21
use crate :: io;
22
22
use crate :: io:: Cursor ;
23
23
use crate :: ln:: channelmanager:: PaymentId ;
@@ -44,6 +44,7 @@ pub struct ForwardNode {
44
44
45
45
/// TLVs to encode in an intermediate onion message packet's hop data. When provided in a blinded
46
46
/// route, they are encoded into [`BlindedHop::encrypted_payload`].
47
+ #[ derive( Clone ) ]
47
48
pub ( crate ) struct ForwardTlvs {
48
49
/// The next hop in the onion message's path.
49
50
pub ( crate ) next_hop : NextMessageHop ,
@@ -53,6 +54,7 @@ pub(crate) struct ForwardTlvs {
53
54
}
54
55
55
56
/// Similar to [`ForwardTlvs`], but these TLVs are for the final node.
57
+ #[ derive( Clone ) ]
56
58
pub ( crate ) struct ReceiveTlvs {
57
59
/// If `context` is `Some`, it is used to identify the blinded path that this onion message is
58
60
/// sending to. This is useful for receivers to check that said blinded path is being used in
@@ -66,7 +68,6 @@ impl Writeable for ForwardTlvs {
66
68
NextMessageHop :: NodeId ( pubkey) => ( Some ( pubkey) , None ) ,
67
69
NextMessageHop :: ShortChannelId ( scid) => ( None , Some ( scid) ) ,
68
70
} ;
69
- // TODO: write padding
70
71
encode_tlv_stream ! ( writer, {
71
72
( 2 , short_channel_id, option) ,
72
73
( 4 , next_node_id, option) ,
@@ -78,7 +79,6 @@ impl Writeable for ForwardTlvs {
78
79
79
80
impl Writeable for ReceiveTlvs {
80
81
fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , io:: Error > {
81
- // TODO: write padding
82
82
encode_tlv_stream ! ( writer, {
83
83
( 65537 , self . context, option) ,
84
84
} ) ;
@@ -187,7 +187,14 @@ pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
187
187
. map ( |next_hop| ControlTlvs :: Forward ( ForwardTlvs { next_hop, next_blinding_override : None } ) )
188
188
. chain ( core:: iter:: once ( ControlTlvs :: Receive ( ReceiveTlvs { context : Some ( context) } ) ) ) ;
189
189
190
- utils:: construct_blinded_hops ( secp_ctx, pks, tlvs, session_priv)
190
+ let max_length = tlvs. clone ( )
191
+ . map ( |tlv| tlv. serialized_length ( ) )
192
+ . max ( )
193
+ . unwrap_or ( 0 ) ;
194
+
195
+ let length_tlvs = tlvs. map ( |tlvs| WithPadding { max_length, tlvs } ) ;
196
+
197
+ utils:: construct_blinded_hops ( secp_ctx, pks, length_tlvs, session_priv)
191
198
}
192
199
193
200
// Advance the blinded onion message path by one hop, so make the second hop into the new
0 commit comments