@@ -151,7 +151,7 @@ for OnionMessenger<ES, NS, L, NL, MR, OMH, APH, CMH> where
151
151
/// # use lightning::blinded_path::message::{BlindedMessagePath, MessageForwardNode, MessageContext};
152
152
/// # use lightning::sign::{EntropySource, KeysManager};
153
153
/// # use lightning::ln::peer_handler::IgnoringMessageHandler;
154
- /// # use lightning::onion_message::messenger::{Destination, MessageRouter, MessageSendInstructions, OnionMessagePath, OnionMessenger};
154
+ /// # use lightning::onion_message::messenger::{BlindedPathParams, Destination, MessageRouter, MessageSendInstructions, 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
/// # }
@@ -436,7 +436,7 @@ pub enum MessageSendInstructions {
436
436
///
437
437
/// PATHS_PLACEHOLDER` is temporarily used as a default value in situations
438
438
/// where a path index is required but has not yet been assigned or initialized.
439
- pub const PATHS_PLACEHOLDER : usize = 0 ;
439
+ pub const PATHS_PLACEHOLDER : usize = 3 ;
440
440
441
441
/// Represents the types of [`BlindedMessagePath`] that can be created.
442
442
///
@@ -460,7 +460,7 @@ pub trait MessageRouter {
460
460
fn create_blinded_paths <
461
461
T : secp256k1:: Signing + secp256k1:: Verification
462
462
> (
463
- & self , recipient : PublicKey , context : MessageContext , peers : Vec < PublicKey > , secp_ctx : & Secp256k1 < T > ,
463
+ & self , params : BlindedPathParams , recipient : PublicKey , context : MessageContext , peers : Vec < PublicKey > , secp_ctx : & Secp256k1 < T > ,
464
464
) -> Result < Vec < BlindedMessagePath > , ( ) > ;
465
465
466
466
/// Creates compact [`BlindedMessagePath`]s to the `recipient` node. The nodes in `peers` are
@@ -486,7 +486,13 @@ pub trait MessageRouter {
486
486
. into_iter ( )
487
487
. map ( |MessageForwardNode { node_id, short_channel_id : _ } | node_id)
488
488
. collect ( ) ;
489
- self . create_blinded_paths ( recipient, context, peers, secp_ctx)
489
+
490
+ // This parameter is a placeholder. This function is removed in the subsequent commits.
491
+ let params = BlindedPathParams {
492
+ paths : PATHS_PLACEHOLDER ,
493
+ is_compact : true ,
494
+ } ;
495
+ self . create_blinded_paths ( params, recipient, context, peers, secp_ctx)
490
496
}
491
497
}
492
498
@@ -521,12 +527,9 @@ where
521
527
I : ExactSizeIterator < Item = MessageForwardNode > ,
522
528
T : secp256k1:: Signing + secp256k1:: Verification
523
529
> (
524
- network_graph : & G , recipient : PublicKey , context : MessageContext , peers : I ,
525
- entropy_source : & ES , secp_ctx : & Secp256k1 < T > , compact_paths : bool ,
530
+ params : BlindedPathParams , network_graph : & G , recipient : PublicKey , context : MessageContext , peers : I ,
531
+ entropy_source : & ES , secp_ctx : & Secp256k1 < T >
526
532
) -> Result < Vec < BlindedMessagePath > , ( ) > {
527
- // Limit the number of blinded paths that are computed.
528
- const MAX_PATHS : usize = 3 ;
529
-
530
533
// Ensure peers have at least three channels so that it is more difficult to infer the
531
534
// recipient's node_id.
532
535
const MIN_PEER_CHANNELS : usize = 3 ;
@@ -563,7 +566,7 @@ where
563
566
. map ( |( peer, _, _) | {
564
567
BlindedMessagePath :: new ( & [ peer] , recipient, context. clone ( ) , & * * entropy_source, secp_ctx)
565
568
} )
566
- . take ( MAX_PATHS )
569
+ . take ( params . paths )
567
570
. collect :: < Result < Vec < _ > , _ > > ( ) ;
568
571
569
572
let mut paths = match paths {
@@ -578,7 +581,7 @@ where
578
581
} ,
579
582
} ?;
580
583
581
- if compact_paths {
584
+ if params . is_compact {
582
585
for path in & mut paths {
583
586
path. use_compact_introduction_node ( & network_graph) ;
584
587
}
@@ -623,13 +626,13 @@ where
623
626
pub ( crate ) fn create_blinded_paths <
624
627
T : secp256k1:: Signing + secp256k1:: Verification
625
628
> (
626
- network_graph : & G , recipient : PublicKey , context : MessageContext ,
629
+ params : BlindedPathParams , network_graph : & G , recipient : PublicKey , context : MessageContext ,
627
630
peers : Vec < PublicKey > , entropy_source : & ES , secp_ctx : & Secp256k1 < T > ,
628
631
) -> Result < Vec < BlindedMessagePath > , ( ) > {
629
632
let peers = peers
630
633
. into_iter ( )
631
634
. map ( |node_id| MessageForwardNode { node_id, short_channel_id : None } ) ;
632
- Self :: create_blinded_paths_from_iter ( network_graph, recipient, context, peers. into_iter ( ) , entropy_source, secp_ctx, false )
635
+ Self :: create_blinded_paths_from_iter ( params , network_graph, recipient, context, peers. into_iter ( ) , entropy_source, secp_ctx)
633
636
}
634
637
635
638
pub ( crate ) fn create_compact_blinded_paths <
@@ -638,7 +641,11 @@ where
638
641
network_graph : & G , recipient : PublicKey , context : MessageContext ,
639
642
peers : Vec < MessageForwardNode > , entropy_source : & ES , secp_ctx : & Secp256k1 < T > ,
640
643
) -> Result < Vec < BlindedMessagePath > , ( ) > {
641
- Self :: create_blinded_paths_from_iter ( network_graph, recipient, context, peers. into_iter ( ) , entropy_source, secp_ctx, true )
644
+ let params = BlindedPathParams {
645
+ paths : PATHS_PLACEHOLDER ,
646
+ is_compact : true ,
647
+ } ;
648
+ Self :: create_blinded_paths_from_iter ( params, network_graph, recipient, context, peers. into_iter ( ) , entropy_source, secp_ctx)
642
649
}
643
650
}
644
651
@@ -656,9 +663,9 @@ where
656
663
fn create_blinded_paths <
657
664
T : secp256k1:: Signing + secp256k1:: Verification
658
665
> (
659
- & self , recipient : PublicKey , context : MessageContext , peers : Vec < PublicKey > , secp_ctx : & Secp256k1 < T > ,
666
+ & self , params : BlindedPathParams , recipient : PublicKey , context : MessageContext , peers : Vec < PublicKey > , secp_ctx : & Secp256k1 < T > ,
660
667
) -> Result < Vec < BlindedMessagePath > , ( ) > {
661
- Self :: create_blinded_paths ( & self . network_graph , recipient, context, peers, & self . entropy_source , secp_ctx)
668
+ Self :: create_blinded_paths ( params , & self . network_graph , recipient, context, peers, & self . entropy_source , secp_ctx)
662
669
}
663
670
664
671
fn create_compact_blinded_paths <
@@ -1185,7 +1192,11 @@ where
1185
1192
MessageSendInstructions :: WithReplyPath { destination, context }
1186
1193
|MessageSendInstructions :: ForReply { instructions : ResponseInstruction { destination, context : Some ( context) } } =>
1187
1194
{
1188
- match self . create_blinded_path ( context) {
1195
+ let params = BlindedPathParams {
1196
+ paths : PATHS_PLACEHOLDER ,
1197
+ is_compact : false ,
1198
+ } ;
1199
+ match self . create_blinded_path ( params, context) {
1189
1200
Ok ( reply_path) => ( destination, Some ( reply_path) ) ,
1190
1201
Err ( err) => {
1191
1202
log_trace ! (
@@ -1250,7 +1261,7 @@ where
1250
1261
. map_err ( |_| SendError :: PathNotFound )
1251
1262
}
1252
1263
1253
- fn create_blinded_path ( & self , context : MessageContext ) -> Result < BlindedMessagePath , SendError > {
1264
+ fn create_blinded_path ( & self , params : BlindedPathParams , context : MessageContext ) -> Result < BlindedMessagePath , SendError > {
1254
1265
let recipient = self . node_signer
1255
1266
. get_node_id ( Recipient :: Node )
1256
1267
. map_err ( |_| SendError :: GetNodeIdFailed ) ?;
@@ -1263,7 +1274,7 @@ where
1263
1274
. collect :: < Vec < _ > > ( ) ;
1264
1275
1265
1276
self . message_router
1266
- . create_blinded_paths ( recipient, context, peers, secp_ctx)
1277
+ . create_blinded_paths ( params , recipient, context, peers, secp_ctx)
1267
1278
. and_then ( |paths| paths. into_iter ( ) . next ( ) . ok_or ( ( ) ) )
1268
1279
. map_err ( |_| SendError :: PathNotFound )
1269
1280
}
0 commit comments