@@ -402,7 +402,7 @@ struct PendingInboundPayment {
402
402
403
403
/// Stores the session_priv for each part of a payment that is still pending. For versions 0.0.102
404
404
/// and later, also stores information for retrying the payment.
405
- enum PendingOutboundPayment {
405
+ pub ( crate ) enum PendingOutboundPayment {
406
406
Legacy {
407
407
session_privs : HashSet < [ u8 ; 32 ] > ,
408
408
} ,
@@ -557,6 +557,9 @@ pub struct ChannelManager<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref,
557
557
/// See `PendingOutboundPayment` documentation for more info.
558
558
///
559
559
/// Locked *after* channel_state.
560
+ #[ cfg( test) ] // Exposed so that we can check there aren't dangling entries
561
+ pub ( crate ) pending_outbound_payments : Mutex < HashMap < PaymentId , PendingOutboundPayment > > ,
562
+ #[ cfg( not( test) ) ]
560
563
pending_outbound_payments : Mutex < HashMap < PaymentId , PendingOutboundPayment > > ,
561
564
562
565
our_network_key : SecretKey ,
@@ -1951,16 +1954,6 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
1951
1954
let onion_packet = onion_utils:: construct_onion_packet ( onion_payloads, onion_keys, prng_seed, payment_hash) ;
1952
1955
1953
1956
let _persistence_guard = PersistenceNotifierGuard :: notify_on_drop ( & self . total_consistency_lock , & self . persistence_notifier ) ;
1954
- let mut pending_outbounds = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
1955
- let payment = pending_outbounds. entry ( payment_id) . or_insert_with ( || PendingOutboundPayment :: Retryable {
1956
- session_privs : HashSet :: new ( ) ,
1957
- pending_amt_msat : 0 ,
1958
- payment_hash : * payment_hash,
1959
- payment_secret : * payment_secret,
1960
- starting_block_height : self . best_block . read ( ) . unwrap ( ) . height ( ) ,
1961
- total_msat : total_value,
1962
- } ) ;
1963
- assert ! ( payment. insert( session_priv_bytes, path. last( ) . unwrap( ) . fee_msat) ) ;
1964
1957
1965
1958
let err: Result < ( ) , _ > = loop {
1966
1959
let mut channel_lock = self . channel_state . lock ( ) . unwrap ( ) ;
@@ -1978,12 +1971,28 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
1978
1971
if !chan. get ( ) . is_live ( ) {
1979
1972
return Err ( APIError :: ChannelUnavailable { err : "Peer for first hop currently disconnected/pending monitor update!" . to_owned ( ) } ) ;
1980
1973
}
1981
- break_chan_entry ! ( self , chan. get_mut( ) . send_htlc_and_commit( htlc_msat, payment_hash. clone( ) , htlc_cltv, HTLCSource :: OutboundRoute {
1982
- path: path. clone( ) ,
1983
- session_priv: session_priv. clone( ) ,
1984
- first_hop_htlc_msat: htlc_msat,
1985
- payment_id,
1986
- } , onion_packet, & self . logger) , channel_state, chan)
1974
+ let send_res =
1975
+ break_chan_entry ! ( self , chan. get_mut( ) . send_htlc_and_commit(
1976
+ htlc_msat, payment_hash. clone( ) , htlc_cltv, HTLCSource :: OutboundRoute {
1977
+ path: path. clone( ) ,
1978
+ session_priv: session_priv. clone( ) ,
1979
+ first_hop_htlc_msat: htlc_msat,
1980
+ payment_id,
1981
+ } , onion_packet, & self . logger) ,
1982
+ channel_state, chan) ;
1983
+
1984
+ let mut pending_outbounds = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
1985
+ let payment = pending_outbounds. entry ( payment_id) . or_insert_with ( || PendingOutboundPayment :: Retryable {
1986
+ session_privs : HashSet :: new ( ) ,
1987
+ pending_amt_msat : 0 ,
1988
+ payment_hash : * payment_hash,
1989
+ payment_secret : * payment_secret,
1990
+ starting_block_height : self . best_block . read ( ) . unwrap ( ) . height ( ) ,
1991
+ total_msat : total_value,
1992
+ } ) ;
1993
+ assert ! ( payment. insert( session_priv_bytes, path. last( ) . unwrap( ) . fee_msat) ) ;
1994
+
1995
+ send_res
1987
1996
} {
1988
1997
Some ( ( update_add, commitment_signed, monitor_update) ) => {
1989
1998
if let Err ( e) = self . chain_monitor . update_channel ( chan. get ( ) . get_funding_txo ( ) . unwrap ( ) , monitor_update) {
0 commit comments