@@ -17,7 +17,7 @@ use crate::prelude::*;
1717use bitcoin:: hashes:: hmac:: Hmac ;
1818use bitcoin:: hashes:: sha256:: Hash as Sha256 ;
1919use crate :: blinded_path:: { BlindedHop , BlindedPath , Direction , IntroductionNode , NodeIdLookUp } ;
20- use crate :: blinded_path:: utils;
20+ use crate :: blinded_path:: utils:: { self , BlindedPathWithPadding } ;
2121use crate :: io;
2222use crate :: io:: Cursor ;
2323use crate :: ln:: channelmanager:: PaymentId ;
@@ -250,7 +250,6 @@ impl Writeable for ForwardTlvs {
250250 NextMessageHop :: NodeId ( pubkey) => ( Some ( pubkey) , None ) ,
251251 NextMessageHop :: ShortChannelId ( scid) => ( None , Some ( scid) ) ,
252252 } ;
253- // TODO: write padding
254253 encode_tlv_stream ! ( writer, {
255254 ( 2 , short_channel_id, option) ,
256255 ( 4 , next_node_id, option) ,
@@ -262,7 +261,6 @@ impl Writeable for ForwardTlvs {
262261
263262impl Writeable for ReceiveTlvs {
264263 fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , io:: Error > {
265- // TODO: write padding
266264 encode_tlv_stream ! ( writer, {
267265 ( 65537 , self . context, option) ,
268266 } ) ;
@@ -453,13 +451,19 @@ impl_writeable_tlv_based!(DNSResolverContext, {
453451 ( 0 , nonce, required) ,
454452} ) ;
455453
454+ /// Represents the padding round off size (in bytes) that is used
455+ /// to pad message blinded path's [`BlindedHop`]
456+ pub ( crate ) const MESSAGE_PADDING_ROUND_OFF : usize = 100 ;
457+
456458/// Construct blinded onion message hops for the given `intermediate_nodes` and `recipient_node_id`.
457459pub ( super ) fn blinded_hops < T : secp256k1:: Signing + secp256k1:: Verification > (
458460 secp_ctx : & Secp256k1 < T > , intermediate_nodes : & [ MessageForwardNode ] ,
459461 recipient_node_id : PublicKey , context : MessageContext , session_priv : & SecretKey ,
460462) -> Result < Vec < BlindedHop > , secp256k1:: Error > {
461463 let pks = intermediate_nodes. iter ( ) . map ( |node| node. node_id )
462464 . chain ( core:: iter:: once ( recipient_node_id) ) ;
465+ let is_compact = intermediate_nodes. iter ( ) . any ( |node| node. short_channel_id . is_some ( ) ) ;
466+
463467 let tlvs = pks. clone ( )
464468 . skip ( 1 ) // The first node's TLVs contains the next node's pubkey
465469 . zip ( intermediate_nodes. iter ( ) . map ( |node| node. short_channel_id ) )
@@ -470,8 +474,12 @@ pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
470474 . map ( |next_hop| ControlTlvs :: Forward ( ForwardTlvs { next_hop, next_blinding_override : None } ) )
471475 . chain ( core:: iter:: once ( ControlTlvs :: Receive ( ReceiveTlvs { context : Some ( context) } ) ) ) ;
472476
473- let path = pks. zip ( tlvs) ;
474-
475- utils:: construct_blinded_hops ( secp_ctx, path, session_priv)
477+ if is_compact {
478+ let path = pks. zip ( tlvs) ;
479+ utils:: construct_blinded_hops ( secp_ctx, path, session_priv)
480+ } else {
481+ let path = pks. zip ( tlvs. map ( |tlv| BlindedPathWithPadding { tlvs : tlv, round_off : MESSAGE_PADDING_ROUND_OFF } ) ) ;
482+ utils:: construct_blinded_hops ( secp_ctx, path, session_priv)
483+ }
476484}
477485
0 commit comments