@@ -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,36 @@ 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
+ macro_rules! create_pending_payment {
953
+ ( $invreq_opt: expr) => {
954
+ self . create_pending_payment(
955
+ payment_hash, recipient_onion. clone( ) , keysend_preimage, $invreq_opt, & route,
956
+ Some ( retry_strategy) , payment_params, entropy_source, best_block_height
957
+ )
958
+ }
959
+ }
960
+
961
+ let mut outbounds = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
962
+ let onion_session_privs = match outbounds. entry ( payment_id) {
956
963
hash_map:: Entry :: Occupied ( entry) => match entry. get ( ) {
957
- PendingOutboundPayment :: InvoiceReceived { .. }
958
- | PendingOutboundPayment :: StaticInvoiceReceived { .. } => {
964
+ PendingOutboundPayment :: InvoiceReceived { .. } => {
965
+ let ( retryable_payment , onion_session_privs ) = create_pending_payment ! ( None ) ;
959
966
* entry. into_mut ( ) = retryable_payment;
967
+ onion_session_privs
968
+ } ,
969
+ PendingOutboundPayment :: StaticInvoiceReceived { .. } => {
970
+ let invreq = if let PendingOutboundPayment :: StaticInvoiceReceived { invoice_request, .. } = entry. remove ( ) {
971
+ invoice_request
972
+ } else { unreachable ! ( ) } ;
973
+ let ( retryable_payment, onion_session_privs) = create_pending_payment ! ( Some ( invreq) ) ;
974
+ outbounds. insert ( payment_id, retryable_payment) ;
975
+ onion_session_privs
960
976
} ,
961
977
_ => return Err ( Bolt12PaymentError :: DuplicateInvoice ) ,
962
978
} ,
963
979
hash_map:: Entry :: Vacant ( _) => return Err ( Bolt12PaymentError :: UnexpectedInvoice ) ,
964
- }
980
+ } ;
981
+ core:: mem:: drop ( outbounds) ;
965
982
966
983
let result = self . pay_route_internal (
967
984
& route, payment_hash, & recipient_onion, keysend_preimage, invoice_request, payment_id,
@@ -1324,14 +1341,14 @@ impl OutboundPayments {
1324
1341
}
1325
1342
}
1326
1343
}
1327
- let ( total_msat, recipient_onion, keysend_preimage, onion_session_privs) = {
1344
+ let ( total_msat, recipient_onion, keysend_preimage, onion_session_privs, invoice_request ) = {
1328
1345
let mut outbounds = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
1329
1346
match outbounds. entry ( payment_id) {
1330
1347
hash_map:: Entry :: Occupied ( mut payment) => {
1331
1348
match payment. get ( ) {
1332
1349
PendingOutboundPayment :: Retryable {
1333
1350
total_msat, keysend_preimage, payment_secret, payment_metadata,
1334
- custom_tlvs, pending_amt_msat, ..
1351
+ custom_tlvs, pending_amt_msat, invoice_request , ..
1335
1352
} => {
1336
1353
const RETRY_OVERFLOW_PERCENTAGE : u64 = 10 ;
1337
1354
let retry_amt_msat = route. get_total_amount ( ) ;
@@ -1354,6 +1371,7 @@ impl OutboundPayments {
1354
1371
custom_tlvs : custom_tlvs. clone ( ) ,
1355
1372
} ;
1356
1373
let keysend_preimage = * keysend_preimage;
1374
+ let invoice_request = invoice_request. clone ( ) ;
1357
1375
1358
1376
let mut onion_session_privs = Vec :: with_capacity ( route. paths . len ( ) ) ;
1359
1377
for _ in 0 ..route. paths . len ( ) {
@@ -1366,7 +1384,7 @@ impl OutboundPayments {
1366
1384
1367
1385
payment. get_mut ( ) . increment_attempts ( ) ;
1368
1386
1369
- ( total_msat, recipient_onion, keysend_preimage, onion_session_privs)
1387
+ ( total_msat, recipient_onion, keysend_preimage, onion_session_privs, invoice_request )
1370
1388
} ,
1371
1389
PendingOutboundPayment :: Legacy { .. } => {
1372
1390
log_error ! ( logger, "Unable to retry payments that were initially sent on LDK versions prior to 0.0.102" ) ;
@@ -1404,8 +1422,8 @@ impl OutboundPayments {
1404
1422
}
1405
1423
} ;
1406
1424
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) ;
1425
+ invoice_request . as_ref ( ) , payment_id, Some ( total_msat) , onion_session_privs, node_signer,
1426
+ best_block_height , & send_payment_along_path) ;
1409
1427
log_info ! ( logger, "Result retrying payment id {}: {:?}" , & payment_id, res) ;
1410
1428
if let Err ( e) = res {
1411
1429
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 +1575,7 @@ impl OutboundPayments {
1557
1575
hash_map:: Entry :: Occupied ( _) => Err ( PaymentSendFailure :: DuplicatePayment ) ,
1558
1576
hash_map:: Entry :: Vacant ( entry) => {
1559
1577
let ( payment, onion_session_privs) = self . create_pending_payment (
1560
- payment_hash, recipient_onion, keysend_preimage, route, retry_strategy,
1578
+ payment_hash, recipient_onion, keysend_preimage, None , route, retry_strategy,
1561
1579
payment_params, entropy_source, best_block_height
1562
1580
) ;
1563
1581
entry. insert ( payment) ;
@@ -1568,8 +1586,9 @@ impl OutboundPayments {
1568
1586
1569
1587
fn create_pending_payment < ES : Deref > (
1570
1588
& self , 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
1589
+ keysend_preimage : Option < PaymentPreimage > , invoice_request : Option < InvoiceRequest > ,
1590
+ route : & Route , retry_strategy : Option < Retry > , payment_params : Option < PaymentParameters > ,
1591
+ entropy_source : & ES , best_block_height : u32
1573
1592
) -> ( PendingOutboundPayment , Vec < [ u8 ; 32 ] > )
1574
1593
where
1575
1594
ES :: Target : EntropySource ,
@@ -1590,6 +1609,7 @@ impl OutboundPayments {
1590
1609
payment_secret : recipient_onion. payment_secret ,
1591
1610
payment_metadata : recipient_onion. payment_metadata ,
1592
1611
keysend_preimage,
1612
+ invoice_request,
1593
1613
custom_tlvs : recipient_onion. custom_tlvs ,
1594
1614
starting_block_height : best_block_height,
1595
1615
total_msat : route. get_total_amount ( ) ,
@@ -2151,6 +2171,7 @@ impl OutboundPayments {
2151
2171
payment_secret: None , // only used for retries, and we'll never retry on startup
2152
2172
payment_metadata: None , // only used for retries, and we'll never retry on startup
2153
2173
keysend_preimage: None , // only used for retries, and we'll never retry on startup
2174
+ invoice_request: None , // only used for retries, and we'll never retry on startup
2154
2175
custom_tlvs: Vec :: new( ) , // only used for retries, and we'll never retry on startup
2155
2176
pending_amt_msat: path_amt,
2156
2177
pending_fee_msat: Some ( path_fee) ,
@@ -2237,6 +2258,7 @@ impl_writeable_tlv_based_enum_upgradable!(PendingOutboundPayment,
2237
2258
( 9 , custom_tlvs, optional_vec) ,
2238
2259
( 10 , starting_block_height, required) ,
2239
2260
( 11 , remaining_max_total_routing_fee_msat, option) ,
2261
+ ( 13 , invoice_request, option) ,
2240
2262
( not_written, retry_strategy, ( static_value, None ) ) ,
2241
2263
( not_written, attempts, ( static_value, PaymentAttempts :: new( ) ) ) ,
2242
2264
} ,
0 commit comments