1
- //! Utilities for channelmanager.rs
1
+ //! Utilities to decode payment onions and do contextless validation of incoming payments.
2
2
//!
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.
4
5
5
6
use bitcoin:: hashes:: Hash ;
6
7
use bitcoin:: hashes:: sha256:: Hash as Sha256 ;
@@ -179,7 +180,9 @@ pub(super) fn create_recv_pending_htlc_info(
179
180
} )
180
181
}
181
182
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
+ ///
183
186
/// This does all the relevant context-free checks that LDK requires for payment relay or
184
187
/// acceptance. If the payment is to be received, and the amount matches the expected amount for
185
188
/// 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(
188
191
/// [`Event::PaymentClaimable`]: crate::events::Event::PaymentClaimable
189
192
pub fn peel_payment_onion < NS : Deref , L : Deref , T : secp256k1:: Verification > (
190
193
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 ,
192
195
) -> Result < PendingHTLCInfo , InboundOnionErr >
193
196
where
194
197
NS :: Target : NodeSigner ,
@@ -227,6 +230,10 @@ where
227
230
err_data : Vec :: new ( ) ,
228
231
} ) ;
229
232
}
233
+
234
+ // TODO: If this is potentially a phantom payment we should decode the phantom payment
235
+ // onion here and check it.
236
+
230
237
create_fwd_pending_htlc_info (
231
238
msg, next_hop_data, next_hop_hmac, new_packet_bytes, shared_secret,
232
239
Some ( next_packet_pubkey)
@@ -235,7 +242,7 @@ where
235
242
onion_utils:: Hop :: Receive ( received_data) => {
236
243
create_recv_pending_htlc_info (
237
244
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,
239
246
) ?
240
247
}
241
248
} )
@@ -410,7 +417,7 @@ mod tests {
410
417
let msg = make_update_add_msg ( amount_msat, cltv_expiry, payment_hash, onion) ;
411
418
let logger = test_utils:: TestLogger :: with_id ( "bob" . to_string ( ) ) ;
412
419
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 )
414
421
. map_err ( |e| e. msg ) . unwrap ( ) ;
415
422
416
423
let next_onion = match peeled. routing {
@@ -421,7 +428,7 @@ mod tests {
421
428
} ;
422
429
423
430
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 )
425
432
. map_err ( |e| e. msg ) . unwrap ( ) ;
426
433
427
434
match peeled2. routing {
0 commit comments