Skip to content

Commit be02889

Browse files
committed
Allow users to accept skimmed fees in calling peel_payment_onion
LSP users who wish to use `peel_payment_onion` to understand if they'd accept an HTLC prior to receit should be able to check the skimmed fees just like they would for full payment receipt. Thus, we need to expose the fee-skimming acceptance bool to `peel_payment_onion`, which we do here, in addition to some doc cleanups.
1 parent 1290e04 commit be02889

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

lightning/src/ln/onion_payment.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
//! Utilities for channelmanager.rs
1+
//! Utilities to decode payment onions and do contextless validation of incoming payments.
22
//!
3-
//! Includes a public [`peel_payment_onion`] function for use by external projects or libraries.
3+
//! Primarily features [`peel_payment_onion`], which allows the decoding of an onion statelessly
4+
//! and can be used to predict whether we'd accept a payment.
45
56
use bitcoin::hashes::Hash;
67
use bitcoin::hashes::sha256::Hash as Sha256;
@@ -179,7 +180,9 @@ pub(super) fn create_recv_pending_htlc_info(
179180
})
180181
}
181182

182-
/// Peel one layer off an incoming onion, returning [`PendingHTLCInfo`] (either Forward or Receive).
183+
/// Peel one layer off an incoming onion, returning a [`PendingHTLCInfo`] which provides details on
184+
/// where the sender intended the HTLC to go.
185+
///
183186
/// This does all the relevant context-free checks that LDK requires for payment relay or
184187
/// acceptance. If the payment is to be received, and the amount matches the expected amount for
185188
/// a given invoice, this indicates the [`msgs::UpdateAddHTLC`], once fully committed in the
@@ -188,7 +191,7 @@ pub(super) fn create_recv_pending_htlc_info(
188191
/// [`Event::PaymentClaimable`]: crate::events::Event::PaymentClaimable
189192
pub fn peel_payment_onion<NS: Deref, L: Deref, T: secp256k1::Verification>(
190193
msg: &msgs::UpdateAddHTLC, node_signer: &NS, logger: &L, secp_ctx: &Secp256k1<T>,
191-
cur_height: u32, accept_mpp_keysend: bool,
194+
cur_height: u32, accept_mpp_keysend: bool, allow_skimmed_fees: bool,
192195
) -> Result<PendingHTLCInfo, InboundOnionErr>
193196
where
194197
NS::Target: NodeSigner,
@@ -227,6 +230,10 @@ where
227230
err_data: Vec::new(),
228231
});
229232
}
233+
234+
// TODO: If this is potentially a phantom payment we should decode the phantom payment
235+
// onion here and check it.
236+
230237
create_fwd_pending_htlc_info(
231238
msg, next_hop_data, next_hop_hmac, new_packet_bytes, shared_secret,
232239
Some(next_packet_pubkey)
@@ -235,7 +242,7 @@ where
235242
onion_utils::Hop::Receive(received_data) => {
236243
create_recv_pending_htlc_info(
237244
received_data, shared_secret, msg.payment_hash, msg.amount_msat, msg.cltv_expiry,
238-
None, false, msg.skimmed_fee_msat, cur_height, accept_mpp_keysend,
245+
None, allow_skimmed_fees, msg.skimmed_fee_msat, cur_height, accept_mpp_keysend,
239246
)?
240247
}
241248
})
@@ -410,7 +417,7 @@ mod tests {
410417
let msg = make_update_add_msg(amount_msat, cltv_expiry, payment_hash, onion);
411418
let logger = test_utils::TestLogger::with_id("bob".to_string());
412419

413-
let peeled = peel_payment_onion(&msg, &&bob, &&logger, &secp_ctx, cur_height, true)
420+
let peeled = peel_payment_onion(&msg, &&bob, &&logger, &secp_ctx, cur_height, true, false)
414421
.map_err(|e| e.msg).unwrap();
415422

416423
let next_onion = match peeled.routing {
@@ -421,7 +428,7 @@ mod tests {
421428
};
422429

423430
let msg2 = make_update_add_msg(amount_msat, cltv_expiry, payment_hash, next_onion);
424-
let peeled2 = peel_payment_onion(&msg2, &&charlie, &&logger, &secp_ctx, cur_height, true)
431+
let peeled2 = peel_payment_onion(&msg2, &&charlie, &&logger, &secp_ctx, cur_height, true, false)
425432
.map_err(|e| e.msg).unwrap();
426433

427434
match peeled2.routing {

0 commit comments

Comments
 (0)