@@ -2413,8 +2413,16 @@ where
2413
2413
} )
2414
2414
}
2415
2415
2416
- // Only public for testing, this should otherwise never be called direcly
2417
- pub ( crate ) fn send_payment_along_path ( & self , path : & Vec < RouteHop > , payment_params : & Option < PaymentParameters > , payment_hash : & PaymentHash , payment_secret : & Option < PaymentSecret > , total_value : u64 , cur_height : u32 , payment_id : PaymentId , keysend_preimage : & Option < PaymentPreimage > , session_priv_bytes : [ u8 ; 32 ] ) -> Result < ( ) , APIError > {
2416
+ #[ cfg( test) ]
2417
+ pub ( crate ) fn test_send_payment_along_path ( & self , path : & Vec < RouteHop > , payment_params : & Option < PaymentParameters > , payment_hash : & PaymentHash , payment_secret : & Option < PaymentSecret > , total_value : u64 , cur_height : u32 , payment_id : PaymentId , keysend_preimage : & Option < PaymentPreimage > , session_priv_bytes : [ u8 ; 32 ] ) -> Result < ( ) , APIError > {
2418
+ let _lck = self . total_consistency_lock . read ( ) . unwrap ( ) ;
2419
+ self . send_payment_along_path ( path, payment_params, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv_bytes)
2420
+ }
2421
+
2422
+ fn send_payment_along_path ( & self , path : & Vec < RouteHop > , payment_params : & Option < PaymentParameters > , payment_hash : & PaymentHash , payment_secret : & Option < PaymentSecret > , total_value : u64 , cur_height : u32 , payment_id : PaymentId , keysend_preimage : & Option < PaymentPreimage > , session_priv_bytes : [ u8 ; 32 ] ) -> Result < ( ) , APIError > {
2423
+ // The top-level caller should hold the total_consistency_lock read lock.
2424
+ debug_assert ! ( self . total_consistency_lock. try_write( ) . is_err( ) ) ;
2425
+
2418
2426
log_trace ! ( self . logger, "Attempting to send payment for path with next hop {}" , path. first( ) . unwrap( ) . short_channel_id) ;
2419
2427
let prng_seed = self . entropy_source . get_secure_random_bytes ( ) ;
2420
2428
let session_priv = SecretKey :: from_slice ( & session_priv_bytes[ ..] ) . expect ( "RNG is busted" ) ;
@@ -2427,8 +2435,6 @@ where
2427
2435
}
2428
2436
let onion_packet = onion_utils:: construct_onion_packet ( onion_payloads, onion_keys, prng_seed, payment_hash) ;
2429
2437
2430
- let _persistence_guard = PersistenceNotifierGuard :: notify_on_drop ( & self . total_consistency_lock , & self . persistence_notifier ) ;
2431
-
2432
2438
let err: Result < ( ) , _ > = loop {
2433
2439
let ( counterparty_node_id, id) = match self . short_to_chan_info . read ( ) . unwrap ( ) . get ( & path. first ( ) . unwrap ( ) . short_channel_id ) {
2434
2440
None => return Err ( APIError :: ChannelUnavailable { err : "No channel available with first hop!" . to_owned ( ) } ) ,
@@ -2555,6 +2561,7 @@ where
2555
2561
/// [`ChannelMonitorUpdateStatus::InProgress`]: crate::chain::ChannelMonitorUpdateStatus::InProgress
2556
2562
pub fn send_payment ( & self , route : & Route , payment_hash : PaymentHash , payment_secret : & Option < PaymentSecret > , payment_id : PaymentId ) -> Result < ( ) , PaymentSendFailure > {
2557
2563
let best_block_height = self . best_block . read ( ) . unwrap ( ) . height ( ) ;
2564
+ let _persistence_guard = PersistenceNotifierGuard :: notify_on_drop ( & self . total_consistency_lock , & self . persistence_notifier ) ;
2558
2565
self . pending_outbound_payments
2559
2566
. send_payment_with_route ( route, payment_hash, payment_secret, payment_id, & self . entropy_source , & self . node_signer , best_block_height,
2560
2567
|path, payment_params, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv|
@@ -2565,6 +2572,7 @@ where
2565
2572
/// `route_params` and retry failed payment paths based on `retry_strategy`.
2566
2573
pub fn send_payment_with_retry ( & self , payment_hash : PaymentHash , payment_secret : & Option < PaymentSecret > , payment_id : PaymentId , route_params : RouteParameters , retry_strategy : Retry ) -> Result < ( ) , RetryableSendFailure > {
2567
2574
let best_block_height = self . best_block . read ( ) . unwrap ( ) . height ( ) ;
2575
+ let _persistence_guard = PersistenceNotifierGuard :: notify_on_drop ( & self . total_consistency_lock , & self . persistence_notifier ) ;
2568
2576
self . pending_outbound_payments
2569
2577
. send_payment ( payment_hash, payment_secret, payment_id, retry_strategy, route_params,
2570
2578
& self . router , self . list_usable_channels ( ) , || self . compute_inflight_htlcs ( ) ,
@@ -2577,6 +2585,7 @@ where
2577
2585
#[ cfg( test) ]
2578
2586
fn test_send_payment_internal ( & self , route : & Route , payment_hash : PaymentHash , payment_secret : & Option < PaymentSecret > , keysend_preimage : Option < PaymentPreimage > , payment_id : PaymentId , recv_value_msat : Option < u64 > , onion_session_privs : Vec < [ u8 ; 32 ] > ) -> Result < ( ) , PaymentSendFailure > {
2579
2587
let best_block_height = self . best_block . read ( ) . unwrap ( ) . height ( ) ;
2588
+ let _persistence_guard = PersistenceNotifierGuard :: notify_on_drop ( & self . total_consistency_lock , & self . persistence_notifier ) ;
2580
2589
self . pending_outbound_payments . test_send_payment_internal ( route, payment_hash, payment_secret, keysend_preimage, payment_id, recv_value_msat, onion_session_privs, & self . node_signer , best_block_height,
2581
2590
|path, payment_params, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv|
2582
2591
self . send_payment_along_path ( path, payment_params, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv) )
@@ -2627,6 +2636,7 @@ where
2627
2636
/// [`send_payment`]: Self::send_payment
2628
2637
pub fn send_spontaneous_payment ( & self , route : & Route , payment_preimage : Option < PaymentPreimage > , payment_id : PaymentId ) -> Result < PaymentHash , PaymentSendFailure > {
2629
2638
let best_block_height = self . best_block . read ( ) . unwrap ( ) . height ( ) ;
2639
+ let _persistence_guard = PersistenceNotifierGuard :: notify_on_drop ( & self . total_consistency_lock , & self . persistence_notifier ) ;
2630
2640
self . pending_outbound_payments . send_spontaneous_payment_with_route (
2631
2641
route, payment_preimage, payment_id, & self . entropy_source , & self . node_signer ,
2632
2642
best_block_height,
@@ -2643,6 +2653,7 @@ where
2643
2653
/// [`PaymentParameters::for_keysend`]: crate::routing::router::PaymentParameters::for_keysend
2644
2654
pub fn send_spontaneous_payment_with_retry ( & self , payment_preimage : Option < PaymentPreimage > , payment_id : PaymentId , route_params : RouteParameters , retry_strategy : Retry ) -> Result < PaymentHash , RetryableSendFailure > {
2645
2655
let best_block_height = self . best_block . read ( ) . unwrap ( ) . height ( ) ;
2656
+ let _persistence_guard = PersistenceNotifierGuard :: notify_on_drop ( & self . total_consistency_lock , & self . persistence_notifier ) ;
2646
2657
self . pending_outbound_payments . send_spontaneous_payment ( payment_preimage, payment_id,
2647
2658
retry_strategy, route_params, & self . router , self . list_usable_channels ( ) ,
2648
2659
|| self . compute_inflight_htlcs ( ) , & self . entropy_source , & self . node_signer , best_block_height,
@@ -2656,6 +2667,7 @@ where
2656
2667
/// us to easily discern them from real payments.
2657
2668
pub fn send_probe ( & self , hops : Vec < RouteHop > ) -> Result < ( PaymentHash , PaymentId ) , PaymentSendFailure > {
2658
2669
let best_block_height = self . best_block . read ( ) . unwrap ( ) . height ( ) ;
2670
+ let _persistence_guard = PersistenceNotifierGuard :: notify_on_drop ( & self . total_consistency_lock , & self . persistence_notifier ) ;
2659
2671
self . pending_outbound_payments . send_probe ( hops, self . probing_cookie_secret , & self . entropy_source , & self . node_signer , best_block_height,
2660
2672
|path, payment_params, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv|
2661
2673
self . send_payment_along_path ( path, payment_params, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv) )
@@ -7841,7 +7853,7 @@ mod tests {
7841
7853
// indicates there are more HTLCs coming.
7842
7854
let cur_height = CHAN_CONFIRM_DEPTH + 1 ; // route_payment calls send_payment, which adds 1 to the current height. So we do the same here to match.
7843
7855
let session_privs = nodes[ 0 ] . node . test_add_new_pending_payment ( our_payment_hash, Some ( payment_secret) , payment_id, & mpp_route) . unwrap ( ) ;
7844
- nodes[ 0 ] . node . send_payment_along_path ( & mpp_route. paths [ 0 ] , & route. payment_params , & our_payment_hash, & Some ( payment_secret) , 200_000 , cur_height, payment_id, & None , session_privs[ 0 ] ) . unwrap ( ) ;
7856
+ nodes[ 0 ] . node . test_send_payment_along_path ( & mpp_route. paths [ 0 ] , & route. payment_params , & our_payment_hash, & Some ( payment_secret) , 200_000 , cur_height, payment_id, & None , session_privs[ 0 ] ) . unwrap ( ) ;
7845
7857
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
7846
7858
let mut events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
7847
7859
assert_eq ! ( events. len( ) , 1 ) ;
@@ -7871,7 +7883,7 @@ mod tests {
7871
7883
expect_payment_failed ! ( nodes[ 0 ] , our_payment_hash, true ) ;
7872
7884
7873
7885
// Send the second half of the original MPP payment.
7874
- nodes[ 0 ] . node . send_payment_along_path ( & mpp_route. paths [ 1 ] , & route. payment_params , & our_payment_hash, & Some ( payment_secret) , 200_000 , cur_height, payment_id, & None , session_privs[ 1 ] ) . unwrap ( ) ;
7886
+ nodes[ 0 ] . node . test_send_payment_along_path ( & mpp_route. paths [ 1 ] , & route. payment_params , & our_payment_hash, & Some ( payment_secret) , 200_000 , cur_height, payment_id, & None , session_privs[ 1 ] ) . unwrap ( ) ;
7875
7887
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
7876
7888
let mut events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
7877
7889
assert_eq ! ( events. len( ) , 1 ) ;
0 commit comments