Skip to content

Commit 0202964

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 fc211db commit 0202964

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/event.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,21 @@ where
750750
})
751751
.unwrap_or(0)
752752
},
753-
_ => 0,
753+
_ => {
754+
// Fallback: check the metadata store for LSP fee limits.
755+
self.payment_metadata_store
756+
.get_lsp_fee_limits_for_payment_id(&payment_id)
757+
.and_then(|limits| {
758+
limits.max_total_opening_fee_msat.or_else(|| {
759+
limits.max_proportional_opening_fee_ppm_msat.and_then(
760+
|max_prop_fee| {
761+
compute_opening_fee(amount_msat, 0, max_prop_fee)
762+
},
763+
)
764+
})
765+
})
766+
.unwrap_or(0)
767+
},
754768
};
755769

756770
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,
@@ -212,6 +215,16 @@ impl Bolt11Payment {
212215
max_proportional_opening_fee_ppm_msat: lsp_prop_opening_fee,
213216
};
214217
let id = PaymentId(payment_hash.0);
218+
219+
// Store LSP fee limits in the metadata store.
220+
let metadata_id = MetadataId { id: self.keys_manager.get_secure_random_bytes() };
221+
let metadata_entry = PaymentMetadataEntry {
222+
id: metadata_id,
223+
kind: PaymentMetadataKind::LSPFeeLimits { limits: lsp_fee_limits },
224+
payment_ids: vec![id],
225+
};
226+
self.payment_metadata_store.insert(metadata_entry)?;
227+
215228
let preimage =
216229
self.channel_manager.get_payment_preimage(payment_hash, payment_secret.clone()).ok();
217230
let kind = PaymentKind::Bolt11Jit {

0 commit comments

Comments
 (0)