@@ -181,6 +181,7 @@ pub(super) enum HTLCForwardInfo {
181
181
pub(crate) struct HTLCPreviousHopData {
182
182
// Note that this may be an outbound SCID alias for the associated channel.
183
183
short_channel_id: u64,
184
+ user_channel_id: Option<u128>,
184
185
htlc_id: u64,
185
186
incoming_packet_shared_secret: [u8; 32],
186
187
phantom_shared_secret: Option<[u8; 32]>,
@@ -221,6 +222,17 @@ struct ClaimableHTLC {
221
222
counterparty_skimmed_fee_msat: Option<u64>,
222
223
}
223
224
225
+ impl From<&ClaimableHTLC> for events::ClaimedHTLC {
226
+ fn from(val: &ClaimableHTLC) -> Self {
227
+ events::ClaimedHTLC {
228
+ channel_id: val.prev_hop.outpoint.to_channel_id(),
229
+ user_channel_id: val.prev_hop.user_channel_id.unwrap_or(0),
230
+ cltv_expiry: val.cltv_expiry,
231
+ value_msat: val.value,
232
+ }
233
+ }
234
+ }
235
+
224
236
/// A payment identifier used to uniquely identify a payment to LDK.
225
237
///
226
238
/// This is not exported to bindings users as we just use [u8; 32] directly
@@ -496,11 +508,15 @@ struct ClaimingPayment {
496
508
amount_msat: u64,
497
509
payment_purpose: events::PaymentPurpose,
498
510
receiver_node_id: PublicKey,
511
+ htlcs: Vec<events::ClaimedHTLC>,
512
+ sender_intended_value: Option<u64>,
499
513
}
500
514
impl_writeable_tlv_based!(ClaimingPayment, {
501
515
(0, amount_msat, required),
502
516
(2, payment_purpose, required),
503
517
(4, receiver_node_id, required),
518
+ (5, htlcs, optional_vec),
519
+ (7, sender_intended_value, option),
504
520
});
505
521
506
522
struct ClaimablePayment {
@@ -3785,6 +3801,7 @@ where
3785
3801
if let PendingHTLCRouting::Forward { short_channel_id, .. } = payment.forward_info.routing {
3786
3802
let htlc_source = HTLCSource::PreviousHopData(HTLCPreviousHopData {
3787
3803
short_channel_id: payment.prev_short_channel_id,
3804
+ user_channel_id: Some(payment.prev_user_channel_id),
3788
3805
outpoint: payment.prev_funding_outpoint,
3789
3806
htlc_id: payment.prev_htlc_id,
3790
3807
incoming_packet_shared_secret: payment.forward_info.incoming_shared_secret,
@@ -3832,6 +3849,7 @@ where
3832
3849
3833
3850
let htlc_source = HTLCSource::PreviousHopData(HTLCPreviousHopData {
3834
3851
short_channel_id: prev_short_channel_id,
3852
+ user_channel_id: Some(prev_user_channel_id),
3835
3853
outpoint: prev_funding_outpoint,
3836
3854
htlc_id: prev_htlc_id,
3837
3855
incoming_packet_shared_secret: incoming_shared_secret,
@@ -3936,7 +3954,7 @@ where
3936
3954
for forward_info in pending_forwards.drain(..) {
3937
3955
match forward_info {
3938
3956
HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo {
3939
- prev_short_channel_id, prev_htlc_id, prev_funding_outpoint, prev_user_channel_id: _ ,
3957
+ prev_short_channel_id, prev_htlc_id, prev_funding_outpoint, prev_user_channel_id,
3940
3958
forward_info: PendingHTLCInfo {
3941
3959
incoming_shared_secret, payment_hash, outgoing_amt_msat, outgoing_cltv_value,
3942
3960
routing: PendingHTLCRouting::Forward { onion_packet, .. }, skimmed_fee_msat, ..
@@ -3945,6 +3963,7 @@ where
3945
3963
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);
3946
3964
let htlc_source = HTLCSource::PreviousHopData(HTLCPreviousHopData {
3947
3965
short_channel_id: prev_short_channel_id,
3966
+ user_channel_id: Some(prev_user_channel_id),
3948
3967
outpoint: prev_funding_outpoint,
3949
3968
htlc_id: prev_htlc_id,
3950
3969
incoming_packet_shared_secret: incoming_shared_secret,
@@ -4026,6 +4045,7 @@ where
4026
4045
let claimable_htlc = ClaimableHTLC {
4027
4046
prev_hop: HTLCPreviousHopData {
4028
4047
short_channel_id: prev_short_channel_id,
4048
+ user_channel_id: Some(prev_user_channel_id),
4029
4049
outpoint: prev_funding_outpoint,
4030
4050
htlc_id: prev_htlc_id,
4031
4051
incoming_packet_shared_secret: incoming_shared_secret,
@@ -4055,6 +4075,7 @@ where
4055
4075
);
4056
4076
failed_forwards.push((HTLCSource::PreviousHopData(HTLCPreviousHopData {
4057
4077
short_channel_id: $htlc.prev_hop.short_channel_id,
4078
+ user_channel_id: $htlc.prev_hop.user_channel_id,
4058
4079
outpoint: prev_funding_outpoint,
4059
4080
htlc_id: $htlc.prev_hop.htlc_id,
4060
4081
incoming_packet_shared_secret: $htlc.prev_hop.incoming_packet_shared_secret,
@@ -4786,7 +4807,7 @@ where
4786
4807
&self.pending_events, &self.logger)
4787
4808
{ self.push_pending_forwards_ev(); }
4788
4809
},
4789
- HTLCSource::PreviousHopData(HTLCPreviousHopData { ref short_channel_id, ref htlc_id, ref incoming_packet_shared_secret, ref phantom_shared_secret, ref outpoint }) => {
4810
+ HTLCSource::PreviousHopData(HTLCPreviousHopData { ref short_channel_id, ref htlc_id, ref incoming_packet_shared_secret, ref phantom_shared_secret, ref outpoint, .. }) => {
4790
4811
log_trace!(self.logger, "Failing HTLC with payment_hash {} backwards from us with {:?}", log_bytes!(payment_hash.0), onion_error);
4791
4812
let err_packet = onion_error.get_encrypted_failure_packet(incoming_packet_shared_secret, phantom_shared_secret);
4792
4813
@@ -4873,9 +4894,11 @@ where
4873
4894
}
4874
4895
}
4875
4896
4897
+ let htlcs = payment.htlcs.iter().map(events::ClaimedHTLC::from).collect();
4898
+ let sender_intended_value = payment.htlcs.first().map(|htlc| htlc.total_msat);
4876
4899
let dup_purpose = claimable_payments.pending_claiming_payments.insert(payment_hash,
4877
4900
ClaimingPayment { amount_msat: payment.htlcs.iter().map(|source| source.value).sum(),
4878
- payment_purpose: payment.purpose, receiver_node_id,
4901
+ payment_purpose: payment.purpose, receiver_node_id, htlcs, sender_intended_value
4879
4902
});
4880
4903
if dup_purpose.is_some() {
4881
4904
debug_assert!(false, "Shouldn't get a duplicate pending claim event ever");
@@ -5139,9 +5162,20 @@ where
5139
5162
match action {
5140
5163
MonitorUpdateCompletionAction::PaymentClaimed { payment_hash } => {
5141
5164
let payment = self.claimable_payments.lock().unwrap().pending_claiming_payments.remove(&payment_hash);
5142
- if let Some(ClaimingPayment { amount_msat, payment_purpose: purpose, receiver_node_id }) = payment {
5165
+ if let Some(ClaimingPayment {
5166
+ amount_msat,
5167
+ payment_purpose: purpose,
5168
+ receiver_node_id,
5169
+ htlcs,
5170
+ sender_intended_value: sender_intended_total_msat,
5171
+ }) = payment {
5143
5172
self.pending_events.lock().unwrap().push_back((events::Event::PaymentClaimed {
5144
- payment_hash, purpose, amount_msat, receiver_node_id: Some(receiver_node_id),
5173
+ payment_hash,
5174
+ purpose,
5175
+ amount_msat,
5176
+ receiver_node_id: Some(receiver_node_id),
5177
+ htlcs,
5178
+ sender_intended_total_msat,
5145
5179
}, None));
5146
5180
}
5147
5181
},
@@ -6019,6 +6053,7 @@ where
6019
6053
log_info!(self.logger, "Failed to forward incoming HTLC: detected duplicate intercepted payment over short channel id {}", scid);
6020
6054
let htlc_source = HTLCSource::PreviousHopData(HTLCPreviousHopData {
6021
6055
short_channel_id: prev_short_channel_id,
6056
+ user_channel_id: Some(prev_user_channel_id),
6022
6057
outpoint: prev_funding_outpoint,
6023
6058
htlc_id: prev_htlc_id,
6024
6059
incoming_packet_shared_secret: forward_info.incoming_shared_secret,
@@ -7145,6 +7180,7 @@ where
7145
7180
if height >= htlc.forward_info.outgoing_cltv_value - HTLC_FAIL_BACK_BUFFER {
7146
7181
let prev_hop_data = HTLCSource::PreviousHopData(HTLCPreviousHopData {
7147
7182
short_channel_id: htlc.prev_short_channel_id,
7183
+ user_channel_id: Some(htlc.prev_user_channel_id),
7148
7184
htlc_id: htlc.prev_htlc_id,
7149
7185
incoming_packet_shared_secret: htlc.forward_info.incoming_shared_secret,
7150
7186
phantom_shared_secret: None,
@@ -7920,7 +7956,8 @@ impl_writeable_tlv_based!(HTLCPreviousHopData, {
7920
7956
(1, phantom_shared_secret, option),
7921
7957
(2, outpoint, required),
7922
7958
(4, htlc_id, required),
7923
- (6, incoming_packet_shared_secret, required)
7959
+ (6, incoming_packet_shared_secret, required),
7960
+ (7, user_channel_id, option),
7924
7961
});
7925
7962
7926
7963
impl Writeable for ClaimableHTLC {
@@ -9174,7 +9211,7 @@ where
9174
9211
.expect("Failed to get node_id for phantom node recipient");
9175
9212
receiver_node_id = Some(phantom_pubkey)
9176
9213
}
9177
- for claimable_htlc in payment.htlcs {
9214
+ for claimable_htlc in & payment.htlcs {
9178
9215
claimable_amt_msat += claimable_htlc.value;
9179
9216
9180
9217
// Add a holding-cell claim of the payment to the Channel, which should be
@@ -9210,6 +9247,8 @@ where
9210
9247
payment_hash,
9211
9248
purpose: payment.purpose,
9212
9249
amount_msat: claimable_amt_msat,
9250
+ htlcs: payment.htlcs.iter().map(events::ClaimedHTLC::from).collect(),
9251
+ sender_intended_total_msat: payment.htlcs.first().map(|htlc| htlc.total_msat),
9213
9252
}, None));
9214
9253
}
9215
9254
}
0 commit comments