@@ -17,7 +17,7 @@ use crate::prelude::*;
17
17
use bitcoin:: hashes:: hmac:: Hmac ;
18
18
use bitcoin:: hashes:: sha256:: Hash as Sha256 ;
19
19
use crate :: blinded_path:: { BlindedHop , BlindedPath , Direction , IntroductionNode , NodeIdLookUp } ;
20
- use crate :: blinded_path:: utils;
20
+ use crate :: blinded_path:: utils:: { self , BlindedPathWithPadding } ;
21
21
use crate :: io;
22
22
use crate :: io:: Cursor ;
23
23
use crate :: ln:: channelmanager:: PaymentId ;
@@ -250,7 +250,6 @@ impl Writeable for ForwardTlvs {
250
250
NextMessageHop :: NodeId ( pubkey) => ( Some ( pubkey) , None ) ,
251
251
NextMessageHop :: ShortChannelId ( scid) => ( None , Some ( scid) ) ,
252
252
} ;
253
- // TODO: write padding
254
253
encode_tlv_stream ! ( writer, {
255
254
( 2 , short_channel_id, option) ,
256
255
( 4 , next_node_id, option) ,
@@ -262,7 +261,6 @@ impl Writeable for ForwardTlvs {
262
261
263
262
impl Writeable for ReceiveTlvs {
264
263
fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , io:: Error > {
265
- // TODO: write padding
266
264
encode_tlv_stream ! ( writer, {
267
265
( 65537 , self . context, option) ,
268
266
} ) ;
@@ -453,13 +451,19 @@ impl_writeable_tlv_based!(DNSResolverContext, {
453
451
( 0 , nonce, required) ,
454
452
} ) ;
455
453
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
+
456
458
/// Construct blinded onion message hops for the given `intermediate_nodes` and `recipient_node_id`.
457
459
pub ( super ) fn blinded_hops < T : secp256k1:: Signing + secp256k1:: Verification > (
458
460
secp_ctx : & Secp256k1 < T > , intermediate_nodes : & [ MessageForwardNode ] ,
459
461
recipient_node_id : PublicKey , context : MessageContext , session_priv : & SecretKey ,
460
462
) -> Result < Vec < BlindedHop > , secp256k1:: Error > {
461
463
let pks = intermediate_nodes. iter ( ) . map ( |node| node. node_id )
462
464
. chain ( core:: iter:: once ( recipient_node_id) ) ;
465
+ let is_compact = intermediate_nodes. iter ( ) . any ( |node| node. short_channel_id . is_some ( ) ) ;
466
+
463
467
let tlvs = pks. clone ( )
464
468
. skip ( 1 ) // The first node's TLVs contains the next node's pubkey
465
469
. zip ( intermediate_nodes. iter ( ) . map ( |node| node. short_channel_id ) )
@@ -470,8 +474,12 @@ pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
470
474
. map ( |next_hop| ControlTlvs :: Forward ( ForwardTlvs { next_hop, next_blinding_override : None } ) )
471
475
. chain ( core:: iter:: once ( ControlTlvs :: Receive ( ReceiveTlvs { context : Some ( context) } ) ) ) ;
472
476
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
+ }
476
484
}
477
485
0 commit comments