@@ -43,7 +43,7 @@ pub(crate) const IDEMPOTENCY_TIMEOUT_TICKS: u8 = 7;
43
43
/// a response is timed out.
44
44
///
45
45
/// [`ChannelManager::timer_tick_occurred`]: crate::ln::channelmanager::ChannelManager::timer_tick_occurred
46
- const INVOICE_REQUEST_TIMEOUT_TICKS : u8 = 3 ;
46
+ const INVOICE_REQUEST_TIMEOUT_TICKS : Option < u64 > = Some ( 3 ) ;
47
47
48
48
/// Stores the session_priv for each part of a payment that is still pending. For versions 0.0.102
49
49
/// and later, also stores information for retrying the payment.
@@ -52,7 +52,7 @@ pub(crate) enum PendingOutboundPayment {
52
52
session_privs : HashSet < [ u8 ; 32 ] > ,
53
53
} ,
54
54
AwaitingInvoice {
55
- timer_ticks_without_response : u8 ,
55
+ timer_ticks_without_response_remaining : Option < u64 > ,
56
56
retry_strategy : Retry ,
57
57
max_total_routing_fee_msat : Option < u64 > ,
58
58
} ,
@@ -1274,15 +1274,35 @@ impl OutboundPayments {
1274
1274
}
1275
1275
1276
1276
#[ allow( unused) ]
1277
- pub ( super ) fn add_new_awaiting_invoice (
1277
+ pub ( super ) fn add_new_awaiting_invoice_for_offer (
1278
1278
& self , payment_id : PaymentId , retry_strategy : Retry , max_total_routing_fee_msat : Option < u64 >
1279
+ ) -> Result < ( ) , ( ) > {
1280
+ self . add_new_awaiting_invoice (
1281
+ payment_id, retry_strategy, max_total_routing_fee_msat, INVOICE_REQUEST_TIMEOUT_TICKS
1282
+ )
1283
+ }
1284
+
1285
+ #[ allow( unused) ]
1286
+ pub ( super ) fn add_new_awaiting_invoice_for_refund (
1287
+ & self , payment_id : PaymentId , retry_strategy : Retry ,
1288
+ max_total_routing_fee_msat : Option < u64 > , timer_ticks_before_expiration : Option < u64 >
1289
+ ) -> Result < ( ) , ( ) > {
1290
+ self . add_new_awaiting_invoice (
1291
+ payment_id, retry_strategy, max_total_routing_fee_msat, timer_ticks_before_expiration
1292
+ )
1293
+ }
1294
+
1295
+ #[ allow( unused) ]
1296
+ fn add_new_awaiting_invoice (
1297
+ & self , payment_id : PaymentId , retry_strategy : Retry ,
1298
+ max_total_routing_fee_msat : Option < u64 > , timer_ticks_before_expiration : Option < u64 >
1279
1299
) -> Result < ( ) , ( ) > {
1280
1300
let mut pending_outbounds = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
1281
1301
match pending_outbounds. entry ( payment_id) {
1282
1302
hash_map:: Entry :: Occupied ( _) => Err ( ( ) ) ,
1283
1303
hash_map:: Entry :: Vacant ( entry) => {
1284
1304
entry. insert ( PendingOutboundPayment :: AwaitingInvoice {
1285
- timer_ticks_without_response : 0 ,
1305
+ timer_ticks_without_response_remaining : timer_ticks_before_expiration ,
1286
1306
retry_strategy,
1287
1307
max_total_routing_fee_msat,
1288
1308
} ) ;
@@ -1550,9 +1570,11 @@ impl OutboundPayments {
1550
1570
* timer_ticks_without_htlcs = 0 ;
1551
1571
true
1552
1572
}
1553
- } else if let PendingOutboundPayment :: AwaitingInvoice { timer_ticks_without_response, .. } = payment {
1554
- * timer_ticks_without_response += 1 ;
1555
- if * timer_ticks_without_response <= INVOICE_REQUEST_TIMEOUT_TICKS {
1573
+ } else if let PendingOutboundPayment :: AwaitingInvoice {
1574
+ timer_ticks_without_response_remaining : Some ( timer_ticks_remaining) , ..
1575
+ } = payment {
1576
+ if * timer_ticks_remaining > 0 {
1577
+ * timer_ticks_remaining -= 1 ;
1556
1578
true
1557
1579
} else {
1558
1580
#[ cfg( invreqfailed) ]
@@ -1778,7 +1800,7 @@ impl_writeable_tlv_based_enum_upgradable!(PendingOutboundPayment,
1778
1800
( 2 , payment_hash, required) ,
1779
1801
} ,
1780
1802
( 5 , AwaitingInvoice ) => {
1781
- ( 0 , timer_ticks_without_response , required ) ,
1803
+ ( 0 , timer_ticks_without_response_remaining , option ) ,
1782
1804
( 2 , retry_strategy, required) ,
1783
1805
( 4 , max_total_routing_fee_msat, option) ,
1784
1806
} ,
@@ -2014,11 +2036,13 @@ mod tests {
2014
2036
2015
2037
assert ! ( !outbound_payments. has_pending_payments( ) ) ;
2016
2038
assert ! (
2017
- outbound_payments. add_new_awaiting_invoice( payment_id, Retry :: Attempts ( 0 ) , None ) . is_ok( )
2039
+ outbound_payments. add_new_awaiting_invoice(
2040
+ payment_id, Retry :: Attempts ( 0 ) , None , INVOICE_REQUEST_TIMEOUT_TICKS
2041
+ ) . is_ok( )
2018
2042
) ;
2019
2043
assert ! ( outbound_payments. has_pending_payments( ) ) ;
2020
2044
2021
- for _ in 0 ..INVOICE_REQUEST_TIMEOUT_TICKS {
2045
+ for _ in 0 ..INVOICE_REQUEST_TIMEOUT_TICKS . unwrap ( ) {
2022
2046
outbound_payments. remove_stale_payments ( & pending_events) ;
2023
2047
assert ! ( outbound_payments. has_pending_payments( ) ) ;
2024
2048
assert ! ( pending_events. lock( ) . unwrap( ) . is_empty( ) ) ;
@@ -2034,13 +2058,16 @@ mod tests {
2034
2058
assert ! ( pending_events. lock( ) . unwrap( ) . is_empty( ) ) ;
2035
2059
2036
2060
assert ! (
2037
- outbound_payments. add_new_awaiting_invoice( payment_id, Retry :: Attempts ( 0 ) , None ) . is_ok( )
2061
+ outbound_payments. add_new_awaiting_invoice(
2062
+ payment_id, Retry :: Attempts ( 0 ) , None , INVOICE_REQUEST_TIMEOUT_TICKS
2063
+ ) . is_ok( )
2038
2064
) ;
2039
2065
assert ! ( outbound_payments. has_pending_payments( ) ) ;
2040
2066
2041
2067
assert ! (
2042
- outbound_payments. add_new_awaiting_invoice( payment_id, Retry :: Attempts ( 0 ) , None )
2043
- . is_err( )
2068
+ outbound_payments. add_new_awaiting_invoice(
2069
+ payment_id, Retry :: Attempts ( 0 ) , None , INVOICE_REQUEST_TIMEOUT_TICKS
2070
+ ) . is_err( )
2044
2071
) ;
2045
2072
}
2046
2073
@@ -2053,7 +2080,9 @@ mod tests {
2053
2080
2054
2081
assert ! ( !outbound_payments. has_pending_payments( ) ) ;
2055
2082
assert ! (
2056
- outbound_payments. add_new_awaiting_invoice( payment_id, Retry :: Attempts ( 0 ) , None ) . is_ok( )
2083
+ outbound_payments. add_new_awaiting_invoice(
2084
+ payment_id, Retry :: Attempts ( 0 ) , None , INVOICE_REQUEST_TIMEOUT_TICKS
2085
+ ) . is_ok( )
2057
2086
) ;
2058
2087
assert ! ( outbound_payments. has_pending_payments( ) ) ;
2059
2088
@@ -2083,7 +2112,9 @@ mod tests {
2083
2112
let payment_id = PaymentId ( [ 0 ; 32 ] ) ;
2084
2113
2085
2114
assert ! (
2086
- outbound_payments. add_new_awaiting_invoice( payment_id, Retry :: Attempts ( 0 ) , None ) . is_ok( )
2115
+ outbound_payments. add_new_awaiting_invoice(
2116
+ payment_id, Retry :: Attempts ( 0 ) , None , INVOICE_REQUEST_TIMEOUT_TICKS
2117
+ ) . is_ok( )
2087
2118
) ;
2088
2119
assert ! ( outbound_payments. has_pending_payments( ) ) ;
2089
2120
@@ -2140,9 +2171,11 @@ mod tests {
2140
2171
. build ( ) . unwrap ( )
2141
2172
. sign ( recipient_sign) . unwrap ( ) ;
2142
2173
2143
- assert ! ( outbound_payments. add_new_awaiting_invoice(
2144
- payment_id, Retry :: Attempts ( 0 ) , Some ( invoice. amount_msats( ) / 100 + 50_000 ) )
2145
- . is_ok( )
2174
+ assert ! (
2175
+ outbound_payments. add_new_awaiting_invoice(
2176
+ payment_id, Retry :: Attempts ( 0 ) , Some ( invoice. amount_msats( ) / 100 + 50_000 ) ,
2177
+ INVOICE_REQUEST_TIMEOUT_TICKS
2178
+ ) . is_ok( )
2146
2179
) ;
2147
2180
assert ! ( outbound_payments. has_pending_payments( ) ) ;
2148
2181
@@ -2196,9 +2229,11 @@ mod tests {
2196
2229
. build ( ) . unwrap ( )
2197
2230
. sign ( recipient_sign) . unwrap ( ) ;
2198
2231
2199
- assert ! ( outbound_payments. add_new_awaiting_invoice(
2200
- payment_id, Retry :: Attempts ( 0 ) , Some ( invoice. amount_msats( ) / 100 + 50_000 ) )
2201
- . is_ok( )
2232
+ assert ! (
2233
+ outbound_payments. add_new_awaiting_invoice(
2234
+ payment_id, Retry :: Attempts ( 0 ) , Some ( invoice. amount_msats( ) / 100 + 50_000 ) ,
2235
+ INVOICE_REQUEST_TIMEOUT_TICKS
2236
+ ) . is_ok( )
2202
2237
) ;
2203
2238
assert ! ( outbound_payments. has_pending_payments( ) ) ;
2204
2239
@@ -2292,7 +2327,9 @@ mod tests {
2292
2327
assert ! ( pending_events. lock( ) . unwrap( ) . is_empty( ) ) ;
2293
2328
2294
2329
assert ! (
2295
- outbound_payments. add_new_awaiting_invoice( payment_id, Retry :: Attempts ( 0 ) , Some ( 1234 ) ) . is_ok( )
2330
+ outbound_payments. add_new_awaiting_invoice(
2331
+ payment_id, Retry :: Attempts ( 0 ) , Some ( 1234 ) , INVOICE_REQUEST_TIMEOUT_TICKS
2332
+ ) . is_ok( )
2296
2333
) ;
2297
2334
assert ! ( outbound_payments. has_pending_payments( ) ) ;
2298
2335
0 commit comments