@@ -14,7 +14,7 @@ use bitcoin::secp256k1::{self, PublicKey, Secp256k1, SecretKey};
14
14
#[ allow( unused_imports) ]
15
15
use crate :: prelude:: * ;
16
16
17
- use crate :: blinded_path:: utils;
17
+ use crate :: blinded_path:: utils:: { self , BlindedPathWithPadding } ;
18
18
use crate :: blinded_path:: { BlindedHop , BlindedPath , Direction , IntroductionNode , NodeIdLookUp } ;
19
19
use crate :: crypto:: streams:: ChaChaPolyReadAdapter ;
20
20
use crate :: io;
@@ -265,7 +265,6 @@ impl Writeable for ForwardTlvs {
265
265
NextMessageHop :: NodeId ( pubkey) => ( Some ( pubkey) , None ) ,
266
266
NextMessageHop :: ShortChannelId ( scid) => ( None , Some ( scid) ) ,
267
267
} ;
268
- // TODO: write padding
269
268
encode_tlv_stream ! ( writer, {
270
269
( 2 , short_channel_id, option) ,
271
270
( 4 , next_node_id, option) ,
@@ -277,7 +276,6 @@ impl Writeable for ForwardTlvs {
277
276
278
277
impl Writeable for ReceiveTlvs {
279
278
fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , io:: Error > {
280
- // TODO: write padding
281
279
encode_tlv_stream ! ( writer, {
282
280
( 65537 , self . context, option) ,
283
281
} ) ;
@@ -495,6 +493,10 @@ impl_writeable_tlv_based!(DNSResolverContext, {
495
493
( 0 , nonce, required) ,
496
494
} ) ;
497
495
496
+ /// Represents the padding round off size (in bytes) that is used
497
+ /// to pad message blinded path's [`BlindedHop`]
498
+ pub ( crate ) const MESSAGE_PADDING_ROUND_OFF : usize = 100 ;
499
+
498
500
/// Construct blinded onion message hops for the given `intermediate_nodes` and `recipient_node_id`.
499
501
pub ( super ) fn blinded_hops < T : secp256k1:: Signing + secp256k1:: Verification > (
500
502
secp_ctx : & Secp256k1 < T > , intermediate_nodes : & [ MessageForwardNode ] ,
@@ -504,6 +506,8 @@ pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
504
506
. iter ( )
505
507
. map ( |node| node. node_id )
506
508
. chain ( core:: iter:: once ( recipient_node_id) ) ;
509
+ let is_compact = intermediate_nodes. iter ( ) . any ( |node| node. short_channel_id . is_some ( ) ) ;
510
+
507
511
let tlvs = pks
508
512
. clone ( )
509
513
. skip ( 1 ) // The first node's TLVs contains the next node's pubkey
@@ -517,7 +521,15 @@ pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
517
521
} )
518
522
. chain ( core:: iter:: once ( ControlTlvs :: Receive ( ReceiveTlvs { context : Some ( context) } ) ) ) ;
519
523
520
- let path = pks. zip ( tlvs) ;
521
-
522
- utils:: construct_blinded_hops ( secp_ctx, path, session_priv)
524
+ if is_compact {
525
+ let path = pks. zip ( tlvs) ;
526
+ utils:: construct_blinded_hops ( secp_ctx, path, session_priv)
527
+ } else {
528
+ let path =
529
+ pks. zip ( tlvs. map ( |tlv| BlindedPathWithPadding {
530
+ tlvs : tlv,
531
+ round_off : MESSAGE_PADDING_ROUND_OFF ,
532
+ } ) ) ;
533
+ utils:: construct_blinded_hops ( secp_ctx, path, session_priv)
534
+ }
523
535
}
0 commit comments