@@ -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+.
@@ -947,12 +948,18 @@ impl OutboundPayments {
947
948
} ;
948
949
949
950
let payment_params = Some ( route_params. payment_params . clone ( ) ) ;
951
+ let mut outbounds = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
952
+ let mut invoice_request_opt = outbounds. get ( & payment_id) . and_then ( |pmt| {
953
+ if let PendingOutboundPayment :: StaticInvoiceReceived { invoice_request, .. } = pmt {
954
+ Some ( invoice_request. clone ( ) )
955
+ } else {
956
+ None
957
+ }
958
+ } ) ;
950
959
let ( retryable_payment, onion_session_privs) = self . create_pending_payment (
951
- payment_hash, recipient_onion. clone ( ) , keysend_preimage, & route , Some ( retry_strategy ) ,
952
- payment_params, entropy_source, best_block_height
960
+ payment_hash, recipient_onion. clone ( ) , keysend_preimage, invoice_request_opt . take ( ) , & route ,
961
+ Some ( retry_strategy ) , payment_params, entropy_source, best_block_height
953
962
) ;
954
- let mut invoice_request_opt = None ;
955
- let mut outbounds = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
956
963
match outbounds. entry ( payment_id) {
957
964
hash_map:: Entry :: Occupied ( entry) => match entry. remove ( ) {
958
965
PendingOutboundPayment :: InvoiceReceived { .. } => {
@@ -1328,14 +1335,14 @@ impl OutboundPayments {
1328
1335
}
1329
1336
}
1330
1337
}
1331
- let ( total_msat, recipient_onion, keysend_preimage, onion_session_privs) = {
1338
+ let ( total_msat, recipient_onion, keysend_preimage, onion_session_privs, invoice_request ) = {
1332
1339
let mut outbounds = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
1333
1340
match outbounds. entry ( payment_id) {
1334
1341
hash_map:: Entry :: Occupied ( mut payment) => {
1335
1342
match payment. get ( ) {
1336
1343
PendingOutboundPayment :: Retryable {
1337
1344
total_msat, keysend_preimage, payment_secret, payment_metadata,
1338
- custom_tlvs, pending_amt_msat, ..
1345
+ custom_tlvs, pending_amt_msat, invoice_request , ..
1339
1346
} => {
1340
1347
const RETRY_OVERFLOW_PERCENTAGE : u64 = 10 ;
1341
1348
let retry_amt_msat = route. get_total_amount ( ) ;
@@ -1358,6 +1365,7 @@ impl OutboundPayments {
1358
1365
custom_tlvs : custom_tlvs. clone ( ) ,
1359
1366
} ;
1360
1367
let keysend_preimage = * keysend_preimage;
1368
+ let invoice_request = invoice_request. clone ( ) ;
1361
1369
1362
1370
let mut onion_session_privs = Vec :: with_capacity ( route. paths . len ( ) ) ;
1363
1371
for _ in 0 ..route. paths . len ( ) {
@@ -1370,7 +1378,7 @@ impl OutboundPayments {
1370
1378
1371
1379
payment. get_mut ( ) . increment_attempts ( ) ;
1372
1380
1373
- ( total_msat, recipient_onion, keysend_preimage, onion_session_privs)
1381
+ ( total_msat, recipient_onion, keysend_preimage, onion_session_privs, invoice_request )
1374
1382
} ,
1375
1383
PendingOutboundPayment :: Legacy { .. } => {
1376
1384
log_error ! ( logger, "Unable to retry payments that were initially sent on LDK versions prior to 0.0.102" ) ;
@@ -1408,8 +1416,8 @@ impl OutboundPayments {
1408
1416
}
1409
1417
} ;
1410
1418
let res = self . pay_route_internal ( & route, payment_hash, & recipient_onion, keysend_preimage,
1411
- None , payment_id, Some ( total_msat) , onion_session_privs, node_signer, best_block_height ,
1412
- & send_payment_along_path) ;
1419
+ invoice_request . as_ref ( ) , payment_id, Some ( total_msat) , onion_session_privs, node_signer,
1420
+ best_block_height , & send_payment_along_path) ;
1413
1421
log_info ! ( logger, "Result retrying payment id {}: {:?}" , & payment_id, res) ;
1414
1422
if let Err ( e) = res {
1415
1423
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) ;
@@ -1561,7 +1569,7 @@ impl OutboundPayments {
1561
1569
hash_map:: Entry :: Occupied ( _) => Err ( PaymentSendFailure :: DuplicatePayment ) ,
1562
1570
hash_map:: Entry :: Vacant ( entry) => {
1563
1571
let ( payment, onion_session_privs) = self . create_pending_payment (
1564
- payment_hash, recipient_onion, keysend_preimage, route, retry_strategy,
1572
+ payment_hash, recipient_onion, keysend_preimage, None , route, retry_strategy,
1565
1573
payment_params, entropy_source, best_block_height
1566
1574
) ;
1567
1575
entry. insert ( payment) ;
@@ -1572,8 +1580,9 @@ impl OutboundPayments {
1572
1580
1573
1581
fn create_pending_payment < ES : Deref > (
1574
1582
& self , payment_hash : PaymentHash , recipient_onion : RecipientOnionFields ,
1575
- keysend_preimage : Option < PaymentPreimage > , route : & Route , retry_strategy : Option < Retry > ,
1576
- payment_params : Option < PaymentParameters > , entropy_source : & ES , best_block_height : u32
1583
+ keysend_preimage : Option < PaymentPreimage > , invoice_request : Option < InvoiceRequest > ,
1584
+ route : & Route , retry_strategy : Option < Retry > , payment_params : Option < PaymentParameters > ,
1585
+ entropy_source : & ES , best_block_height : u32
1577
1586
) -> ( PendingOutboundPayment , Vec < [ u8 ; 32 ] > )
1578
1587
where
1579
1588
ES :: Target : EntropySource ,
@@ -1594,6 +1603,7 @@ impl OutboundPayments {
1594
1603
payment_secret : recipient_onion. payment_secret ,
1595
1604
payment_metadata : recipient_onion. payment_metadata ,
1596
1605
keysend_preimage,
1606
+ invoice_request,
1597
1607
custom_tlvs : recipient_onion. custom_tlvs ,
1598
1608
starting_block_height : best_block_height,
1599
1609
total_msat : route. get_total_amount ( ) ,
@@ -2155,6 +2165,7 @@ impl OutboundPayments {
2155
2165
payment_secret: None , // only used for retries, and we'll never retry on startup
2156
2166
payment_metadata: None , // only used for retries, and we'll never retry on startup
2157
2167
keysend_preimage: None , // only used for retries, and we'll never retry on startup
2168
+ invoice_request: None , // only used for retries, and we'll never retry on startup
2158
2169
custom_tlvs: Vec :: new( ) , // only used for retries, and we'll never retry on startup
2159
2170
pending_amt_msat: path_amt,
2160
2171
pending_fee_msat: Some ( path_fee) ,
@@ -2241,6 +2252,7 @@ impl_writeable_tlv_based_enum_upgradable!(PendingOutboundPayment,
2241
2252
( 9 , custom_tlvs, optional_vec) ,
2242
2253
( 10 , starting_block_height, required) ,
2243
2254
( 11 , remaining_max_total_routing_fee_msat, option) ,
2255
+ ( 13 , invoice_request, option) ,
2244
2256
( not_written, retry_strategy, ( static_value, None ) ) ,
2245
2257
( not_written, attempts, ( static_value, PaymentAttempts :: new( ) ) ) ,
2246
2258
} ,
0 commit comments