Skip to content

Commit c2279f8

Browse files
committed
Route the skim site through resolve_skim
Replace the inline compute_forward_fee block in calculate_htlc_actions_for_peer with a single resolve_skim call against a literal Flat(Standard) policy. This is the one place the LSP decides what to skim; routing it through the pure function is what later milestones need to swap the literal for a per-peer policy lookup. Not a strict no-op: it inherits the u128 overflow fix from resolve_skim, so a >9223-BTC HTLC is now skimmed 2% instead of overflowing and forwarding free. Every realistic HTLC is unchanged. The peer's stored policy is still ignored; every forward resolves Flat(Standard) until the lookup lands. The two old log lines (overflow, skim-ate-the-HTLC) collapse into one: resolve_skim can't overflow, so a zero skim on a non-zero HTLC can only mean the fee would have eaten the whole amount.
1 parent 8892efe commit c2279f8

2 files changed

Lines changed: 15 additions & 23 deletions

File tree

lightning-liquidity/src/lsps4/fee_policy.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,10 @@ impl_writeable_tlv_based_enum!(FeePolicy,
6060
///
6161
/// `standard_ppm` is the LSP's configured proportional rate, used only by [`FeeTier::Standard`].
6262
///
63-
/// The skim is waived in exactly one case: when it would consume the entire HTLC. A zero-value
64-
/// forward is rejected by the channel (`channel.rs` force-closes on a 0-msat `update_add_htlc`),
65-
/// so skimming the whole amount would break the forward; that is the only reason we ever waive.
63+
/// The skim is zero in two distinct cases. [`FeeTier::ZeroFee`] never skims, by design. Any other
64+
/// tier is additionally forced to zero when its fee would consume the entire HTLC: a zero-value
65+
/// forward is rejected by the channel (`channel.rs` force-closes on a 0-msat `update_add_htlc`), so
66+
/// skimming the whole amount would break the forward; dropping to zero forwards it intact instead.
6667
/// The proportional component is computed in 128-bit precision, so a very large HTLC is skimmed
6768
/// correctly rather than (as the previous `u64` arithmetic did) overflowing and forwarding the
6869
/// whole amount for free.

lightning-liquidity/src/lsps4/service.rs

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ use crate::lsps0::ser::{
1717
};
1818
use crate::lsps4::event::LSPS4ServiceEvent;
1919
use crate::lsps4::htlc_store::{HTLCStore, InterceptedHtlc};
20+
use crate::lsps4::fee_policy::{resolve_skim, FeePolicy, FeeTier};
2021
use crate::lsps4::scid_store::ScidStore;
21-
use crate::lsps4::utils::compute_forward_fee;
2222
use crate::message_queue::MessageQueue;
2323
use crate::prelude::hash_map::Entry;
2424
use crate::prelude::{new_hash_map, HashMap};
@@ -740,33 +740,24 @@ where
740740
}
741741

742742
let htlc_id = htlc.id();
743-
let mut fee_msat = match crate::lsps4::utils::compute_forward_fee(
743+
let skimmed_fee_msat = resolve_skim(
744+
&FeePolicy::Flat(FeeTier::Standard),
744745
expected_outbound_msat,
745746
self.config.forwarding_fee_proportional_millionths,
746-
) {
747-
Some(fee) => core::cmp::min(fee, expected_outbound_msat),
748-
None => {
749-
log_error!(
750-
self.logger,
751-
"Overflow while computing skimmed fee for intercepted HTLC {:?}. Skipping skim.",
752-
htlc_id
753-
);
754-
0
755-
},
756-
};
757-
758-
let mut amount_to_forward_msat = expected_outbound_msat.saturating_sub(fee_msat);
759-
if amount_to_forward_msat == 0 && fee_msat > 0 {
747+
);
748+
if skimmed_fee_msat == 0 {
749+
// The policy here is always Flat(Standard), so a zero skim can only mean the
750+
// fee would have consumed the entire HTLC; it is never a ZeroFee waiver yet.
760751
log_error!(
761752
self.logger,
762-
"Skimmed fee equaled the entire HTLC amount for {:?}. Skipping skim.",
753+
"Standard skim would have consumed the entire HTLC {:?}; forwarding the full amount.",
763754
htlc_id
764755
);
765-
fee_msat = 0;
766-
amount_to_forward_msat = expected_outbound_msat;
767756
}
768757

769-
ComputedHtlc { htlc, amount_to_forward_msat, skimmed_fee_msat: fee_msat }
758+
let amount_to_forward_msat = expected_outbound_msat.saturating_sub(skimmed_fee_msat);
759+
760+
ComputedHtlc { htlc, amount_to_forward_msat, skimmed_fee_msat }
770761
})
771762
.collect();
772763

0 commit comments

Comments
 (0)