Skip to content

Commit efcef2d

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 efcef2d

1 file changed

Lines changed: 9 additions & 20 deletions

File tree

lightning-liquidity/src/lsps4/service.rs

Lines changed: 9 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,22 @@ 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 {
760749
log_error!(
761750
self.logger,
762-
"Skimmed fee equaled the entire HTLC amount for {:?}. Skipping skim.",
751+
"Skim would have consumed the entire HTLC {:?}; forwarding without a skim.",
763752
htlc_id
764753
);
765-
fee_msat = 0;
766-
amount_to_forward_msat = expected_outbound_msat;
767754
}
768755

769-
ComputedHtlc { htlc, amount_to_forward_msat, skimmed_fee_msat: fee_msat }
756+
let amount_to_forward_msat = expected_outbound_msat.saturating_sub(skimmed_fee_msat);
757+
758+
ComputedHtlc { htlc, amount_to_forward_msat, skimmed_fee_msat }
770759
})
771760
.collect();
772761

0 commit comments

Comments
 (0)