@@ -24,6 +24,7 @@ use crate::ln::onion_utils;
24
24
use crate :: ln:: onion_utils:: { DecodedOnionFailure , HTLCFailReason } ;
25
25
use crate :: offers:: invoice:: Bolt12Invoice ;
26
26
use crate :: offers:: invoice_request:: InvoiceRequest ;
27
+ use crate :: offers:: nonce:: Nonce ;
27
28
use crate :: routing:: router:: { BlindedTail , InFlightHtlcs , Path , PaymentParameters , Route , RouteParameters , Router } ;
28
29
use crate :: sign:: { EntropySource , NodeSigner , Recipient } ;
29
30
use crate :: util:: errors:: APIError ;
@@ -58,7 +59,7 @@ pub(crate) enum PendingOutboundPayment {
58
59
retry_strategy : Retry ,
59
60
max_total_routing_fee_msat : Option < u64 > ,
60
61
invoice_request : Option < InvoiceRequest > ,
61
- context : OffersContext ,
62
+ nonce : Option < Nonce > ,
62
63
} ,
63
64
InvoiceReceived {
64
65
payment_hash : PaymentHash ,
@@ -1363,7 +1364,7 @@ impl OutboundPayments {
1363
1364
pub ( super ) fn add_new_awaiting_invoice (
1364
1365
& self , payment_id : PaymentId , expiration : StaleExpiration , retry_strategy : Retry ,
1365
1366
max_total_routing_fee_msat : Option < u64 > , invoice_request : Option < InvoiceRequest > ,
1366
- context : OffersContext ,
1367
+ nonce : Nonce ,
1367
1368
) -> Result < ( ) , ( ) > {
1368
1369
let mut pending_outbounds = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
1369
1370
match pending_outbounds. entry ( payment_id) {
@@ -1374,7 +1375,7 @@ impl OutboundPayments {
1374
1375
retry_strategy,
1375
1376
max_total_routing_fee_msat,
1376
1377
invoice_request,
1377
- context ,
1378
+ nonce : Some ( nonce ) ,
1378
1379
} ) ;
1379
1380
self . awaiting_invoice . store ( true , Ordering :: Release ) ;
1380
1381
@@ -1849,12 +1850,20 @@ impl OutboundPayments {
1849
1850
}
1850
1851
1851
1852
let mut pending_outbound_payments = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
1852
- let invoice_requests = pending_outbound_payments. iter_mut ( )
1853
- . filter_map ( |( _, payment) | match payment {
1854
- PendingOutboundPayment :: AwaitingInvoice { invoice_request, context, ..} => {
1855
- invoice_request. take ( ) . map ( |req| ( context. clone ( ) , req) )
1853
+ let invoice_requests = pending_outbound_payments
1854
+ . iter_mut ( )
1855
+ . filter_map ( |( payment_id, payment) | {
1856
+ if let PendingOutboundPayment :: AwaitingInvoice {
1857
+ invoice_request, nonce : Some ( nonce) , ..
1858
+ } = payment {
1859
+ let context = OffersContext :: OutboundPayment {
1860
+ payment_id : * payment_id,
1861
+ nonce : * nonce,
1862
+ } ;
1863
+ invoice_request. take ( ) . map ( |req| ( context, req) )
1864
+ } else {
1865
+ None
1856
1866
}
1857
- _ => None ,
1858
1867
} )
1859
1868
. collect ( ) ;
1860
1869
@@ -1917,7 +1926,7 @@ impl_writeable_tlv_based_enum_upgradable!(PendingOutboundPayment,
1917
1926
( 2 , retry_strategy, required) ,
1918
1927
( 4 , max_total_routing_fee_msat, option) ,
1919
1928
( 5 , invoice_request, option) ,
1920
- ( 6 , context , required ) ,
1929
+ ( 7 , nonce , option ) ,
1921
1930
} ,
1922
1931
( 7 , InvoiceReceived ) => {
1923
1932
( 0 , payment_hash, required) ,
@@ -1933,7 +1942,6 @@ mod tests {
1933
1942
1934
1943
use core:: time:: Duration ;
1935
1944
1936
- use crate :: blinded_path:: message:: OffersContext ;
1937
1945
use crate :: blinded_path:: EmptyNodeIdLookUp ;
1938
1946
use crate :: events:: { Event , PathFailure , PaymentFailureReason } ;
1939
1947
use crate :: ln:: types:: PaymentHash ;
@@ -1943,6 +1951,7 @@ mod tests {
1943
1951
use crate :: ln:: outbound_payment:: { Bolt12PaymentError , OutboundPayments , Retry , RetryableSendFailure , StaleExpiration } ;
1944
1952
#[ cfg( feature = "std" ) ]
1945
1953
use crate :: offers:: invoice:: DEFAULT_RELATIVE_EXPIRY ;
1954
+ use crate :: offers:: nonce:: Nonce ;
1946
1955
use crate :: offers:: offer:: OfferBuilder ;
1947
1956
use crate :: offers:: test_utils:: * ;
1948
1957
use crate :: routing:: gossip:: NetworkGraph ;
@@ -2158,7 +2167,7 @@ mod tests {
2158
2167
assert ! ( !outbound_payments. has_pending_payments( ) ) ;
2159
2168
assert ! (
2160
2169
outbound_payments. add_new_awaiting_invoice(
2161
- payment_id, expiration, Retry :: Attempts ( 0 ) , None , None , OffersContext :: Unknown { }
2170
+ payment_id, expiration, Retry :: Attempts ( 0 ) , None , None , Nonce :: try_from ( & [ 0u8 ; 16 ] [ .. ] ) . unwrap ( )
2162
2171
) . is_ok( )
2163
2172
) ;
2164
2173
assert ! ( outbound_payments. has_pending_payments( ) ) ;
@@ -2184,14 +2193,14 @@ mod tests {
2184
2193
2185
2194
assert ! (
2186
2195
outbound_payments. add_new_awaiting_invoice(
2187
- payment_id, expiration, Retry :: Attempts ( 0 ) , None , None , OffersContext :: Unknown { }
2196
+ payment_id, expiration, Retry :: Attempts ( 0 ) , None , None , Nonce :: try_from ( & [ 0u8 ; 16 ] [ .. ] ) . unwrap ( )
2188
2197
) . is_ok( )
2189
2198
) ;
2190
2199
assert ! ( outbound_payments. has_pending_payments( ) ) ;
2191
2200
2192
2201
assert ! (
2193
2202
outbound_payments. add_new_awaiting_invoice(
2194
- payment_id, expiration, Retry :: Attempts ( 0 ) , None , None , OffersContext :: Unknown { }
2203
+ payment_id, expiration, Retry :: Attempts ( 0 ) , None , None , Nonce :: try_from ( & [ 0u8 ; 16 ] [ .. ] ) . unwrap ( )
2195
2204
) . is_err( )
2196
2205
) ;
2197
2206
}
@@ -2207,7 +2216,7 @@ mod tests {
2207
2216
assert ! ( !outbound_payments. has_pending_payments( ) ) ;
2208
2217
assert ! (
2209
2218
outbound_payments. add_new_awaiting_invoice(
2210
- payment_id, expiration, Retry :: Attempts ( 0 ) , None , None , OffersContext :: Unknown { }
2219
+ payment_id, expiration, Retry :: Attempts ( 0 ) , None , None , Nonce :: try_from ( & [ 0u8 ; 16 ] [ .. ] ) . unwrap ( )
2211
2220
) . is_ok( )
2212
2221
) ;
2213
2222
assert ! ( outbound_payments. has_pending_payments( ) ) ;
@@ -2233,14 +2242,14 @@ mod tests {
2233
2242
2234
2243
assert ! (
2235
2244
outbound_payments. add_new_awaiting_invoice(
2236
- payment_id, expiration, Retry :: Attempts ( 0 ) , None , None , OffersContext :: Unknown { }
2245
+ payment_id, expiration, Retry :: Attempts ( 0 ) , None , None , Nonce :: try_from ( & [ 0u8 ; 16 ] [ .. ] ) . unwrap ( )
2237
2246
) . is_ok( )
2238
2247
) ;
2239
2248
assert ! ( outbound_payments. has_pending_payments( ) ) ;
2240
2249
2241
2250
assert ! (
2242
2251
outbound_payments. add_new_awaiting_invoice(
2243
- payment_id, expiration, Retry :: Attempts ( 0 ) , None , None , OffersContext :: Unknown { }
2252
+ payment_id, expiration, Retry :: Attempts ( 0 ) , None , None , Nonce :: try_from ( & [ 0u8 ; 16 ] [ .. ] ) . unwrap ( )
2244
2253
) . is_err( )
2245
2254
) ;
2246
2255
}
@@ -2255,7 +2264,7 @@ mod tests {
2255
2264
assert ! ( !outbound_payments. has_pending_payments( ) ) ;
2256
2265
assert ! (
2257
2266
outbound_payments. add_new_awaiting_invoice(
2258
- payment_id, expiration, Retry :: Attempts ( 0 ) , None , None , OffersContext :: Unknown { }
2267
+ payment_id, expiration, Retry :: Attempts ( 0 ) , None , None , Nonce :: try_from ( & [ 0u8 ; 16 ] [ .. ] ) . unwrap ( )
2259
2268
) . is_ok( )
2260
2269
) ;
2261
2270
assert ! ( outbound_payments. has_pending_payments( ) ) ;
@@ -2289,7 +2298,7 @@ mod tests {
2289
2298
2290
2299
assert ! (
2291
2300
outbound_payments. add_new_awaiting_invoice(
2292
- payment_id, expiration, Retry :: Attempts ( 0 ) , None , None , OffersContext :: Unknown { }
2301
+ payment_id, expiration, Retry :: Attempts ( 0 ) , None , None , Nonce :: try_from ( & [ 0u8 ; 16 ] [ .. ] ) . unwrap ( )
2293
2302
) . is_ok( )
2294
2303
) ;
2295
2304
assert ! ( outbound_payments. has_pending_payments( ) ) ;
@@ -2353,7 +2362,7 @@ mod tests {
2353
2362
assert ! (
2354
2363
outbound_payments. add_new_awaiting_invoice(
2355
2364
payment_id, expiration, Retry :: Attempts ( 0 ) ,
2356
- Some ( invoice. amount_msats( ) / 100 + 50_000 ) , None , OffersContext :: Unknown { }
2365
+ Some ( invoice. amount_msats( ) / 100 + 50_000 ) , None , Nonce :: try_from ( & [ 0u8 ; 16 ] [ .. ] ) . unwrap ( )
2357
2366
) . is_ok( )
2358
2367
) ;
2359
2368
assert ! ( outbound_payments. has_pending_payments( ) ) ;
@@ -2453,7 +2462,7 @@ mod tests {
2453
2462
2454
2463
assert ! (
2455
2464
outbound_payments. add_new_awaiting_invoice(
2456
- payment_id, expiration, Retry :: Attempts ( 0 ) , Some ( 1234 ) , None , OffersContext :: Unknown { }
2465
+ payment_id, expiration, Retry :: Attempts ( 0 ) , Some ( 1234 ) , None , Nonce :: try_from ( & [ 0u8 ; 16 ] [ .. ] ) . unwrap ( )
2457
2466
) . is_ok( )
2458
2467
) ;
2459
2468
assert ! ( outbound_payments. has_pending_payments( ) ) ;
0 commit comments