@@ -59,6 +59,9 @@ pub(crate) const IDEMPOTENCY_TIMEOUT_TICKS: u8 = 7;
5959/// payee to fulfill.
6060const ASYNC_PAYMENT_TIMEOUT_RELATIVE_EXPIRY : Duration = Duration :: from_secs ( 60 * 60 * 24 * 7 ) ;
6161
62+ #[ cfg( all( async_payments, test) ) ]
63+ pub ( crate ) const TEST_ASYNC_PAYMENT_TIMEOUT_RELATIVE_EXPIRY : Duration = ASYNC_PAYMENT_TIMEOUT_RELATIVE_EXPIRY ;
64+
6265/// Stores the session_priv for each part of a payment that is still pending. For versions 0.0.102
6366/// and later, also stores information for retrying the payment.
6467pub ( crate ) enum PendingOutboundPayment {
@@ -3361,109 +3364,6 @@ mod tests {
33613364 } , None ) ) ;
33623365 }
33633366
3364- #[ test]
3365- #[ rustfmt:: skip]
3366- fn time_out_unreleased_async_payments_using_stale_absolute_time ( ) {
3367- let pending_events = Mutex :: new ( VecDeque :: new ( ) ) ;
3368- let outbound_payments = OutboundPayments :: new ( new_hash_map ( ) ) ;
3369- let payment_id = PaymentId ( [ 0 ; 32 ] ) ;
3370- let absolute_expiry = 60 ;
3371-
3372- let mut outbounds = outbound_payments. pending_outbound_payments . lock ( ) . unwrap ( ) ;
3373- let payment_params = PaymentParameters :: from_node_id ( test_utils:: pubkey ( 42 ) , 0 )
3374- . with_expiry_time ( absolute_expiry) ;
3375- let route_params = RouteParameters {
3376- payment_params,
3377- final_value_msat : 0 ,
3378- max_total_routing_fee_msat : None ,
3379- } ;
3380- let payment_hash = PaymentHash ( [ 0 ; 32 ] ) ;
3381- let outbound = PendingOutboundPayment :: StaticInvoiceReceived {
3382- payment_hash,
3383- keysend_preimage : PaymentPreimage ( [ 0 ; 32 ] ) ,
3384- retry_strategy : Retry :: Attempts ( 0 ) ,
3385- route_params,
3386- invoice_request : dummy_invoice_request ( ) ,
3387- static_invoice : dummy_static_invoice ( ) ,
3388- expiry_time : StaleExpiration :: AbsoluteTimeout ( Duration :: from_secs ( absolute_expiry) ) ,
3389- } ;
3390- outbounds. insert ( payment_id, outbound) ;
3391- core:: mem:: drop ( outbounds) ;
3392-
3393- // The payment will not be removed if it isn't expired yet.
3394- outbound_payments. remove_stale_payments ( Duration :: from_secs ( absolute_expiry) , & pending_events) ;
3395- let outbounds = outbound_payments. pending_outbound_payments . lock ( ) . unwrap ( ) ;
3396- assert_eq ! ( outbounds. len( ) , 1 ) ;
3397- let events = pending_events. lock ( ) . unwrap ( ) ;
3398- assert_eq ! ( events. len( ) , 0 ) ;
3399- core:: mem:: drop ( outbounds) ;
3400- core:: mem:: drop ( events) ;
3401-
3402- outbound_payments. remove_stale_payments ( Duration :: from_secs ( absolute_expiry + 1 ) , & pending_events) ;
3403- let outbounds = outbound_payments. pending_outbound_payments . lock ( ) . unwrap ( ) ;
3404- assert_eq ! ( outbounds. len( ) , 0 ) ;
3405- let events = pending_events. lock ( ) . unwrap ( ) ;
3406- assert_eq ! ( events. len( ) , 1 ) ;
3407- assert_eq ! ( events[ 0 ] , ( Event :: PaymentFailed {
3408- payment_hash: Some ( payment_hash) ,
3409- payment_id,
3410- reason: Some ( PaymentFailureReason :: PaymentExpired ) ,
3411- } , None ) ) ;
3412- }
3413-
3414- #[ test]
3415- #[ rustfmt:: skip]
3416- fn time_out_unreleased_async_payments_using_stale_timer_ticks ( ) {
3417- let pending_events = Mutex :: new ( VecDeque :: new ( ) ) ;
3418- let outbound_payments = OutboundPayments :: new ( new_hash_map ( ) ) ;
3419- let payment_id = PaymentId ( [ 0 ; 32 ] ) ;
3420- let absolute_expiry = 60 ;
3421-
3422- let mut outbounds = outbound_payments. pending_outbound_payments . lock ( ) . unwrap ( ) ;
3423- let payment_params = PaymentParameters :: from_node_id ( test_utils:: pubkey ( 42 ) , 0 )
3424- . with_expiry_time ( absolute_expiry) ;
3425- let route_params = RouteParameters {
3426- payment_params,
3427- final_value_msat : 0 ,
3428- max_total_routing_fee_msat : None ,
3429- } ;
3430- let payment_hash = PaymentHash ( [ 0 ; 32 ] ) ;
3431- let timer_ticks = 1 ;
3432- let expiration = StaleExpiration :: TimerTicks ( timer_ticks) ;
3433- let outbound = PendingOutboundPayment :: StaticInvoiceReceived {
3434- payment_hash,
3435- keysend_preimage : PaymentPreimage ( [ 0 ; 32 ] ) ,
3436- retry_strategy : Retry :: Attempts ( 0 ) ,
3437- route_params,
3438- invoice_request : dummy_invoice_request ( ) ,
3439- static_invoice : dummy_static_invoice ( ) ,
3440- expiry_time : expiration,
3441- } ;
3442- outbounds. insert ( payment_id, outbound) ;
3443- core:: mem:: drop ( outbounds) ;
3444-
3445- // First time should go through
3446- outbound_payments. remove_stale_payments ( Duration :: from_secs ( absolute_expiry) , & pending_events) ;
3447- let outbounds = outbound_payments. pending_outbound_payments . lock ( ) . unwrap ( ) ;
3448- assert_eq ! ( outbounds. len( ) , 1 ) ;
3449- let events = pending_events. lock ( ) . unwrap ( ) ;
3450- assert_eq ! ( events. len( ) , 0 ) ;
3451- core:: mem:: drop ( outbounds) ;
3452- core:: mem:: drop ( events) ;
3453-
3454- // As timer ticks is 1, payment should be timed out
3455- outbound_payments. remove_stale_payments ( Duration :: from_secs ( absolute_expiry) , & pending_events) ;
3456- let outbounds = outbound_payments. pending_outbound_payments . lock ( ) . unwrap ( ) ;
3457- assert_eq ! ( outbounds. len( ) , 0 ) ;
3458- let events = pending_events. lock ( ) . unwrap ( ) ;
3459- assert_eq ! ( events. len( ) , 1 ) ;
3460- assert_eq ! ( events[ 0 ] , ( Event :: PaymentFailed {
3461- payment_hash: Some ( payment_hash) ,
3462- payment_id,
3463- reason: Some ( PaymentFailureReason :: PaymentExpired ) ,
3464- } , None ) ) ;
3465- }
3466-
34673367 #[ test]
34683368 #[ rustfmt:: skip]
34693369 fn abandon_unreleased_async_payment ( ) {
0 commit comments