@@ -13,6 +13,8 @@ use bitcoin::hashes::Hash;
13
13
use bitcoin:: hashes:: sha256:: Hash as Sha256 ;
14
14
use bitcoin:: secp256k1:: { self , Secp256k1 , SecretKey } ;
15
15
16
+ use crate :: blinded_path:: { IntroductionNode , NodeIdLookUp } ;
17
+ use crate :: blinded_path:: payment:: advance_path_by_one;
16
18
use crate :: events:: { self , PaymentFailureReason } ;
17
19
use crate :: ln:: types:: { PaymentHash , PaymentPreimage , PaymentSecret } ;
18
20
use crate :: ln:: channel_state:: ChannelDetails ;
@@ -775,17 +777,21 @@ impl OutboundPayments {
775
777
}
776
778
}
777
779
778
- pub ( super ) fn send_payment_for_bolt12_invoice < R : Deref , ES : Deref , NS : Deref , IH , SP , L : Deref > (
780
+ pub ( super ) fn send_payment_for_bolt12_invoice <
781
+ R : Deref , ES : Deref , NS : Deref , NL : Deref , IH , SP , L : Deref
782
+ > (
779
783
& self , invoice : & Bolt12Invoice , payment_id : PaymentId , router : & R ,
780
784
first_hops : Vec < ChannelDetails > , inflight_htlcs : IH , entropy_source : & ES , node_signer : & NS ,
781
- best_block_height : u32 , logger : & L ,
785
+ node_id_lookup : & NL , secp_ctx : & Secp256k1 < secp256k1:: All > , best_block_height : u32 ,
786
+ logger : & L ,
782
787
pending_events : & Mutex < VecDeque < ( events:: Event , Option < EventCompletionAction > ) > > ,
783
788
send_payment_along_path : SP ,
784
789
) -> Result < ( ) , Bolt12PaymentError >
785
790
where
786
791
R :: Target : Router ,
787
792
ES :: Target : EntropySource ,
788
793
NS :: Target : NodeSigner ,
794
+ NL :: Target : NodeIdLookUp ,
789
795
L :: Target : Logger ,
790
796
IH : Fn ( ) -> InFlightHtlcs ,
791
797
SP : Fn ( SendAlongPathArgs ) -> Result < ( ) , APIError > ,
@@ -807,7 +813,26 @@ impl OutboundPayments {
807
813
hash_map:: Entry :: Vacant ( _) => return Err ( Bolt12PaymentError :: UnexpectedInvoice ) ,
808
814
} ;
809
815
810
- let payment_params = PaymentParameters :: from_bolt12_invoice ( & invoice) ;
816
+ let mut payment_params = PaymentParameters :: from_bolt12_invoice ( & invoice) ;
817
+
818
+ // Advance any blinded path where the introduction node is our node.
819
+ if let Ok ( our_node_id) = node_signer. get_node_id ( Recipient :: Node ) {
820
+ for ( _, path) in payment_params. payee . blinded_route_hints_mut ( ) . iter_mut ( ) {
821
+ let introduction_node_id = match path. introduction_node {
822
+ IntroductionNode :: NodeId ( pubkey) => pubkey,
823
+ IntroductionNode :: DirectedShortChannelId ( direction, scid) => {
824
+ match node_id_lookup. next_node_id ( scid) {
825
+ Some ( next_node_id) => * direction. select_pubkey ( & our_node_id, & next_node_id) ,
826
+ None => continue ,
827
+ }
828
+ } ,
829
+ } ;
830
+ if introduction_node_id == our_node_id {
831
+ let _ = advance_path_by_one ( path, node_signer, node_id_lookup, secp_ctx) ;
832
+ }
833
+ }
834
+ }
835
+
811
836
let amount_msat = invoice. amount_msats ( ) ;
812
837
let mut route_params = RouteParameters :: from_payment_params_and_value (
813
838
payment_params, amount_msat
@@ -1858,6 +1883,7 @@ mod tests {
1858
1883
1859
1884
use core:: time:: Duration ;
1860
1885
1886
+ use crate :: blinded_path:: EmptyNodeIdLookUp ;
1861
1887
use crate :: events:: { Event , PathFailure , PaymentFailureReason } ;
1862
1888
use crate :: ln:: types:: PaymentHash ;
1863
1889
use crate :: ln:: channelmanager:: { PaymentId , RecipientOnionFields } ;
@@ -2201,6 +2227,7 @@ mod tests {
2201
2227
let network_graph = Arc :: new ( NetworkGraph :: new ( Network :: Testnet , & logger) ) ;
2202
2228
let scorer = RwLock :: new ( test_utils:: TestScorer :: new ( ) ) ;
2203
2229
let router = test_utils:: TestRouter :: new ( network_graph, & logger, & scorer) ;
2230
+ let secp_ctx = Secp256k1 :: new ( ) ;
2204
2231
let keys_manager = test_utils:: TestKeysInterface :: new ( & [ 0 ; 32 ] , Network :: Testnet ) ;
2205
2232
2206
2233
let pending_events = Mutex :: new ( VecDeque :: new ( ) ) ;
@@ -2229,7 +2256,8 @@ mod tests {
2229
2256
assert_eq ! (
2230
2257
outbound_payments. send_payment_for_bolt12_invoice(
2231
2258
& invoice, payment_id, &&router, vec![ ] , || InFlightHtlcs :: new( ) , &&keys_manager,
2232
- &&keys_manager, 0 , &&logger, & pending_events, |_| panic!( )
2259
+ &&keys_manager, & EmptyNodeIdLookUp { } , & secp_ctx, 0 , &&logger, & pending_events,
2260
+ |_| panic!( )
2233
2261
) ,
2234
2262
Ok ( ( ) ) ,
2235
2263
) ;
@@ -2252,6 +2280,7 @@ mod tests {
2252
2280
let network_graph = Arc :: new ( NetworkGraph :: new ( Network :: Testnet , & logger) ) ;
2253
2281
let scorer = RwLock :: new ( test_utils:: TestScorer :: new ( ) ) ;
2254
2282
let router = test_utils:: TestRouter :: new ( network_graph, & logger, & scorer) ;
2283
+ let secp_ctx = Secp256k1 :: new ( ) ;
2255
2284
let keys_manager = test_utils:: TestKeysInterface :: new ( & [ 0 ; 32 ] , Network :: Testnet ) ;
2256
2285
2257
2286
let pending_events = Mutex :: new ( VecDeque :: new ( ) ) ;
@@ -2288,7 +2317,8 @@ mod tests {
2288
2317
assert_eq ! (
2289
2318
outbound_payments. send_payment_for_bolt12_invoice(
2290
2319
& invoice, payment_id, &&router, vec![ ] , || InFlightHtlcs :: new( ) , &&keys_manager,
2291
- &&keys_manager, 0 , &&logger, & pending_events, |_| panic!( )
2320
+ &&keys_manager, & EmptyNodeIdLookUp { } , & secp_ctx, 0 , &&logger, & pending_events,
2321
+ |_| panic!( )
2292
2322
) ,
2293
2323
Ok ( ( ) ) ,
2294
2324
) ;
@@ -2311,6 +2341,7 @@ mod tests {
2311
2341
let network_graph = Arc :: new ( NetworkGraph :: new ( Network :: Testnet , & logger) ) ;
2312
2342
let scorer = RwLock :: new ( test_utils:: TestScorer :: new ( ) ) ;
2313
2343
let router = test_utils:: TestRouter :: new ( network_graph, & logger, & scorer) ;
2344
+ let secp_ctx = Secp256k1 :: new ( ) ;
2314
2345
let keys_manager = test_utils:: TestKeysInterface :: new ( & [ 0 ; 32 ] , Network :: Testnet ) ;
2315
2346
2316
2347
let pending_events = Mutex :: new ( VecDeque :: new ( ) ) ;
@@ -2360,7 +2391,8 @@ mod tests {
2360
2391
assert_eq ! (
2361
2392
outbound_payments. send_payment_for_bolt12_invoice(
2362
2393
& invoice, payment_id, &&router, vec![ ] , || InFlightHtlcs :: new( ) , &&keys_manager,
2363
- &&keys_manager, 0 , &&logger, & pending_events, |_| panic!( )
2394
+ &&keys_manager, & EmptyNodeIdLookUp { } , & secp_ctx, 0 , &&logger, & pending_events,
2395
+ |_| panic!( )
2364
2396
) ,
2365
2397
Err ( Bolt12PaymentError :: UnexpectedInvoice ) ,
2366
2398
) ;
@@ -2377,7 +2409,8 @@ mod tests {
2377
2409
assert_eq ! (
2378
2410
outbound_payments. send_payment_for_bolt12_invoice(
2379
2411
& invoice, payment_id, &&router, vec![ ] , || InFlightHtlcs :: new( ) , &&keys_manager,
2380
- &&keys_manager, 0 , &&logger, & pending_events, |_| Ok ( ( ) )
2412
+ &&keys_manager, & EmptyNodeIdLookUp { } , & secp_ctx, 0 , &&logger, & pending_events,
2413
+ |_| Ok ( ( ) )
2381
2414
) ,
2382
2415
Ok ( ( ) ) ,
2383
2416
) ;
@@ -2387,7 +2420,8 @@ mod tests {
2387
2420
assert_eq ! (
2388
2421
outbound_payments. send_payment_for_bolt12_invoice(
2389
2422
& invoice, payment_id, &&router, vec![ ] , || InFlightHtlcs :: new( ) , &&keys_manager,
2390
- &&keys_manager, 0 , &&logger, & pending_events, |_| panic!( )
2423
+ &&keys_manager, & EmptyNodeIdLookUp { } , & secp_ctx, 0 , &&logger, & pending_events,
2424
+ |_| panic!( )
2391
2425
) ,
2392
2426
Err ( Bolt12PaymentError :: DuplicateInvoice ) ,
2393
2427
) ;
0 commit comments