@@ -992,9 +992,9 @@ impl OutboundPayments {
992992 ) ;
993993 if let Err ( e) = result {
994994 self . handle_pay_route_err (
995- e, payment_id, payment_hash, route, route_params, router, first_hops,
996- & inflight_htlcs, entropy_source, node_signer, best_block_height, logger,
997- pending_events , & send_payment_along_path
995+ e, payment_id, payment_hash, route, route_params, onion_session_privs , router, first_hops,
996+ & inflight_htlcs, entropy_source, node_signer, best_block_height, logger, pending_events ,
997+ & send_payment_along_path
998998 ) ;
999999 }
10001000 Ok ( ( ) )
@@ -1274,7 +1274,11 @@ impl OutboundPayments {
12741274 log_info ! ( logger, "Sending payment with id {} and hash {} returned {:?}" ,
12751275 payment_id, payment_hash, res) ;
12761276 if let Err ( e) = res {
1277- self . handle_pay_route_err ( e, payment_id, payment_hash, route, route_params, router, first_hops, & inflight_htlcs, entropy_source, node_signer, best_block_height, logger, pending_events, & send_payment_along_path) ;
1277+ self . handle_pay_route_err (
1278+ e, payment_id, payment_hash, route, route_params, onion_session_privs, router, first_hops,
1279+ & inflight_htlcs, entropy_source, node_signer, best_block_height, logger, pending_events,
1280+ & send_payment_along_path
1281+ ) ;
12781282 }
12791283 Ok ( ( ) )
12801284 }
@@ -1430,15 +1434,21 @@ impl OutboundPayments {
14301434 best_block_height, & send_payment_along_path) ;
14311435 log_info ! ( logger, "Result retrying payment id {}: {:?}" , & payment_id, res) ;
14321436 if let Err ( e) = res {
1433- self . handle_pay_route_err ( e, payment_id, payment_hash, route, route_params, router, first_hops, inflight_htlcs, entropy_source, node_signer, best_block_height, logger, pending_events, send_payment_along_path) ;
1437+ self . handle_pay_route_err (
1438+ e, payment_id, payment_hash, route, route_params, onion_session_privs, router, first_hops,
1439+ inflight_htlcs, entropy_source, node_signer, best_block_height, logger, pending_events,
1440+ send_payment_along_path
1441+ ) ;
14341442 }
14351443 }
14361444
14371445 fn handle_pay_route_err < R : Deref , NS : Deref , ES : Deref , IH , SP , L : Deref > (
14381446 & self , err : PaymentSendFailure , payment_id : PaymentId , payment_hash : PaymentHash , route : Route ,
1439- mut route_params : RouteParameters , router : & R , first_hops : Vec < ChannelDetails > ,
1440- inflight_htlcs : & IH , entropy_source : & ES , node_signer : & NS , best_block_height : u32 , logger : & L ,
1441- pending_events : & Mutex < VecDeque < ( events:: Event , Option < EventCompletionAction > ) > > , send_payment_along_path : & SP ,
1447+ mut route_params : RouteParameters , onion_session_privs : Vec < [ u8 ; 32 ] > , router : & R ,
1448+ first_hops : Vec < ChannelDetails > , inflight_htlcs : & IH , entropy_source : & ES , node_signer : & NS ,
1449+ best_block_height : u32 , logger : & L ,
1450+ pending_events : & Mutex < VecDeque < ( events:: Event , Option < EventCompletionAction > ) > > ,
1451+ send_payment_along_path : & SP ,
14421452 )
14431453 where
14441454 R :: Target : Router ,
@@ -1448,6 +1458,19 @@ impl OutboundPayments {
14481458 IH : Fn ( ) -> InFlightHtlcs ,
14491459 SP : Fn ( SendAlongPathArgs ) -> Result < ( ) , APIError > ,
14501460 {
1461+ macro_rules! remove_session_privs {
1462+ ( ) => {
1463+ if let Some ( payment) = self . pending_outbound_payments. lock( ) . unwrap( ) . get_mut( & payment_id) {
1464+ for ( path, session_priv_bytes) in route. paths. iter( ) . zip( onion_session_privs. into_iter( ) ) {
1465+ let removed = payment. remove( & session_priv_bytes, Some ( path) ) ;
1466+ debug_assert!( removed, "This can't happen as the payment has an entry for this path added by callers" ) ;
1467+ }
1468+ } else {
1469+ debug_assert!( false , "This can't happen as the payment was added by callers" ) ;
1470+ }
1471+ }
1472+ }
1473+
14511474 match err {
14521475 PaymentSendFailure :: AllFailedResendSafe ( errs) => {
14531476 Self :: push_path_failed_evs_and_scids ( payment_id, payment_hash, & mut route_params, route. paths , errs. into_iter ( ) . map ( |e| Err ( e) ) , logger, pending_events) ;
@@ -1467,11 +1490,13 @@ impl OutboundPayments {
14671490 } ,
14681491 PaymentSendFailure :: PathParameterError ( results) => {
14691492 log_error ! ( logger, "Failed to send to route due to parameter error in a single path. Your router is buggy" ) ;
1493+ remove_session_privs ! ( ) ;
14701494 Self :: push_path_failed_evs_and_scids ( payment_id, payment_hash, & mut route_params, route. paths , results. into_iter ( ) , logger, pending_events) ;
14711495 self . abandon_payment ( payment_id, PaymentFailureReason :: UnexpectedError , pending_events) ;
14721496 } ,
14731497 PaymentSendFailure :: ParameterError ( e) => {
14741498 log_error ! ( logger, "Failed to send to route due to parameter error: {:?}. Your router is buggy" , e) ;
1499+ remove_session_privs ! ( ) ;
14751500 self . abandon_payment ( payment_id, PaymentFailureReason :: UnexpectedError , pending_events) ;
14761501 } ,
14771502 PaymentSendFailure :: DuplicatePayment => debug_assert ! ( false ) , // unreachable
@@ -1880,9 +1905,15 @@ impl OutboundPayments {
18801905 // If we failed to send any paths, remove the new PaymentId from the `pending_outbound_payments`
18811906 // map as the payment is free to be resent.
18821907 fn remove_outbound_if_all_failed ( & self , payment_id : PaymentId , err : & PaymentSendFailure ) {
1883- if let & PaymentSendFailure :: AllFailedResendSafe ( _) = err {
1884- let removed = self . pending_outbound_payments . lock ( ) . unwrap ( ) . remove ( & payment_id) . is_some ( ) ;
1885- debug_assert ! ( removed, "We should always have a pending payment to remove here" ) ;
1908+ match err {
1909+ PaymentSendFailure :: AllFailedResendSafe ( _)
1910+ | PaymentSendFailure :: ParameterError ( _)
1911+ | PaymentSendFailure :: PathParameterError ( _) =>
1912+ {
1913+ let removed = self . pending_outbound_payments . lock ( ) . unwrap ( ) . remove ( & payment_id) . is_some ( ) ;
1914+ debug_assert ! ( removed, "We should always have a pending payment to remove here" ) ;
1915+ } ,
1916+ PaymentSendFailure :: DuplicatePayment | PaymentSendFailure :: PartialFailure { .. } => { }
18861917 }
18871918 }
18881919
0 commit comments