@@ -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 {
@@ -3781,6 +3797,7 @@ where
3781
3797
if let PendingHTLCRouting::Forward { short_channel_id, .. } = payment.forward_info.routing {
3782
3798
let htlc_source = HTLCSource::PreviousHopData(HTLCPreviousHopData {
3783
3799
short_channel_id: payment.prev_short_channel_id,
3800
+ user_channel_id: Some(payment.prev_user_channel_id),
3784
3801
outpoint: payment.prev_funding_outpoint,
3785
3802
htlc_id: payment.prev_htlc_id,
3786
3803
incoming_packet_shared_secret: payment.forward_info.incoming_shared_secret,
@@ -3828,6 +3845,7 @@ where
3828
3845
3829
3846
let htlc_source = HTLCSource::PreviousHopData(HTLCPreviousHopData {
3830
3847
short_channel_id: prev_short_channel_id,
3848
+ user_channel_id: Some(prev_user_channel_id),
3831
3849
outpoint: prev_funding_outpoint,
3832
3850
htlc_id: prev_htlc_id,
3833
3851
incoming_packet_shared_secret: incoming_shared_secret,
@@ -3932,7 +3950,7 @@ where
3932
3950
for forward_info in pending_forwards.drain(..) {
3933
3951
match forward_info {
3934
3952
HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo {
3935
- prev_short_channel_id, prev_htlc_id, prev_funding_outpoint, prev_user_channel_id: _ ,
3953
+ prev_short_channel_id, prev_htlc_id, prev_funding_outpoint, prev_user_channel_id,
3936
3954
forward_info: PendingHTLCInfo {
3937
3955
incoming_shared_secret, payment_hash, outgoing_amt_msat, outgoing_cltv_value,
3938
3956
routing: PendingHTLCRouting::Forward { onion_packet, .. }, skimmed_fee_msat, ..
@@ -3941,6 +3959,7 @@ where
3941
3959
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);
3942
3960
let htlc_source = HTLCSource::PreviousHopData(HTLCPreviousHopData {
3943
3961
short_channel_id: prev_short_channel_id,
3962
+ user_channel_id: Some(prev_user_channel_id),
3944
3963
outpoint: prev_funding_outpoint,
3945
3964
htlc_id: prev_htlc_id,
3946
3965
incoming_packet_shared_secret: incoming_shared_secret,
@@ -4022,6 +4041,7 @@ where
4022
4041
let claimable_htlc = ClaimableHTLC {
4023
4042
prev_hop: HTLCPreviousHopData {
4024
4043
short_channel_id: prev_short_channel_id,
4044
+ user_channel_id: Some(prev_user_channel_id),
4025
4045
outpoint: prev_funding_outpoint,
4026
4046
htlc_id: prev_htlc_id,
4027
4047
incoming_packet_shared_secret: incoming_shared_secret,
@@ -4051,6 +4071,7 @@ where
4051
4071
);
4052
4072
failed_forwards.push((HTLCSource::PreviousHopData(HTLCPreviousHopData {
4053
4073
short_channel_id: $htlc.prev_hop.short_channel_id,
4074
+ user_channel_id: $htlc.prev_hop.user_channel_id,
4054
4075
outpoint: prev_funding_outpoint,
4055
4076
htlc_id: $htlc.prev_hop.htlc_id,
4056
4077
incoming_packet_shared_secret: $htlc.prev_hop.incoming_packet_shared_secret,
@@ -4782,7 +4803,7 @@ where
4782
4803
&self.pending_events, &self.logger)
4783
4804
{ self.push_pending_forwards_ev(); }
4784
4805
},
4785
- HTLCSource::PreviousHopData(HTLCPreviousHopData { ref short_channel_id, ref htlc_id, ref incoming_packet_shared_secret, ref phantom_shared_secret, ref outpoint }) => {
4806
+ HTLCSource::PreviousHopData(HTLCPreviousHopData { ref short_channel_id, ref htlc_id, ref incoming_packet_shared_secret, ref phantom_shared_secret, ref outpoint, .. }) => {
4786
4807
log_trace!(self.logger, "Failing HTLC with payment_hash {} backwards from us with {:?}", log_bytes!(payment_hash.0), onion_error);
4787
4808
let err_packet = onion_error.get_encrypted_failure_packet(incoming_packet_shared_secret, phantom_shared_secret);
4788
4809
@@ -4869,9 +4890,11 @@ where
4869
4890
}
4870
4891
}
4871
4892
4893
+ let htlcs = payment.htlcs.iter().map(events::ClaimedHTLC::from).collect();
4894
+ let sender_intended_value = payment.htlcs.first().map(|htlc| htlc.total_msat);
4872
4895
let dup_purpose = claimable_payments.pending_claiming_payments.insert(payment_hash,
4873
4896
ClaimingPayment { amount_msat: payment.htlcs.iter().map(|source| source.value).sum(),
4874
- payment_purpose: payment.purpose, receiver_node_id,
4897
+ payment_purpose: payment.purpose, receiver_node_id, htlcs, sender_intended_value
4875
4898
});
4876
4899
if dup_purpose.is_some() {
4877
4900
debug_assert!(false, "Shouldn't get a duplicate pending claim event ever");
@@ -5129,9 +5152,20 @@ where
5129
5152
match action {
5130
5153
MonitorUpdateCompletionAction::PaymentClaimed { payment_hash } => {
5131
5154
let payment = self.claimable_payments.lock().unwrap().pending_claiming_payments.remove(&payment_hash);
5132
- if let Some(ClaimingPayment { amount_msat, payment_purpose: purpose, receiver_node_id }) = payment {
5155
+ if let Some(ClaimingPayment {
5156
+ amount_msat,
5157
+ payment_purpose: purpose,
5158
+ receiver_node_id,
5159
+ htlcs,
5160
+ sender_intended_value: sender_intended_total_msat,
5161
+ }) = payment {
5133
5162
self.pending_events.lock().unwrap().push_back((events::Event::PaymentClaimed {
5134
- payment_hash, purpose, amount_msat, receiver_node_id: Some(receiver_node_id),
5163
+ payment_hash,
5164
+ purpose,
5165
+ amount_msat,
5166
+ receiver_node_id: Some(receiver_node_id),
5167
+ htlcs,
5168
+ sender_intended_total_msat,
5135
5169
}, None));
5136
5170
}
5137
5171
},
@@ -6006,6 +6040,7 @@ where
6006
6040
log_info!(self.logger, "Failed to forward incoming HTLC: detected duplicate intercepted payment over short channel id {}", scid);
6007
6041
let htlc_source = HTLCSource::PreviousHopData(HTLCPreviousHopData {
6008
6042
short_channel_id: prev_short_channel_id,
6043
+ user_channel_id: Some(prev_user_channel_id),
6009
6044
outpoint: prev_funding_outpoint,
6010
6045
htlc_id: prev_htlc_id,
6011
6046
incoming_packet_shared_secret: forward_info.incoming_shared_secret,
@@ -7124,6 +7159,7 @@ where
7124
7159
if height >= htlc.forward_info.outgoing_cltv_value - HTLC_FAIL_BACK_BUFFER {
7125
7160
let prev_hop_data = HTLCSource::PreviousHopData(HTLCPreviousHopData {
7126
7161
short_channel_id: htlc.prev_short_channel_id,
7162
+ user_channel_id: Some(htlc.prev_user_channel_id),
7127
7163
htlc_id: htlc.prev_htlc_id,
7128
7164
incoming_packet_shared_secret: htlc.forward_info.incoming_shared_secret,
7129
7165
phantom_shared_secret: None,
@@ -7899,7 +7935,8 @@ impl_writeable_tlv_based!(HTLCPreviousHopData, {
7899
7935
(1, phantom_shared_secret, option),
7900
7936
(2, outpoint, required),
7901
7937
(4, htlc_id, required),
7902
- (6, incoming_packet_shared_secret, required)
7938
+ (6, incoming_packet_shared_secret, required),
7939
+ (7, user_channel_id, option),
7903
7940
});
7904
7941
7905
7942
impl Writeable for ClaimableHTLC {
@@ -9147,7 +9184,7 @@ where
9147
9184
.expect("Failed to get node_id for phantom node recipient");
9148
9185
receiver_node_id = Some(phantom_pubkey)
9149
9186
}
9150
- for claimable_htlc in payment.htlcs {
9187
+ for claimable_htlc in & payment.htlcs {
9151
9188
claimable_amt_msat += claimable_htlc.value;
9152
9189
9153
9190
// Add a holding-cell claim of the payment to the Channel, which should be
@@ -9183,6 +9220,8 @@ where
9183
9220
payment_hash,
9184
9221
purpose: payment.purpose,
9185
9222
amount_msat: claimable_amt_msat,
9223
+ htlcs: payment.htlcs.iter().map(events::ClaimedHTLC::from).collect(),
9224
+ sender_intended_total_msat: payment.htlcs.first().map(|htlc| htlc.total_msat),
9186
9225
}, None));
9187
9226
}
9188
9227
}
0 commit comments