@@ -131,6 +131,9 @@ pub(super) struct PendingHTLCInfo {
131
131
/// may overshoot this in either case)
132
132
pub ( super ) outgoing_amt_msat : u64 ,
133
133
pub ( super ) outgoing_cltv_value : u32 ,
134
+ /// The fee being skimmed off the top of this HTLC. If this is a forward, it'll be the fee we are
135
+ /// skimming. If we're receiving this HTLC, it's the fee that our counterparty skimmed.
136
+ pub ( super ) skimmed_fee_msat : Option < u64 > ,
134
137
}
135
138
136
139
#[ derive( Clone ) ] // See Channel::revoke_and_ack for why, tl;dr: Rust bug
@@ -2616,6 +2619,7 @@ where
2616
2619
incoming_amt_msat : Some ( amt_msat) ,
2617
2620
outgoing_amt_msat : hop_data. amt_to_forward ,
2618
2621
outgoing_cltv_value : hop_data. outgoing_cltv_value ,
2622
+ skimmed_fee_msat : None ,
2619
2623
} )
2620
2624
}
2621
2625
@@ -2890,6 +2894,7 @@ where
2890
2894
incoming_amt_msat : Some ( msg. amount_msat ) ,
2891
2895
outgoing_amt_msat : next_hop_data. amt_to_forward ,
2892
2896
outgoing_cltv_value : next_hop_data. outgoing_cltv_value ,
2897
+ skimmed_fee_msat : None ,
2893
2898
} )
2894
2899
}
2895
2900
}
@@ -3485,13 +3490,16 @@ where
3485
3490
/// [`ChannelManager::fail_intercepted_htlc`] MUST be called in response to the event.
3486
3491
///
3487
3492
/// Note that LDK does not enforce fee requirements in `amt_to_forward_msat`, and will not stop
3488
- /// you from forwarding more than you received.
3493
+ /// you from forwarding more than you received. See
3494
+ /// [`HTLCIntercepted::expected_outbound_amount_msat`] for more on forwarding a different amount
3495
+ /// than expected.
3489
3496
///
3490
3497
/// Errors if the event was not handled in time, in which case the HTLC was automatically failed
3491
3498
/// backwards.
3492
3499
///
3493
3500
/// [`UserConfig::accept_intercept_htlcs`]: crate::util::config::UserConfig::accept_intercept_htlcs
3494
3501
/// [`HTLCIntercepted`]: events::Event::HTLCIntercepted
3502
+ /// [`HTLCIntercepted::expected_outbound_amount_msat`]: events::Event::HTLCIntercepted::expected_outbound_amount_msat
3495
3503
// TODO: when we move to deciding the best outbound channel at forward time, only take
3496
3504
// `next_node_id` and not `next_hop_channel_id`
3497
3505
pub fn forward_intercepted_htlc ( & self , intercept_id : InterceptId , next_hop_channel_id : & [ u8 ; 32 ] , next_node_id : PublicKey , amt_to_forward_msat : u64 ) -> Result < ( ) , APIError > {
@@ -3530,7 +3538,10 @@ where
3530
3538
} ,
3531
3539
_ => unreachable ! ( ) // Only `PendingHTLCRouting::Forward`s are intercepted
3532
3540
} ;
3541
+ let skimmed_fee_msat =
3542
+ payment. forward_info . outgoing_amt_msat . saturating_sub ( amt_to_forward_msat) ;
3533
3543
let pending_htlc_info = PendingHTLCInfo {
3544
+ skimmed_fee_msat : if skimmed_fee_msat == 0 { None } else { Some ( skimmed_fee_msat) } ,
3534
3545
outgoing_amt_msat : amt_to_forward_msat, routing, ..payment. forward_info
3535
3546
} ;
3536
3547
@@ -3600,7 +3611,7 @@ where
3600
3611
prev_short_channel_id, prev_htlc_id, prev_funding_outpoint, prev_user_channel_id,
3601
3612
forward_info: PendingHTLCInfo {
3602
3613
routing, incoming_shared_secret, payment_hash, outgoing_amt_msat,
3603
- outgoing_cltv_value, incoming_amt_msat : _
3614
+ outgoing_cltv_value, ..
3604
3615
}
3605
3616
} ) => {
3606
3617
macro_rules! failure_handler {
@@ -3713,7 +3724,7 @@ where
3713
3724
prev_short_channel_id, prev_htlc_id, prev_funding_outpoint, prev_user_channel_id : _,
3714
3725
forward_info : PendingHTLCInfo {
3715
3726
incoming_shared_secret, payment_hash, outgoing_amt_msat, outgoing_cltv_value,
3716
- routing : PendingHTLCRouting :: Forward { onion_packet, .. } , incoming_amt_msat : _ ,
3727
+ routing : PendingHTLCRouting :: Forward { onion_packet, .. } , ..
3717
3728
} ,
3718
3729
} ) => {
3719
3730
log_trace ! ( self . logger, "Adding HTLC from short id {} with payment_hash {} to channel with short id {} after delay" , prev_short_channel_id, log_bytes!( payment_hash. 0 ) , short_chan_id) ;
@@ -7448,6 +7459,7 @@ impl_writeable_tlv_based!(PendingHTLCInfo, {
7448
7459
( 6 , outgoing_amt_msat, required) ,
7449
7460
( 8 , outgoing_cltv_value, required) ,
7450
7461
( 9 , incoming_amt_msat, option) ,
7462
+ ( 10 , skimmed_fee_msat, option) ,
7451
7463
} ) ;
7452
7464
7453
7465
0 commit comments