Skip to content

Commit 2404c93

Browse files
Include invreq in payment onion when retrying async payments.
1 parent 0a9be8e commit 2404c93

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12589,6 +12589,7 @@ where
1258912589
payment_secret: None, // only used for retries, and we'll never retry on startup
1259012590
payment_metadata: None, // only used for retries, and we'll never retry on startup
1259112591
keysend_preimage: None, // only used for retries, and we'll never retry on startup
12592+
invoice_request: None, // only used for retries, and we'll never retry on startup
1259212593
custom_tlvs: Vec::new(), // only used for retries, and we'll never retry on startup
1259312594
pending_amt_msat: path_amt,
1259412595
pending_fee_msat: Some(path_fee),

lightning/src/ln/outbound_payment.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ pub(crate) enum PendingOutboundPayment {
9494
payment_secret: Option<PaymentSecret>,
9595
payment_metadata: Option<Vec<u8>>,
9696
keysend_preimage: Option<PaymentPreimage>,
97+
invoice_request: Option<InvoiceRequest>,
9798
custom_tlvs: Vec<(u64, Vec<u8>)>,
9899
pending_amt_msat: u64,
99100
/// Used to track the fee paid. Present iff the payment was serialized on 0.0.103+.
@@ -946,18 +947,25 @@ impl OutboundPayments {
946947
};
947948

948949
let payment_params = Some(route_params.payment_params.clone());
949-
let (retryable_payment, onion_session_privs) = self.create_pending_payment(
950-
payment_hash, recipient_onion.clone(), keysend_preimage, &route, Some(retry_strategy),
951-
payment_params, entropy_source, best_block_height
952-
);
950+
let onion_session_privs;
953951
let mut invoice_request_opt = None;
954952
let mut outbounds = self.pending_outbound_payments.lock().unwrap();
955953
match outbounds.entry(payment_id) {
956954
hash_map::Entry::Occupied(entry) => match entry.remove() {
957955
PendingOutboundPayment::InvoiceReceived { .. } => {
956+
let (retryable_payment, session_privs) = self.create_pending_payment(
957+
payment_hash, recipient_onion.clone(), None, None, &route, Some(retry_strategy),
958+
payment_params, entropy_source, best_block_height
959+
);
960+
onion_session_privs = session_privs;
958961
outbounds.insert(payment_id, retryable_payment);
959962
},
960963
PendingOutboundPayment::StaticInvoiceReceived { invoice_request, .. } => {
964+
let (retryable_payment, session_privs) = self.create_pending_payment(
965+
payment_hash, recipient_onion.clone(), keysend_preimage, Some(invoice_request.clone()),
966+
&route, Some(retry_strategy), payment_params, entropy_source, best_block_height
967+
);
968+
onion_session_privs = session_privs;
961969
invoice_request_opt = Some(invoice_request);
962970
outbounds.insert(payment_id, retryable_payment);
963971
},
@@ -1560,7 +1568,7 @@ impl OutboundPayments {
15601568
hash_map::Entry::Occupied(_) => Err(PaymentSendFailure::DuplicatePayment),
15611569
hash_map::Entry::Vacant(entry) => {
15621570
let (payment, onion_session_privs) = self.create_pending_payment(
1563-
payment_hash, recipient_onion, keysend_preimage, route, retry_strategy,
1571+
payment_hash, recipient_onion, keysend_preimage, None, route, retry_strategy,
15641572
payment_params, entropy_source, best_block_height
15651573
);
15661574
entry.insert(payment);
@@ -1571,8 +1579,9 @@ impl OutboundPayments {
15711579

15721580
fn create_pending_payment<ES: Deref>(
15731581
&self, payment_hash: PaymentHash, recipient_onion: RecipientOnionFields,
1574-
keysend_preimage: Option<PaymentPreimage>, route: &Route, retry_strategy: Option<Retry>,
1575-
payment_params: Option<PaymentParameters>, entropy_source: &ES, best_block_height: u32
1582+
keysend_preimage: Option<PaymentPreimage>, invoice_request: Option<InvoiceRequest>,
1583+
route: &Route, retry_strategy: Option<Retry>, payment_params: Option<PaymentParameters>,
1584+
entropy_source: &ES, best_block_height: u32
15761585
) -> (PendingOutboundPayment, Vec<[u8; 32]>)
15771586
where
15781587
ES::Target: EntropySource,
@@ -1593,6 +1602,7 @@ impl OutboundPayments {
15931602
payment_secret: recipient_onion.payment_secret,
15941603
payment_metadata: recipient_onion.payment_metadata,
15951604
keysend_preimage,
1605+
invoice_request,
15961606
custom_tlvs: recipient_onion.custom_tlvs,
15971607
starting_block_height: best_block_height,
15981608
total_msat: route.get_total_amount(),
@@ -2178,6 +2188,7 @@ impl_writeable_tlv_based_enum_upgradable!(PendingOutboundPayment,
21782188
(9, custom_tlvs, optional_vec),
21792189
(10, starting_block_height, required),
21802190
(11, remaining_max_total_routing_fee_msat, option),
2191+
(13, invoice_request, option),
21812192
(not_written, retry_strategy, (static_value, None)),
21822193
(not_written, attempts, (static_value, PaymentAttempts::new())),
21832194
},

0 commit comments

Comments
 (0)