@@ -788,7 +788,7 @@ where
788
788
/// When acquiring this lock in read mode, rather than acquiring it directly, call
789
789
/// `PersistenceNotifierGuard::notify_on_drop(..)` and pass the lock to it, to ensure the
790
790
/// Notifier the lock contains sends out a notification when the lock is released.
791
- total_consistency_lock : RwLock < ( ) > ,
791
+ pub ( crate ) total_consistency_lock : RwLock < ( ) > ,
792
792
793
793
persistence_notifier : Notifier ,
794
794
@@ -2312,6 +2312,8 @@ where
2312
2312
2313
2313
// Only public for testing, this should otherwise never be called direcly
2314
2314
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 > {
2315
+ debug_assert ! ( self . total_consistency_lock. try_write( ) . is_err( ) ) ; // Caller should hold this
2316
+
2315
2317
log_trace ! ( self . logger, "Attempting to send payment for path with next hop {}" , path. first( ) . unwrap( ) . short_channel_id) ;
2316
2318
let prng_seed = self . entropy_source . get_secure_random_bytes ( ) ;
2317
2319
let session_priv = SecretKey :: from_slice ( & session_priv_bytes[ ..] ) . expect ( "RNG is busted" ) ;
@@ -2324,8 +2326,6 @@ where
2324
2326
}
2325
2327
let onion_packet = onion_utils:: construct_onion_packet ( onion_payloads, onion_keys, prng_seed, payment_hash) ;
2326
2328
2327
- let _persistence_guard = PersistenceNotifierGuard :: notify_on_drop ( & self . total_consistency_lock , & self . persistence_notifier ) ;
2328
-
2329
2329
let err: Result < ( ) , _ > = loop {
2330
2330
let ( counterparty_node_id, id) = match self . short_to_chan_info . read ( ) . unwrap ( ) . get ( & path. first ( ) . unwrap ( ) . short_channel_id ) {
2331
2331
None => return Err ( APIError :: ChannelUnavailable { err : "No channel available with first hop!" . to_owned ( ) } ) ,
@@ -2460,6 +2460,7 @@ where
2460
2460
/// [`PeerManager::process_events`]: crate::ln::peer_handler::PeerManager::process_events
2461
2461
pub fn send_payment ( & self , route : & Route , payment_hash : PaymentHash , payment_secret : & Option < PaymentSecret > , payment_id : PaymentId ) -> Result < ( ) , PaymentSendFailure > {
2462
2462
let best_block_height = self . best_block . read ( ) . unwrap ( ) . height ( ) ;
2463
+ let _persistence_guard = PersistenceNotifierGuard :: notify_on_drop ( & self . total_consistency_lock , & self . persistence_notifier ) ;
2463
2464
self . pending_outbound_payments
2464
2465
. send_payment_with_route ( route, payment_hash, payment_secret, payment_id, & self . entropy_source , & self . node_signer , best_block_height,
2465
2466
|path, payment_params, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv|
@@ -2470,6 +2471,7 @@ where
2470
2471
/// `route_params` and retry failed payment paths based on `retry_strategy`.
2471
2472
pub fn send_payment_with_retry ( & self , payment_hash : PaymentHash , payment_secret : & Option < PaymentSecret > , payment_id : PaymentId , route_params : RouteParameters , retry_strategy : Retry ) -> Result < ( ) , PaymentSendFailure > {
2472
2473
let best_block_height = self . best_block . read ( ) . unwrap ( ) . height ( ) ;
2474
+ let _persistence_guard = PersistenceNotifierGuard :: notify_on_drop ( & self . total_consistency_lock , & self . persistence_notifier ) ;
2473
2475
self . pending_outbound_payments
2474
2476
. send_payment ( payment_hash, payment_secret, payment_id, retry_strategy, route_params,
2475
2477
& self . router , self . list_usable_channels ( ) , self . compute_inflight_htlcs ( ) ,
@@ -2481,6 +2483,7 @@ where
2481
2483
#[ cfg( test) ]
2482
2484
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 > {
2483
2485
let best_block_height = self . best_block . read ( ) . unwrap ( ) . height ( ) ;
2486
+ let _persistence_guard = PersistenceNotifierGuard :: notify_on_drop ( & self . total_consistency_lock , & self . persistence_notifier ) ;
2484
2487
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,
2485
2488
|path, payment_params, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv|
2486
2489
self . send_payment_along_path ( path, payment_params, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv) )
@@ -2505,6 +2508,7 @@ where
2505
2508
/// [`abandon_payment`]: [`ChannelManager::abandon_payment`]
2506
2509
pub fn retry_payment ( & self , route : & Route , payment_id : PaymentId ) -> Result < ( ) , PaymentSendFailure > {
2507
2510
let best_block_height = self . best_block . read ( ) . unwrap ( ) . height ( ) ;
2511
+ let _persistence_guard = PersistenceNotifierGuard :: notify_on_drop ( & self . total_consistency_lock , & self . persistence_notifier ) ;
2508
2512
self . pending_outbound_payments . retry_payment_with_route ( route, payment_id, & self . entropy_source , & self . node_signer , best_block_height,
2509
2513
|path, payment_params, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv|
2510
2514
self . send_payment_along_path ( path, payment_params, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv) )
@@ -2554,6 +2558,7 @@ where
2554
2558
/// [`send_payment`]: Self::send_payment
2555
2559
pub fn send_spontaneous_payment ( & self , route : & Route , payment_preimage : Option < PaymentPreimage > , payment_id : PaymentId ) -> Result < PaymentHash , PaymentSendFailure > {
2556
2560
let best_block_height = self . best_block . read ( ) . unwrap ( ) . height ( ) ;
2561
+ let _persistence_guard = PersistenceNotifierGuard :: notify_on_drop ( & self . total_consistency_lock , & self . persistence_notifier ) ;
2557
2562
self . pending_outbound_payments . send_spontaneous_payment ( route, payment_preimage, payment_id, & self . entropy_source , & self . node_signer , best_block_height,
2558
2563
|path, payment_params, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv|
2559
2564
self . send_payment_along_path ( path, payment_params, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv) )
@@ -2564,6 +2569,7 @@ where
2564
2569
/// us to easily discern them from real payments.
2565
2570
pub fn send_probe ( & self , hops : Vec < RouteHop > ) -> Result < ( PaymentHash , PaymentId ) , PaymentSendFailure > {
2566
2571
let best_block_height = self . best_block . read ( ) . unwrap ( ) . height ( ) ;
2572
+ let _persistence_guard = PersistenceNotifierGuard :: notify_on_drop ( & self . total_consistency_lock , & self . persistence_notifier ) ;
2567
2573
self . pending_outbound_payments . send_probe ( hops, self . probing_cookie_secret , & self . entropy_source , & self . node_signer , best_block_height,
2568
2574
|path, payment_params, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv|
2569
2575
self . send_payment_along_path ( path, payment_params, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv) )
@@ -7751,7 +7757,10 @@ mod tests {
7751
7757
// indicates there are more HTLCs coming.
7752
7758
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.
7753
7759
let session_privs = nodes[ 0 ] . node . test_add_new_pending_payment ( our_payment_hash, Some ( payment_secret) , payment_id, & mpp_route) . unwrap ( ) ;
7754
- 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 ( ) ;
7760
+ {
7761
+ let _lck = nodes[ 0 ] . node . total_consistency_lock . read ( ) . unwrap ( ) ;
7762
+ 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 ( ) ;
7763
+ }
7755
7764
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
7756
7765
let mut events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
7757
7766
assert_eq ! ( events. len( ) , 1 ) ;
@@ -7781,7 +7790,10 @@ mod tests {
7781
7790
expect_payment_failed ! ( nodes[ 0 ] , our_payment_hash, true ) ;
7782
7791
7783
7792
// Send the second half of the original MPP payment.
7784
- 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 ( ) ;
7793
+ {
7794
+ let _lck = nodes[ 0 ] . node . total_consistency_lock . read ( ) . unwrap ( ) ;
7795
+ 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 ( ) ;
7796
+ }
7785
7797
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
7786
7798
let mut events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
7787
7799
assert_eq ! ( events. len( ) , 1 ) ;
0 commit comments