@@ -94,6 +94,7 @@ pub(crate) enum PendingOutboundPayment {
94
94
payment_secret : Option < PaymentSecret > ,
95
95
payment_metadata : Option < Vec < u8 > > ,
96
96
keysend_preimage : Option < PaymentPreimage > ,
97
+ invoice_request : Option < InvoiceRequest > ,
97
98
custom_tlvs : Vec < ( u64 , Vec < u8 > ) > ,
98
99
pending_amt_msat : u64 ,
99
100
/// Used to track the fee paid. Present iff the payment was serialized on 0.0.103+.
@@ -948,20 +949,33 @@ impl OutboundPayments {
948
949
} ;
949
950
950
951
let payment_params = Some ( route_params. payment_params . clone ( ) ) ;
951
- let ( retryable_payment, onion_session_privs) = Self :: create_pending_payment (
952
- payment_hash, recipient_onion. clone ( ) , keysend_preimage, & route, Some ( retry_strategy) ,
953
- payment_params, entropy_source, best_block_height
954
- ) ;
955
- match self . pending_outbound_payments . lock ( ) . unwrap ( ) . entry ( payment_id) {
952
+ let mut outbounds = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
953
+ let onion_session_privs = match outbounds. entry ( payment_id) {
956
954
hash_map:: Entry :: Occupied ( entry) => match entry. get ( ) {
957
- PendingOutboundPayment :: InvoiceReceived { .. }
958
- | PendingOutboundPayment :: StaticInvoiceReceived { .. } => {
955
+ PendingOutboundPayment :: InvoiceReceived { .. } => {
956
+ let ( retryable_payment, onion_session_privs) = Self :: create_pending_payment (
957
+ payment_hash, recipient_onion. clone ( ) , keysend_preimage, None , & route,
958
+ Some ( retry_strategy) , payment_params, entropy_source, best_block_height
959
+ ) ;
959
960
* entry. into_mut ( ) = retryable_payment;
961
+ onion_session_privs
962
+ } ,
963
+ PendingOutboundPayment :: StaticInvoiceReceived { .. } => {
964
+ let invreq = if let PendingOutboundPayment :: StaticInvoiceReceived { invoice_request, .. } = entry. remove ( ) {
965
+ invoice_request
966
+ } else { unreachable ! ( ) } ;
967
+ let ( retryable_payment, onion_session_privs) = Self :: create_pending_payment (
968
+ payment_hash, recipient_onion. clone ( ) , keysend_preimage, Some ( invreq) , & route,
969
+ Some ( retry_strategy) , payment_params, entropy_source, best_block_height
970
+ ) ;
971
+ outbounds. insert ( payment_id, retryable_payment) ;
972
+ onion_session_privs
960
973
} ,
961
974
_ => return Err ( Bolt12PaymentError :: DuplicateInvoice ) ,
962
975
} ,
963
976
hash_map:: Entry :: Vacant ( _) => return Err ( Bolt12PaymentError :: UnexpectedInvoice ) ,
964
- }
977
+ } ;
978
+ core:: mem:: drop ( outbounds) ;
965
979
966
980
let result = self . pay_route_internal (
967
981
& route, payment_hash, & recipient_onion, keysend_preimage, invoice_request, payment_id,
@@ -1324,14 +1338,14 @@ impl OutboundPayments {
1324
1338
}
1325
1339
}
1326
1340
}
1327
- let ( total_msat, recipient_onion, keysend_preimage, onion_session_privs) = {
1341
+ let ( total_msat, recipient_onion, keysend_preimage, onion_session_privs, invoice_request ) = {
1328
1342
let mut outbounds = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
1329
1343
match outbounds. entry ( payment_id) {
1330
1344
hash_map:: Entry :: Occupied ( mut payment) => {
1331
1345
match payment. get ( ) {
1332
1346
PendingOutboundPayment :: Retryable {
1333
1347
total_msat, keysend_preimage, payment_secret, payment_metadata,
1334
- custom_tlvs, pending_amt_msat, ..
1348
+ custom_tlvs, pending_amt_msat, invoice_request , ..
1335
1349
} => {
1336
1350
const RETRY_OVERFLOW_PERCENTAGE : u64 = 10 ;
1337
1351
let retry_amt_msat = route. get_total_amount ( ) ;
@@ -1354,6 +1368,7 @@ impl OutboundPayments {
1354
1368
custom_tlvs : custom_tlvs. clone ( ) ,
1355
1369
} ;
1356
1370
let keysend_preimage = * keysend_preimage;
1371
+ let invoice_request = invoice_request. clone ( ) ;
1357
1372
1358
1373
let mut onion_session_privs = Vec :: with_capacity ( route. paths . len ( ) ) ;
1359
1374
for _ in 0 ..route. paths . len ( ) {
@@ -1366,7 +1381,7 @@ impl OutboundPayments {
1366
1381
1367
1382
payment. get_mut ( ) . increment_attempts ( ) ;
1368
1383
1369
- ( total_msat, recipient_onion, keysend_preimage, onion_session_privs)
1384
+ ( total_msat, recipient_onion, keysend_preimage, onion_session_privs, invoice_request )
1370
1385
} ,
1371
1386
PendingOutboundPayment :: Legacy { .. } => {
1372
1387
log_error ! ( logger, "Unable to retry payments that were initially sent on LDK versions prior to 0.0.102" ) ;
@@ -1404,8 +1419,8 @@ impl OutboundPayments {
1404
1419
}
1405
1420
} ;
1406
1421
let res = self . pay_route_internal ( & route, payment_hash, & recipient_onion, keysend_preimage,
1407
- None , payment_id, Some ( total_msat) , onion_session_privs, node_signer, best_block_height ,
1408
- & send_payment_along_path) ;
1422
+ invoice_request . as_ref ( ) , payment_id, Some ( total_msat) , onion_session_privs, node_signer,
1423
+ best_block_height , & send_payment_along_path) ;
1409
1424
log_info ! ( logger, "Result retrying payment id {}: {:?}" , & payment_id, res) ;
1410
1425
if let Err ( e) = res {
1411
1426
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) ;
@@ -1557,7 +1572,7 @@ impl OutboundPayments {
1557
1572
hash_map:: Entry :: Occupied ( _) => Err ( PaymentSendFailure :: DuplicatePayment ) ,
1558
1573
hash_map:: Entry :: Vacant ( entry) => {
1559
1574
let ( payment, onion_session_privs) = Self :: create_pending_payment (
1560
- payment_hash, recipient_onion, keysend_preimage, route, retry_strategy,
1575
+ payment_hash, recipient_onion, keysend_preimage, None , route, retry_strategy,
1561
1576
payment_params, entropy_source, best_block_height
1562
1577
) ;
1563
1578
entry. insert ( payment) ;
@@ -1568,8 +1583,9 @@ impl OutboundPayments {
1568
1583
1569
1584
fn create_pending_payment < ES : Deref > (
1570
1585
payment_hash : PaymentHash , recipient_onion : RecipientOnionFields ,
1571
- keysend_preimage : Option < PaymentPreimage > , route : & Route , retry_strategy : Option < Retry > ,
1572
- payment_params : Option < PaymentParameters > , entropy_source : & ES , best_block_height : u32
1586
+ keysend_preimage : Option < PaymentPreimage > , invoice_request : Option < InvoiceRequest > ,
1587
+ route : & Route , retry_strategy : Option < Retry > , payment_params : Option < PaymentParameters > ,
1588
+ entropy_source : & ES , best_block_height : u32
1573
1589
) -> ( PendingOutboundPayment , Vec < [ u8 ; 32 ] > )
1574
1590
where
1575
1591
ES :: Target : EntropySource ,
@@ -1590,6 +1606,7 @@ impl OutboundPayments {
1590
1606
payment_secret : recipient_onion. payment_secret ,
1591
1607
payment_metadata : recipient_onion. payment_metadata ,
1592
1608
keysend_preimage,
1609
+ invoice_request,
1593
1610
custom_tlvs : recipient_onion. custom_tlvs ,
1594
1611
starting_block_height : best_block_height,
1595
1612
total_msat : route. get_total_amount ( ) ,
@@ -2151,6 +2168,7 @@ impl OutboundPayments {
2151
2168
payment_secret: None , // only used for retries, and we'll never retry on startup
2152
2169
payment_metadata: None , // only used for retries, and we'll never retry on startup
2153
2170
keysend_preimage: None , // only used for retries, and we'll never retry on startup
2171
+ invoice_request: None , // only used for retries, and we'll never retry on startup
2154
2172
custom_tlvs: Vec :: new( ) , // only used for retries, and we'll never retry on startup
2155
2173
pending_amt_msat: path_amt,
2156
2174
pending_fee_msat: Some ( path_fee) ,
@@ -2237,6 +2255,7 @@ impl_writeable_tlv_based_enum_upgradable!(PendingOutboundPayment,
2237
2255
( 9 , custom_tlvs, optional_vec) ,
2238
2256
( 10 , starting_block_height, required) ,
2239
2257
( 11 , remaining_max_total_routing_fee_msat, option) ,
2258
+ ( 13 , invoice_request, option) ,
2240
2259
( not_written, retry_strategy, ( static_value, None ) ) ,
2241
2260
( not_written, attempts, ( static_value, PaymentAttempts :: new( ) ) ) ,
2242
2261
} ,
0 commit comments