Skip to content

Commit 7843a8d

Browse files
committed
Store LSPFeeLimits in metadata store for JIT channel payments
In `receive_via_jit_channel_inner`, insert a `PaymentMetadataKind::LSPFeeLimits` entry into the `PaymentMetadataStore` so JIT channel fee limits are persisted independently of the `PaymentStore` entry. In the `PaymentClaimable` event handler, add a fallback path that checks the metadata store for LSP fee limits when the `PaymentKind` doesn't carry them directly. Generated with the assistance of AI tools. Co-Authored-By: HAL 9000
1 parent 8ee0d43 commit 7843a8d

2 files changed

Lines changed: 29 additions & 2 deletions

File tree

src/event.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,21 @@ where
712712
})
713713
.unwrap_or(0)
714714
},
715-
_ => 0,
715+
_ => {
716+
// Fallback: check the metadata store for LSP fee limits.
717+
self.payment_metadata_store
718+
.get_lsp_fee_limits_for_payment_id(&payment_id)
719+
.and_then(|limits| {
720+
limits.max_total_opening_fee_msat.or_else(|| {
721+
limits.max_proportional_opening_fee_ppm_msat.and_then(
722+
|max_prop_fee| {
723+
compute_opening_fee(amount_msat, 0, max_prop_fee)
724+
},
725+
)
726+
})
727+
})
728+
.unwrap_or(0)
729+
},
716730
};
717731

718732
if counterparty_skimmed_fee_msat > max_total_opening_fee_msat {

src/payment/bolt11.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use lightning::ln::channelmanager::{
1818
};
1919
use lightning::ln::outbound_payment::{Bolt11PaymentError, Retry, RetryableSendFailure};
2020
use lightning::routing::router::{PaymentParameters, RouteParameters, RouteParametersConfig};
21+
use lightning::sign::EntropySource;
2122
use lightning_invoice::{
2223
Bolt11Invoice as LdkBolt11Invoice, Bolt11InvoiceDescription as LdkBolt11InvoiceDescription,
2324
};
@@ -30,7 +31,9 @@ use crate::error::Error;
3031
use crate::ffi::{maybe_deref, maybe_try_convert_enum, maybe_wrap};
3132
use crate::liquidity::LiquiditySource;
3233
use crate::logger::{log_error, log_info, LdkLogger, Logger};
33-
use crate::payment::metadata_store::PaymentMetadataStore;
34+
use crate::payment::metadata_store::{
35+
MetadataId, PaymentMetadataEntry, PaymentMetadataKind, PaymentMetadataStore,
36+
};
3437
use crate::payment::store::{
3538
LSPFeeLimits, PaymentDetails, PaymentDetailsUpdate, PaymentDirection, PaymentKind,
3639
PaymentStatus,
@@ -734,6 +737,16 @@ impl Bolt11Payment {
734737
max_proportional_opening_fee_ppm_msat: lsp_prop_opening_fee,
735738
};
736739
let id = PaymentId(payment_hash.0);
740+
741+
// Store LSP fee limits in the metadata store.
742+
let metadata_id = MetadataId { id: self.keys_manager.get_secure_random_bytes() };
743+
let metadata_entry = PaymentMetadataEntry {
744+
id: metadata_id,
745+
kind: PaymentMetadataKind::LSPFeeLimits { limits: lsp_fee_limits },
746+
payment_ids: vec![id],
747+
};
748+
self.payment_metadata_store.insert(metadata_entry)?;
749+
737750
let preimage =
738751
self.channel_manager.get_payment_preimage(payment_hash, payment_secret.clone()).ok();
739752
let kind = PaymentKind::Bolt11Jit {

0 commit comments

Comments
 (0)