Skip to content

Commit e0600cc

Browse files
committed
Update AwaitingInvoice to Include ManualRoutingParameters
When `pay_for_offer` is called, it creates a new `PendingOutboundPayment` entry with relevant values used when the corresponding invoice is received. This update modifies `AwaitingInvoice` to include the entire `ManualRoutingParameters` struct instead of just `max_total_routing_fee_msat`. This change ensures that all manual routing parameters are available when finding the payment route.
1 parent c52ab5f commit e0600cc

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

lightning/src/ln/outbound_payment.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::ln::onion_utils::{DecodedOnionFailure, HTLCFailReason};
2424
use crate::offers::invoice::Bolt12Invoice;
2525
use crate::offers::invoice_request::InvoiceRequest;
2626
use crate::offers::nonce::Nonce;
27-
use crate::routing::router::{BlindedTail, InFlightHtlcs, Path, PaymentParameters, Route, RouteParameters, Router};
27+
use crate::routing::router::{BlindedTail, InFlightHtlcs, ManualRoutingParameters, Path, PaymentParameters, Route, RouteParameters, Router};
2828
use crate::sign::{EntropySource, NodeSigner, Recipient};
2929
use crate::util::errors::APIError;
3030
use crate::util::logger::Logger;
@@ -61,7 +61,7 @@ pub(crate) enum PendingOutboundPayment {
6161
AwaitingInvoice {
6262
expiration: StaleExpiration,
6363
retry_strategy: Retry,
64-
max_total_routing_fee_msat: Option<u64>,
64+
manual_routing_params: Option<ManualRoutingParameters>,
6565
retryable_invoice_request: Option<RetryableInvoiceRequest>
6666
},
6767
// This state will never be persisted to disk because we transition from `AwaitingInvoice` to
@@ -849,10 +849,12 @@ impl OutboundPayments {
849849
match self.pending_outbound_payments.lock().unwrap().entry(payment_id) {
850850
hash_map::Entry::Occupied(entry) => match entry.get() {
851851
PendingOutboundPayment::AwaitingInvoice {
852-
retry_strategy: retry, max_total_routing_fee_msat: max_total_fee, ..
852+
retry_strategy: retry, manual_routing_params, ..
853853
} => {
854854
retry_strategy = *retry;
855-
max_total_routing_fee_msat = *max_total_fee;
855+
max_total_routing_fee_msat = manual_routing_params.map(
856+
|params| params.max_total_routing_fee_msat
857+
).flatten();
856858
*entry.into_mut() = PendingOutboundPayment::InvoiceReceived {
857859
payment_hash,
858860
retry_strategy: *retry,
@@ -1004,7 +1006,7 @@ impl OutboundPayments {
10041006
match self.pending_outbound_payments.lock().unwrap().entry(payment_id) {
10051007
hash_map::Entry::Occupied(mut entry) => match entry.get() {
10061008
PendingOutboundPayment::AwaitingInvoice {
1007-
retry_strategy, retryable_invoice_request, max_total_routing_fee_msat, ..
1009+
retry_strategy, retryable_invoice_request, manual_routing_params, ..
10081010
} => {
10091011
let invreq = &retryable_invoice_request
10101012
.as_ref()
@@ -1031,7 +1033,7 @@ impl OutboundPayments {
10311033
let payment_hash = PaymentHash(Sha256::hash(&keysend_preimage.0).to_byte_array());
10321034
let pay_params = PaymentParameters::from_static_invoice(invoice);
10331035
let mut route_params = RouteParameters::from_payment_params_and_value(pay_params, amount_msat);
1034-
route_params.max_total_routing_fee_msat = *max_total_routing_fee_msat;
1036+
route_params.max_total_routing_fee_msat = manual_routing_params.map(|params| params.max_total_routing_fee_msat).flatten();
10351037

10361038
if let Err(()) = onion_utils::set_max_path_length(
10371039
&mut route_params, &RecipientOnionFields::spontaneous_empty(), Some(keysend_preimage),
@@ -1599,6 +1601,10 @@ impl OutboundPayments {
15991601
max_total_routing_fee_msat: Option<u64>, retryable_invoice_request: Option<RetryableInvoiceRequest>
16001602
) -> Result<(), ()> {
16011603
let mut pending_outbounds = self.pending_outbound_payments.lock().unwrap();
1604+
let manual_routing_params = max_total_routing_fee_msat.map(
1605+
|fee_msats| ManualRoutingParameters::new()
1606+
.with_max_total_routing_fee_msat(fee_msats)
1607+
);
16021608
match pending_outbounds.entry(payment_id) {
16031609
hash_map::Entry::Occupied(_) => Err(()),
16041610
hash_map::Entry::Vacant(entry) => {
@@ -1608,7 +1614,7 @@ impl OutboundPayments {
16081614
entry.insert(PendingOutboundPayment::AwaitingInvoice {
16091615
expiration,
16101616
retry_strategy,
1611-
max_total_routing_fee_msat,
1617+
manual_routing_params,
16121618
retryable_invoice_request,
16131619
});
16141620

@@ -2238,7 +2244,7 @@ impl_writeable_tlv_based_enum_upgradable!(PendingOutboundPayment,
22382244
(5, AwaitingInvoice) => {
22392245
(0, expiration, required),
22402246
(2, retry_strategy, required),
2241-
(4, max_total_routing_fee_msat, option),
2247+
(4, manual_routing_params, option),
22422248
(5, retryable_invoice_request, option),
22432249
},
22442250
(7, InvoiceReceived) => {

0 commit comments

Comments
 (0)