@@ -306,6 +306,7 @@ pub(super) struct PendingAddHTLCInfo {
306
306
// Note that this may be an outbound SCID alias for the associated channel.
307
307
prev_short_channel_id: u64,
308
308
prev_htlc_id: u64,
309
+ prev_counterparty_node_id: Option<PublicKey>,
309
310
prev_channel_id: ChannelId,
310
311
prev_funding_outpoint: OutPoint,
311
312
prev_user_channel_id: u128,
@@ -349,9 +350,10 @@ pub(crate) struct HTLCPreviousHopData {
349
350
blinded_failure: Option<BlindedFailure>,
350
351
channel_id: ChannelId,
351
352
352
- // This field is consumed by `claim_funds_from_hop()` when updating a force-closed backwards
353
+ // These fields are consumed by `claim_funds_from_hop()` when updating a force-closed backwards
353
354
// channel with a preimage provided by the forward channel.
354
355
outpoint: OutPoint,
356
+ counterparty_node_id: Option<PublicKey>,
355
357
}
356
358
357
359
enum OnionPayload {
@@ -4692,6 +4694,7 @@ where
4692
4694
4693
4695
let mut per_source_pending_forward = [(
4694
4696
payment.prev_short_channel_id,
4697
+ payment.prev_counterparty_node_id,
4695
4698
payment.prev_funding_outpoint,
4696
4699
payment.prev_channel_id,
4697
4700
payment.prev_user_channel_id,
@@ -4722,6 +4725,7 @@ where
4722
4725
user_channel_id: Some(payment.prev_user_channel_id),
4723
4726
outpoint: payment.prev_funding_outpoint,
4724
4727
channel_id: payment.prev_channel_id,
4728
+ counterparty_node_id: payment.prev_counterparty_node_id,
4725
4729
htlc_id: payment.prev_htlc_id,
4726
4730
incoming_packet_shared_secret: payment.forward_info.incoming_shared_secret,
4727
4731
phantom_shared_secret: None,
@@ -4851,8 +4855,10 @@ where
4851
4855
4852
4856
// Process all of the forwards and failures for the channel in which the HTLCs were
4853
4857
// proposed to as a batch.
4854
- let pending_forwards = (incoming_scid, incoming_funding_txo, incoming_channel_id,
4855
- incoming_user_channel_id, htlc_forwards.drain(..).collect());
4858
+ let pending_forwards = (
4859
+ incoming_scid, Some(incoming_counterparty_node_id), incoming_funding_txo,
4860
+ incoming_channel_id, incoming_user_channel_id, htlc_forwards.drain(..).collect()
4861
+ );
4856
4862
self.forward_htlcs_without_forward_event(&mut [pending_forwards]);
4857
4863
for (htlc_fail, htlc_destination) in htlc_fails.drain(..) {
4858
4864
let failure = match htlc_fail {
@@ -4886,7 +4892,7 @@ where
4886
4892
4887
4893
let mut new_events = VecDeque::new();
4888
4894
let mut failed_forwards = Vec::new();
4889
- let mut phantom_receives: Vec<(u64, OutPoint, ChannelId, u128, Vec<(PendingHTLCInfo, u64)>)> = Vec::new();
4895
+ let mut phantom_receives: Vec<(u64, Option<PublicKey>, OutPoint, ChannelId, u128, Vec<(PendingHTLCInfo, u64)>)> = Vec::new();
4890
4896
{
4891
4897
let mut forward_htlcs = new_hash_map();
4892
4898
mem::swap(&mut forward_htlcs, &mut self.forward_htlcs.lock().unwrap());
@@ -4900,7 +4906,7 @@ where
4900
4906
match forward_info {
4901
4907
HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo {
4902
4908
prev_short_channel_id, prev_htlc_id, prev_channel_id, prev_funding_outpoint,
4903
- prev_user_channel_id, forward_info: PendingHTLCInfo {
4909
+ prev_user_channel_id, prev_counterparty_node_id, forward_info: PendingHTLCInfo {
4904
4910
routing, incoming_shared_secret, payment_hash, outgoing_amt_msat,
4905
4911
outgoing_cltv_value, ..
4906
4912
}
@@ -4915,6 +4921,7 @@ where
4915
4921
user_channel_id: Some(prev_user_channel_id),
4916
4922
channel_id: prev_channel_id,
4917
4923
outpoint: prev_funding_outpoint,
4924
+ counterparty_node_id: prev_counterparty_node_id,
4918
4925
htlc_id: prev_htlc_id,
4919
4926
incoming_packet_shared_secret: incoming_shared_secret,
4920
4927
phantom_shared_secret: $phantom_ss,
@@ -4977,7 +4984,10 @@ where
4977
4984
outgoing_cltv_value, Some(phantom_shared_secret), false, None,
4978
4985
current_height, self.default_configuration.accept_mpp_keysend)
4979
4986
{
4980
- Ok(info) => phantom_receives.push((prev_short_channel_id, prev_funding_outpoint, prev_channel_id, prev_user_channel_id, vec![(info, prev_htlc_id)])),
4987
+ Ok(info) => phantom_receives.push((
4988
+ prev_short_channel_id, prev_counterparty_node_id, prev_funding_outpoint,
4989
+ prev_channel_id, prev_user_channel_id, vec![(info, prev_htlc_id)]
4990
+ )),
4981
4991
Err(InboundHTLCErr { err_code, err_data, msg }) => failed_payment!(msg, err_code, err_data, Some(phantom_shared_secret))
4982
4992
}
4983
4993
},
@@ -5022,7 +5032,7 @@ where
5022
5032
let queue_fail_htlc_res = match forward_info {
5023
5033
HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo {
5024
5034
prev_short_channel_id, prev_htlc_id, prev_channel_id, prev_funding_outpoint,
5025
- prev_user_channel_id, forward_info: PendingHTLCInfo {
5035
+ prev_user_channel_id, prev_counterparty_node_id, forward_info: PendingHTLCInfo {
5026
5036
incoming_shared_secret, payment_hash, outgoing_amt_msat, outgoing_cltv_value,
5027
5037
routing: PendingHTLCRouting::Forward {
5028
5038
ref onion_packet, blinded, ..
@@ -5032,6 +5042,7 @@ where
5032
5042
let htlc_source = HTLCSource::PreviousHopData(HTLCPreviousHopData {
5033
5043
short_channel_id: prev_short_channel_id,
5034
5044
user_channel_id: Some(prev_user_channel_id),
5045
+ counterparty_node_id: prev_counterparty_node_id,
5035
5046
channel_id: prev_channel_id,
5036
5047
outpoint: prev_funding_outpoint,
5037
5048
htlc_id: prev_htlc_id,
@@ -5160,7 +5171,7 @@ where
5160
5171
match forward_info {
5161
5172
HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo {
5162
5173
prev_short_channel_id, prev_htlc_id, prev_channel_id, prev_funding_outpoint,
5163
- prev_user_channel_id, forward_info: PendingHTLCInfo {
5174
+ prev_user_channel_id, prev_counterparty_node_id, forward_info: PendingHTLCInfo {
5164
5175
routing, incoming_shared_secret, payment_hash, incoming_amt_msat, outgoing_amt_msat,
5165
5176
skimmed_fee_msat, ..
5166
5177
}
@@ -5198,6 +5209,7 @@ where
5198
5209
prev_hop: HTLCPreviousHopData {
5199
5210
short_channel_id: prev_short_channel_id,
5200
5211
user_channel_id: Some(prev_user_channel_id),
5212
+ counterparty_node_id: prev_counterparty_node_id,
5201
5213
channel_id: prev_channel_id,
5202
5214
outpoint: prev_funding_outpoint,
5203
5215
htlc_id: prev_htlc_id,
@@ -5230,6 +5242,7 @@ where
5230
5242
failed_forwards.push((HTLCSource::PreviousHopData(HTLCPreviousHopData {
5231
5243
short_channel_id: $htlc.prev_hop.short_channel_id,
5232
5244
user_channel_id: $htlc.prev_hop.user_channel_id,
5245
+ counterparty_node_id: $htlc.prev_hop.counterparty_node_id,
5233
5246
channel_id: prev_channel_id,
5234
5247
outpoint: prev_funding_outpoint,
5235
5248
htlc_id: $htlc.prev_hop.htlc_id,
@@ -6586,7 +6599,7 @@ where
6586
6599
pending_forwards: Vec<(PendingHTLCInfo, u64)>, pending_update_adds: Vec<msgs::UpdateAddHTLC>,
6587
6600
funding_broadcastable: Option<Transaction>,
6588
6601
channel_ready: Option<msgs::ChannelReady>, announcement_sigs: Option<msgs::AnnouncementSignatures>)
6589
- -> (Option<(u64, OutPoint, ChannelId, u128, Vec<(PendingHTLCInfo, u64)>)>, Option<(u64, Vec<msgs::UpdateAddHTLC>)>) {
6602
+ -> (Option<(u64, Option<PublicKey>, OutPoint, ChannelId, u128, Vec<(PendingHTLCInfo, u64)>)>, Option<(u64, Vec<msgs::UpdateAddHTLC>)>) {
6590
6603
let logger = WithChannelContext::from(&self.logger, &channel.context, None);
6591
6604
log_trace!(logger, "Handling channel resumption for channel {} with {} RAA, {} commitment update, {} pending forwards, {} pending update_add_htlcs, {}broadcasting funding, {} channel ready, {} announcement",
6592
6605
&channel.context.channel_id(),
@@ -6602,8 +6615,11 @@ where
6602
6615
6603
6616
let mut htlc_forwards = None;
6604
6617
if !pending_forwards.is_empty() {
6605
- htlc_forwards = Some((short_channel_id, channel.context.get_funding_txo().unwrap(),
6606
- channel.context.channel_id(), channel.context.get_user_id(), pending_forwards));
6618
+ htlc_forwards = Some((
6619
+ short_channel_id, Some(channel.context.get_counterparty_node_id()),
6620
+ channel.context.get_funding_txo().unwrap(), channel.context.channel_id(),
6621
+ channel.context.get_user_id(), pending_forwards
6622
+ ));
6607
6623
}
6608
6624
let mut decode_update_add_htlcs = None;
6609
6625
if !pending_update_adds.is_empty() {
@@ -7646,15 +7662,15 @@ where
7646
7662
}
7647
7663
7648
7664
#[inline]
7649
- fn forward_htlcs(&self, per_source_pending_forwards: &mut [(u64, OutPoint, ChannelId, u128, Vec<(PendingHTLCInfo, u64)>)]) {
7665
+ fn forward_htlcs(&self, per_source_pending_forwards: &mut [(u64, Option<PublicKey>, OutPoint, ChannelId, u128, Vec<(PendingHTLCInfo, u64)>)]) {
7650
7666
let push_forward_event = self.forward_htlcs_without_forward_event(per_source_pending_forwards);
7651
7667
if push_forward_event { self.push_pending_forwards_ev() }
7652
7668
}
7653
7669
7654
7670
#[inline]
7655
- fn forward_htlcs_without_forward_event(&self, per_source_pending_forwards: &mut [(u64, OutPoint, ChannelId, u128, Vec<(PendingHTLCInfo, u64)>)]) -> bool {
7671
+ fn forward_htlcs_without_forward_event(&self, per_source_pending_forwards: &mut [(u64, Option<PublicKey>, OutPoint, ChannelId, u128, Vec<(PendingHTLCInfo, u64)>)]) -> bool {
7656
7672
let mut push_forward_event = false;
7657
- for &mut (prev_short_channel_id, prev_funding_outpoint, prev_channel_id, prev_user_channel_id, ref mut pending_forwards) in per_source_pending_forwards {
7673
+ for &mut (prev_short_channel_id, prev_counterparty_node_id, prev_funding_outpoint, prev_channel_id, prev_user_channel_id, ref mut pending_forwards) in per_source_pending_forwards {
7658
7674
let mut new_intercept_events = VecDeque::new();
7659
7675
let mut failed_intercept_forwards = Vec::new();
7660
7676
if !pending_forwards.is_empty() {
@@ -7673,7 +7689,9 @@ where
7673
7689
match forward_htlcs.entry(scid) {
7674
7690
hash_map::Entry::Occupied(mut entry) => {
7675
7691
entry.get_mut().push(HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo {
7676
- prev_short_channel_id, prev_funding_outpoint, prev_channel_id, prev_htlc_id, prev_user_channel_id, forward_info }));
7692
+ prev_short_channel_id, prev_counterparty_node_id, prev_funding_outpoint,
7693
+ prev_channel_id, prev_htlc_id, prev_user_channel_id, forward_info
7694
+ }));
7677
7695
},
7678
7696
hash_map::Entry::Vacant(entry) => {
7679
7697
if !is_our_scid && forward_info.incoming_amt_msat.is_some() &&
@@ -7691,14 +7709,17 @@ where
7691
7709
intercept_id
7692
7710
}, None));
7693
7711
entry.insert(PendingAddHTLCInfo {
7694
- prev_short_channel_id, prev_funding_outpoint, prev_channel_id, prev_htlc_id, prev_user_channel_id, forward_info });
7712
+ prev_short_channel_id, prev_counterparty_node_id, prev_funding_outpoint,
7713
+ prev_channel_id, prev_htlc_id, prev_user_channel_id, forward_info
7714
+ });
7695
7715
},
7696
7716
hash_map::Entry::Occupied(_) => {
7697
7717
let logger = WithContext::from(&self.logger, None, Some(prev_channel_id), Some(forward_info.payment_hash));
7698
7718
log_info!(logger, "Failed to forward incoming HTLC: detected duplicate intercepted payment over short channel id {}", scid);
7699
7719
let htlc_source = HTLCSource::PreviousHopData(HTLCPreviousHopData {
7700
7720
short_channel_id: prev_short_channel_id,
7701
7721
user_channel_id: Some(prev_user_channel_id),
7722
+ counterparty_node_id: prev_counterparty_node_id,
7702
7723
outpoint: prev_funding_outpoint,
7703
7724
channel_id: prev_channel_id,
7704
7725
htlc_id: prev_htlc_id,
@@ -7718,7 +7739,9 @@ where
7718
7739
// payments are being processed.
7719
7740
push_forward_event |= forward_htlcs_empty && decode_update_add_htlcs_empty;
7720
7741
entry.insert(vec!(HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo {
7721
- prev_short_channel_id, prev_funding_outpoint, prev_channel_id, prev_htlc_id, prev_user_channel_id, forward_info })));
7742
+ prev_short_channel_id, prev_counterparty_node_id, prev_funding_outpoint,
7743
+ prev_channel_id, prev_htlc_id, prev_user_channel_id, forward_info
7744
+ })));
7722
7745
}
7723
7746
}
7724
7747
}
@@ -9507,6 +9530,7 @@ where
9507
9530
htlc_id: htlc.prev_htlc_id,
9508
9531
incoming_packet_shared_secret: htlc.forward_info.incoming_shared_secret,
9509
9532
phantom_shared_secret: None,
9533
+ counterparty_node_id: htlc.prev_counterparty_node_id,
9510
9534
outpoint: htlc.prev_funding_outpoint,
9511
9535
channel_id: htlc.prev_channel_id,
9512
9536
blinded_failure: htlc.forward_info.routing.blinded_failure(),
@@ -10616,6 +10640,7 @@ impl_writeable_tlv_based!(HTLCPreviousHopData, {
10616
10640
// Note that by the time we get past the required read for type 2 above, outpoint will be
10617
10641
// filled in, so we can safely unwrap it here.
10618
10642
(9, channel_id, (default_value, ChannelId::v1_from_funding_outpoint(outpoint.0.unwrap()))),
10643
+ (11, counterparty_node_id, option),
10619
10644
});
10620
10645
10621
10646
impl Writeable for ClaimableHTLC {
@@ -10772,6 +10797,7 @@ impl_writeable_tlv_based!(PendingAddHTLCInfo, {
10772
10797
// Note that by the time we get past the required read for type 6 above, prev_funding_outpoint will be
10773
10798
// filled in, so we can safely unwrap it here.
10774
10799
(7, prev_channel_id, (default_value, ChannelId::v1_from_funding_outpoint(prev_funding_outpoint.0.unwrap()))),
10800
+ (9, prev_counterparty_node_id, option),
10775
10801
});
10776
10802
10777
10803
impl Writeable for HTLCForwardInfo {
0 commit comments