Skip to content

Commit d2299f1

Browse files
Add config knob for accepting underpaying HTLCs
See ChannelConfig::accept_underpaying_htlcs
1 parent d78dd48 commit d2299f1

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

lightning/src/util/config.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,36 @@ pub struct ChannelConfig {
397397
/// [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal
398398
/// [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background
399399
pub force_close_avoidance_max_fee_satoshis: u64,
400+
/// If set, allows this channel's counterparty to skim an additional fee off of this node's
401+
/// inbound HTLCs. Useful for liquidity providers to offload on-chain channel costs to end users.
402+
///
403+
/// Usage:
404+
/// - The payee will set this option and set its invoice route hints to use [`intercept scids`]
405+
/// generated by this channel's counterparty.
406+
/// - If this fee is being taken by a liquidity provider for a just-in-time channel, payees MUST
407+
/// disable MPP in their invoices unless they have a way to let their counterparty know when all
408+
/// MPP parts have been aggregated. Otherwise, excess channels may be opened for each MPP part.
409+
/// - The counterparty will get an [`HTLCIntercepted`] event upon payment forward, and call
410+
/// [`forward_intercepted_htlc`] with less than the amount provided in
411+
/// [`HTLCIntercepted::expected_outbound_amount_msat`]. The difference between the expected and
412+
/// actual forward amounts is their fee.
413+
///
414+
/// # Note
415+
/// It's important for payee wallet software to verify that [`PaymentClaimable::amount_msat`] is
416+
/// as-expected if this feature is activated, otherwise they may lose money!
417+
///
418+
/// # Note
419+
/// Switching on this config flag may break compatibility with versions of LDK prior to 0.0.116.
420+
///
421+
/// Default value: false.
422+
///
423+
/// [`intercept scids`]: crate::ln::channelmanager::ChannelManager::get_intercept_scid
424+
/// [`forward_intercepted_htlc`]: crate::ln::channelmanager::ChannelManager::forward_intercepted_htlc
425+
/// [`HTLCIntercepted`]: crate::events::Event::HTLCIntercepted
426+
/// [`HTLCIntercepted::expected_outbound_amount_msat`]: crate::events::Event::HTLCIntercepted::expected_outbound_amount_msat
427+
/// [`PaymentClaimable::amount_msat`]: crate::events::Event::PaymentClaimable::amount_msat
428+
// TODO: link to bLIP when it's merged
429+
pub accept_underpaying_htlcs: bool,
400430
}
401431

402432
impl ChannelConfig {
@@ -429,12 +459,14 @@ impl Default for ChannelConfig {
429459
cltv_expiry_delta: 6 * 12, // 6 blocks/hour * 12 hours
430460
max_dust_htlc_exposure_msat: 5_000_000,
431461
force_close_avoidance_max_fee_satoshis: 1000,
462+
accept_underpaying_htlcs: false,
432463
}
433464
}
434465
}
435466

436467
impl_writeable_tlv_based!(ChannelConfig, {
437468
(0, forwarding_fee_proportional_millionths, required),
469+
(1, accept_underpaying_htlcs, (default_value, false)),
438470
(2, forwarding_fee_base_msat, required),
439471
(4, cltv_expiry_delta, required),
440472
(6, max_dust_htlc_exposure_msat, required),
@@ -543,6 +575,7 @@ impl crate::util::ser::Readable for LegacyChannelConfig {
543575
cltv_expiry_delta,
544576
force_close_avoidance_max_fee_satoshis,
545577
forwarding_fee_base_msat,
578+
accept_underpaying_htlcs: false,
546579
},
547580
announced_channel,
548581
commit_upfront_shutdown_pubkey,

0 commit comments

Comments
 (0)