@@ -151,7 +151,7 @@ for OnionMessenger<ES, NS, L, NL, MR, OMH, APH, CMH> where
151
151
/// # use lightning::blinded_path::message::{BlindedMessagePath, ForwardNode, MessageContext};
152
152
/// # use lightning::sign::{EntropySource, KeysManager};
153
153
/// # use lightning::ln::peer_handler::IgnoringMessageHandler;
154
- /// # use lightning::onion_message::messenger::{Destination, MessageRouter, OnionMessagePath, OnionMessenger};
154
+ /// # use lightning::onion_message::messenger::{BlindedPathParams, Destination, MessageRouter, OnionMessagePath, OnionMessenger};
155
155
/// # use lightning::onion_message::packet::OnionMessageContents;
156
156
/// # use lightning::util::logger::{Logger, Record};
157
157
/// # use lightning::util::ser::{Writeable, Writer};
@@ -175,7 +175,7 @@ for OnionMessenger<ES, NS, L, NL, MR, OMH, APH, CMH> where
175
175
/// # })
176
176
/// # }
177
177
/// # fn create_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
178
- /// # &self, _recipient: PublicKey, _context: MessageContext, _peers: Vec<PublicKey>, _secp_ctx: &Secp256k1<T>
178
+ /// # &self, _params: BlindedPathParams, _recipient: PublicKey, _context: MessageContext, _peers: Vec<PublicKey>, _secp_ctx: &Secp256k1<T>
179
179
/// # ) -> Result<Vec<BlindedMessagePath>, ()> {
180
180
/// # unreachable!()
181
181
/// # }
@@ -421,7 +421,7 @@ pub struct PendingOnionMessage<T: OnionMessageContents> {
421
421
///
422
422
/// PATHS_PLACEHOLDER` is temporarily used as a default value in situations
423
423
/// where a path index is required but has not yet been assigned or initialized.
424
- pub const PATHS_PLACEHOLDER : usize = 0 ;
424
+ pub const PATHS_PLACEHOLDER : usize = 3 ;
425
425
426
426
/// Represents the types of [`BlindedPath`] that can be created.
427
427
///
@@ -461,7 +461,7 @@ pub trait MessageRouter {
461
461
fn create_blinded_paths <
462
462
T : secp256k1:: Signing + secp256k1:: Verification
463
463
> (
464
- & self , recipient : PublicKey , context : MessageContext , peers : Vec < PublicKey > , secp_ctx : & Secp256k1 < T > ,
464
+ & self , params : BlindedPathParams , recipient : PublicKey , context : MessageContext , peers : Vec < PublicKey > , secp_ctx : & Secp256k1 < T > ,
465
465
) -> Result < Vec < BlindedMessagePath > , ( ) > ;
466
466
467
467
/// Creates compact [`BlindedMessagePath`]s to the `recipient` node. The nodes in `peers` are
@@ -487,7 +487,13 @@ pub trait MessageRouter {
487
487
. into_iter ( )
488
488
. map ( |ForwardNode { node_id, short_channel_id : _ } | node_id)
489
489
. collect ( ) ;
490
- self . create_blinded_paths ( recipient, context, peers, secp_ctx)
490
+
491
+ // This parameter is a placeholder. This function is removed in the subsequent commits.
492
+ let params = BlindedPathParams {
493
+ paths : PATHS_PLACEHOLDER ,
494
+ is_compact : true ,
495
+ } ;
496
+ self . create_blinded_paths ( params, recipient, context, peers, secp_ctx)
491
497
}
492
498
}
493
499
@@ -522,12 +528,9 @@ where
522
528
I : ExactSizeIterator < Item = ForwardNode > ,
523
529
T : secp256k1:: Signing + secp256k1:: Verification
524
530
> (
525
- network_graph : & G , recipient : PublicKey , context : MessageContext , peers : I ,
526
- entropy_source : & ES , secp_ctx : & Secp256k1 < T > , compact_paths : bool ,
531
+ params : BlindedPathParams , network_graph : & G , recipient : PublicKey , context : MessageContext , peers : I ,
532
+ entropy_source : & ES , secp_ctx : & Secp256k1 < T >
527
533
) -> Result < Vec < BlindedMessagePath > , ( ) > {
528
- // Limit the number of blinded paths that are computed.
529
- const MAX_PATHS : usize = 3 ;
530
-
531
534
// Ensure peers have at least three channels so that it is more difficult to infer the
532
535
// recipient's node_id.
533
536
const MIN_PEER_CHANNELS : usize = 3 ;
@@ -564,7 +567,7 @@ where
564
567
. map ( |( peer, _, _) | {
565
568
BlindedMessagePath :: new ( & [ peer] , recipient, context. clone ( ) , & * * entropy_source, secp_ctx)
566
569
} )
567
- . take ( MAX_PATHS )
570
+ . take ( params . paths )
568
571
. collect :: < Result < Vec < _ > , _ > > ( ) ;
569
572
570
573
let mut paths = match paths {
@@ -579,7 +582,7 @@ where
579
582
} ,
580
583
} ?;
581
584
582
- if compact_paths {
585
+ if params . is_compact {
583
586
for path in & mut paths {
584
587
path. use_compact_introduction_node ( & network_graph) ;
585
588
}
@@ -624,13 +627,13 @@ where
624
627
pub ( crate ) fn create_blinded_paths <
625
628
T : secp256k1:: Signing + secp256k1:: Verification
626
629
> (
627
- network_graph : & G , recipient : PublicKey , context : MessageContext ,
630
+ params : BlindedPathParams , network_graph : & G , recipient : PublicKey , context : MessageContext ,
628
631
peers : Vec < PublicKey > , entropy_source : & ES , secp_ctx : & Secp256k1 < T > ,
629
632
) -> Result < Vec < BlindedMessagePath > , ( ) > {
630
633
let peers = peers
631
634
. into_iter ( )
632
635
. map ( |node_id| ForwardNode { node_id, short_channel_id : None } ) ;
633
- Self :: create_blinded_paths_from_iter ( network_graph, recipient, context, peers. into_iter ( ) , entropy_source, secp_ctx, false )
636
+ Self :: create_blinded_paths_from_iter ( params , network_graph, recipient, context, peers. into_iter ( ) , entropy_source, secp_ctx)
634
637
}
635
638
636
639
pub ( crate ) fn create_compact_blinded_paths <
@@ -639,7 +642,11 @@ where
639
642
network_graph : & G , recipient : PublicKey , context : MessageContext ,
640
643
peers : Vec < ForwardNode > , entropy_source : & ES , secp_ctx : & Secp256k1 < T > ,
641
644
) -> Result < Vec < BlindedMessagePath > , ( ) > {
642
- Self :: create_blinded_paths_from_iter ( network_graph, recipient, context, peers. into_iter ( ) , entropy_source, secp_ctx, true )
645
+ let params = BlindedPathParams {
646
+ paths : PATHS_PLACEHOLDER ,
647
+ is_compact : true ,
648
+ } ;
649
+ Self :: create_blinded_paths_from_iter ( params, network_graph, recipient, context, peers. into_iter ( ) , entropy_source, secp_ctx)
643
650
}
644
651
}
645
652
@@ -657,9 +664,9 @@ where
657
664
fn create_blinded_paths <
658
665
T : secp256k1:: Signing + secp256k1:: Verification
659
666
> (
660
- & self , recipient : PublicKey , context : MessageContext , peers : Vec < PublicKey > , secp_ctx : & Secp256k1 < T > ,
667
+ & self , params : BlindedPathParams , recipient : PublicKey , context : MessageContext , peers : Vec < PublicKey > , secp_ctx : & Secp256k1 < T > ,
661
668
) -> Result < Vec < BlindedMessagePath > , ( ) > {
662
- Self :: create_blinded_paths ( & self . network_graph , recipient, context, peers, & self . entropy_source , secp_ctx)
669
+ Self :: create_blinded_paths ( params , & self . network_graph , recipient, context, peers, & self . entropy_source , secp_ctx)
663
670
}
664
671
665
672
fn create_compact_blinded_paths <
@@ -1235,7 +1242,7 @@ where
1235
1242
. map_err ( |_| SendError :: PathNotFound )
1236
1243
}
1237
1244
1238
- fn create_blinded_path ( & self , context : MessageContext ) -> Result < BlindedMessagePath , SendError > {
1245
+ fn create_blinded_path ( & self , params : BlindedPathParams , context : MessageContext ) -> Result < BlindedMessagePath , SendError > {
1239
1246
let recipient = self . node_signer
1240
1247
. get_node_id ( Recipient :: Node )
1241
1248
. map_err ( |_| SendError :: GetNodeIdFailed ) ?;
@@ -1248,7 +1255,7 @@ where
1248
1255
. collect :: < Vec < _ > > ( ) ;
1249
1256
1250
1257
self . message_router
1251
- . create_blinded_paths ( recipient, context, peers, secp_ctx)
1258
+ . create_blinded_paths ( params , recipient, context, peers, secp_ctx)
1252
1259
. and_then ( |paths| paths. into_iter ( ) . next ( ) . ok_or ( ( ) ) )
1253
1260
. map_err ( |_| SendError :: PathNotFound )
1254
1261
}
@@ -1346,7 +1353,11 @@ where
1346
1353
1347
1354
let message_type = response. message . msg_type ( ) ;
1348
1355
let reply_path = if let Some ( context) = context {
1349
- match self . create_blinded_path ( context) {
1356
+ let params = BlindedPathParams {
1357
+ paths : PATHS_PLACEHOLDER ,
1358
+ is_compact : false ,
1359
+ } ;
1360
+ match self . create_blinded_path ( params, context) {
1350
1361
Ok ( reply_path) => Some ( reply_path) ,
1351
1362
Err ( err) => {
1352
1363
log_trace ! (
0 commit comments