Skip to content

Commit 925a0cb

Browse files
Include invreq in payment onion when sending async payments
Past commits have set us up to include invoice requests in outbound async payment onions. Here we actually pull the invoice request from where it's stored in outbound_payments and pass it into the correct utility for inclusion in the onion on initial send. Per BOLTs PR 1149, when paying a static invoice we need to include our original invoice request in the HTLC onion since the recipient wouldn't have received it previously.
1 parent 520ae0b commit 925a0cb

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

lightning/src/ln/outbound_payment.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ impl OutboundPayments {
881881
route_params.max_total_routing_fee_msat = Some(max_fee_msat);
882882
}
883883
self.send_payment_for_bolt12_invoice_internal(
884-
payment_id, payment_hash, None, route_params, retry_strategy, router, first_hops,
884+
payment_id, payment_hash, None, None, route_params, retry_strategy, router, first_hops,
885885
inflight_htlcs, entropy_source, node_signer, node_id_lookup, secp_ctx, best_block_height,
886886
logger, pending_events, send_payment_along_path
887887
)
@@ -891,10 +891,10 @@ impl OutboundPayments {
891891
R: Deref, ES: Deref, NS: Deref, NL: Deref, IH, SP, L: Deref
892892
>(
893893
&self, payment_id: PaymentId, payment_hash: PaymentHash,
894-
keysend_preimage: Option<PaymentPreimage>, mut route_params: RouteParameters,
895-
retry_strategy: Retry, router: &R, first_hops: Vec<ChannelDetails>, inflight_htlcs: IH,
896-
entropy_source: &ES, node_signer: &NS, node_id_lookup: &NL,
897-
secp_ctx: &Secp256k1<secp256k1::All>, best_block_height: u32, logger: &L,
894+
keysend_preimage: Option<PaymentPreimage>, invoice_request: Option<&InvoiceRequest>,
895+
mut route_params: RouteParameters, retry_strategy: Retry, router: &R,
896+
first_hops: Vec<ChannelDetails>, inflight_htlcs: IH, entropy_source: &ES, node_signer: &NS,
897+
node_id_lookup: &NL, secp_ctx: &Secp256k1<secp256k1::All>, best_block_height: u32, logger: &L,
898898
pending_events: &Mutex<VecDeque<(events::Event, Option<EventCompletionAction>)>>,
899899
send_payment_along_path: SP,
900900
) -> Result<(), Bolt12PaymentError>
@@ -964,9 +964,9 @@ impl OutboundPayments {
964964
}
965965

966966
let result = self.pay_route_internal(
967-
&route, payment_hash, &recipient_onion, keysend_preimage, None, payment_id,
968-
Some(route_params.final_value_msat), onion_session_privs, node_signer,
969-
best_block_height, &send_payment_along_path
967+
&route, payment_hash, &recipient_onion, keysend_preimage, invoice_request, payment_id,
968+
Some(route_params.final_value_msat), onion_session_privs, node_signer, best_block_height,
969+
&send_payment_along_path
970970
);
971971
log_info!(
972972
logger, "Sending payment with id {} and hash {} returned {:?}", payment_id,
@@ -1082,23 +1082,24 @@ impl OutboundPayments {
10821082
IH: Fn() -> InFlightHtlcs,
10831083
SP: Fn(SendAlongPathArgs) -> Result<(), APIError>,
10841084
{
1085-
let (payment_hash, keysend_preimage, route_params, retry_strategy) =
1085+
let (payment_hash, keysend_preimage, route_params, retry_strategy, invoice_request) =
10861086
match self.pending_outbound_payments.lock().unwrap().entry(payment_id) {
10871087
hash_map::Entry::Occupied(entry) => match entry.get() {
10881088
PendingOutboundPayment::StaticInvoiceReceived {
1089-
payment_hash, route_params, retry_strategy, keysend_preimage, ..
1089+
payment_hash, route_params, retry_strategy, keysend_preimage, invoice_request, ..
10901090
} => {
1091-
(*payment_hash, *keysend_preimage, route_params.clone(), *retry_strategy)
1091+
(*payment_hash, *keysend_preimage, route_params.clone(), *retry_strategy,
1092+
invoice_request.clone())
10921093
},
10931094
_ => return Err(Bolt12PaymentError::DuplicateInvoice),
10941095
},
10951096
hash_map::Entry::Vacant(_) => return Err(Bolt12PaymentError::UnexpectedInvoice),
10961097
};
10971098

10981099
self.send_payment_for_bolt12_invoice_internal(
1099-
payment_id, payment_hash, Some(keysend_preimage), route_params, retry_strategy, router,
1100-
first_hops, inflight_htlcs, entropy_source, node_signer, node_id_lookup, secp_ctx,
1101-
best_block_height, logger, pending_events, send_payment_along_path
1100+
payment_id, payment_hash, Some(keysend_preimage), Some(&invoice_request), route_params,
1101+
retry_strategy, router, first_hops, inflight_htlcs, entropy_source, node_signer,
1102+
node_id_lookup, secp_ctx, best_block_height, logger, pending_events, send_payment_along_path
11021103
)
11031104
}
11041105

0 commit comments

Comments
 (0)