@@ -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 {
@@ -4663,6 +4665,7 @@ where
4663
4665
4664
4666
let mut per_source_pending_forward = [(
4665
4667
payment.prev_short_channel_id,
4668
+ payment.prev_counterparty_node_id,
4666
4669
payment.prev_funding_outpoint,
4667
4670
payment.prev_channel_id,
4668
4671
payment.prev_user_channel_id,
@@ -4693,6 +4696,7 @@ where
4693
4696
user_channel_id: Some(payment.prev_user_channel_id),
4694
4697
outpoint: payment.prev_funding_outpoint,
4695
4698
channel_id: payment.prev_channel_id,
4699
+ counterparty_node_id: payment.prev_counterparty_node_id,
4696
4700
htlc_id: payment.prev_htlc_id,
4697
4701
incoming_packet_shared_secret: payment.forward_info.incoming_shared_secret,
4698
4702
phantom_shared_secret: None,
@@ -4822,8 +4826,10 @@ where
4822
4826
4823
4827
// Process all of the forwards and failures for the channel in which the HTLCs were
4824
4828
// proposed to as a batch.
4825
- let pending_forwards = (incoming_scid, incoming_funding_txo, incoming_channel_id,
4826
- incoming_user_channel_id, htlc_forwards.drain(..).collect());
4829
+ let pending_forwards = (
4830
+ incoming_scid, Some(incoming_counterparty_node_id), incoming_funding_txo,
4831
+ incoming_channel_id, incoming_user_channel_id, htlc_forwards.drain(..).collect()
4832
+ );
4827
4833
self.forward_htlcs_without_forward_event(&mut [pending_forwards]);
4828
4834
for (htlc_fail, htlc_destination) in htlc_fails.drain(..) {
4829
4835
let failure = match htlc_fail {
@@ -4857,7 +4863,7 @@ where
4857
4863
4858
4864
let mut new_events = VecDeque::new();
4859
4865
let mut failed_forwards = Vec::new();
4860
- let mut phantom_receives: Vec<(u64, OutPoint, ChannelId, u128, Vec<(PendingHTLCInfo, u64)>)> = Vec::new();
4866
+ let mut phantom_receives: Vec<(u64, Option<PublicKey>, OutPoint, ChannelId, u128, Vec<(PendingHTLCInfo, u64)>)> = Vec::new();
4861
4867
{
4862
4868
let mut forward_htlcs = new_hash_map();
4863
4869
mem::swap(&mut forward_htlcs, &mut self.forward_htlcs.lock().unwrap());
@@ -4871,7 +4877,7 @@ where
4871
4877
match forward_info {
4872
4878
HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo {
4873
4879
prev_short_channel_id, prev_htlc_id, prev_channel_id, prev_funding_outpoint,
4874
- prev_user_channel_id, forward_info: PendingHTLCInfo {
4880
+ prev_user_channel_id, prev_counterparty_node_id, forward_info: PendingHTLCInfo {
4875
4881
routing, incoming_shared_secret, payment_hash, outgoing_amt_msat,
4876
4882
outgoing_cltv_value, ..
4877
4883
}
@@ -4886,6 +4892,7 @@ where
4886
4892
user_channel_id: Some(prev_user_channel_id),
4887
4893
channel_id: prev_channel_id,
4888
4894
outpoint: prev_funding_outpoint,
4895
+ counterparty_node_id: prev_counterparty_node_id,
4889
4896
htlc_id: prev_htlc_id,
4890
4897
incoming_packet_shared_secret: incoming_shared_secret,
4891
4898
phantom_shared_secret: $phantom_ss,
@@ -4948,7 +4955,10 @@ where
4948
4955
outgoing_cltv_value, Some(phantom_shared_secret), false, None,
4949
4956
current_height, self.default_configuration.accept_mpp_keysend)
4950
4957
{
4951
- Ok(info) => phantom_receives.push((prev_short_channel_id, prev_funding_outpoint, prev_channel_id, prev_user_channel_id, vec![(info, prev_htlc_id)])),
4958
+ Ok(info) => phantom_receives.push((
4959
+ prev_short_channel_id, prev_counterparty_node_id, prev_funding_outpoint,
4960
+ prev_channel_id, prev_user_channel_id, vec![(info, prev_htlc_id)]
4961
+ )),
4952
4962
Err(InboundHTLCErr { err_code, err_data, msg }) => failed_payment!(msg, err_code, err_data, Some(phantom_shared_secret))
4953
4963
}
4954
4964
},
@@ -4994,7 +5004,7 @@ where
4994
5004
let queue_fail_htlc_res = match forward_info {
4995
5005
HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo {
4996
5006
prev_short_channel_id, prev_htlc_id, prev_channel_id, prev_funding_outpoint,
4997
- prev_user_channel_id, forward_info: PendingHTLCInfo {
5007
+ prev_user_channel_id, prev_counterparty_node_id, forward_info: PendingHTLCInfo {
4998
5008
incoming_shared_secret, payment_hash, outgoing_amt_msat, outgoing_cltv_value,
4999
5009
routing: PendingHTLCRouting::Forward {
5000
5010
onion_packet, blinded, ..
@@ -5006,6 +5016,7 @@ where
5006
5016
let htlc_source = HTLCSource::PreviousHopData(HTLCPreviousHopData {
5007
5017
short_channel_id: prev_short_channel_id,
5008
5018
user_channel_id: Some(prev_user_channel_id),
5019
+ counterparty_node_id: prev_counterparty_node_id,
5009
5020
channel_id: prev_channel_id,
5010
5021
outpoint: prev_funding_outpoint,
5011
5022
htlc_id: prev_htlc_id,
@@ -5079,7 +5090,7 @@ where
5079
5090
match forward_info {
5080
5091
HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo {
5081
5092
prev_short_channel_id, prev_htlc_id, prev_channel_id, prev_funding_outpoint,
5082
- prev_user_channel_id, forward_info: PendingHTLCInfo {
5093
+ prev_user_channel_id, prev_counterparty_node_id, forward_info: PendingHTLCInfo {
5083
5094
routing, incoming_shared_secret, payment_hash, incoming_amt_msat, outgoing_amt_msat,
5084
5095
skimmed_fee_msat, ..
5085
5096
}
@@ -5117,6 +5128,7 @@ where
5117
5128
prev_hop: HTLCPreviousHopData {
5118
5129
short_channel_id: prev_short_channel_id,
5119
5130
user_channel_id: Some(prev_user_channel_id),
5131
+ counterparty_node_id: prev_counterparty_node_id,
5120
5132
channel_id: prev_channel_id,
5121
5133
outpoint: prev_funding_outpoint,
5122
5134
htlc_id: prev_htlc_id,
@@ -5149,6 +5161,7 @@ where
5149
5161
failed_forwards.push((HTLCSource::PreviousHopData(HTLCPreviousHopData {
5150
5162
short_channel_id: $htlc.prev_hop.short_channel_id,
5151
5163
user_channel_id: $htlc.prev_hop.user_channel_id,
5164
+ counterparty_node_id: $htlc.prev_hop.counterparty_node_id,
5152
5165
channel_id: prev_channel_id,
5153
5166
outpoint: prev_funding_outpoint,
5154
5167
htlc_id: $htlc.prev_hop.htlc_id,
@@ -6517,7 +6530,7 @@ where
6517
6530
pending_forwards: Vec<(PendingHTLCInfo, u64)>, pending_update_adds: Vec<msgs::UpdateAddHTLC>,
6518
6531
funding_broadcastable: Option<Transaction>,
6519
6532
channel_ready: Option<msgs::ChannelReady>, announcement_sigs: Option<msgs::AnnouncementSignatures>)
6520
- -> (Option<(u64, OutPoint, ChannelId, u128, Vec<(PendingHTLCInfo, u64)>)>, Option<(u64, Vec<msgs::UpdateAddHTLC>)>) {
6533
+ -> (Option<(u64, Option<PublicKey>, OutPoint, ChannelId, u128, Vec<(PendingHTLCInfo, u64)>)>, Option<(u64, Vec<msgs::UpdateAddHTLC>)>) {
6521
6534
let logger = WithChannelContext::from(&self.logger, &channel.context, None);
6522
6535
log_trace!(logger, "Handling channel resumption for channel {} with {} RAA, {} commitment update, {} pending forwards, {} pending update_add_htlcs, {}broadcasting funding, {} channel ready, {} announcement",
6523
6536
&channel.context.channel_id(),
@@ -6533,8 +6546,11 @@ where
6533
6546
6534
6547
let mut htlc_forwards = None;
6535
6548
if !pending_forwards.is_empty() {
6536
- htlc_forwards = Some((short_channel_id, channel.context.get_funding_txo().unwrap(),
6537
- channel.context.channel_id(), channel.context.get_user_id(), pending_forwards));
6549
+ htlc_forwards = Some((
6550
+ short_channel_id, Some(channel.context.get_counterparty_node_id()),
6551
+ channel.context.get_funding_txo().unwrap(), channel.context.channel_id(),
6552
+ channel.context.get_user_id(), pending_forwards
6553
+ ));
6538
6554
}
6539
6555
let mut decode_update_add_htlcs = None;
6540
6556
if !pending_update_adds.is_empty() {
@@ -7577,15 +7593,15 @@ where
7577
7593
}
7578
7594
7579
7595
#[inline]
7580
- fn forward_htlcs(&self, per_source_pending_forwards: &mut [(u64, OutPoint, ChannelId, u128, Vec<(PendingHTLCInfo, u64)>)]) {
7596
+ fn forward_htlcs(&self, per_source_pending_forwards: &mut [(u64, Option<PublicKey>, OutPoint, ChannelId, u128, Vec<(PendingHTLCInfo, u64)>)]) {
7581
7597
let push_forward_event = self.forward_htlcs_without_forward_event(per_source_pending_forwards);
7582
7598
if push_forward_event { self.push_pending_forwards_ev() }
7583
7599
}
7584
7600
7585
7601
#[inline]
7586
- fn forward_htlcs_without_forward_event(&self, per_source_pending_forwards: &mut [(u64, OutPoint, ChannelId, u128, Vec<(PendingHTLCInfo, u64)>)]) -> bool {
7602
+ fn forward_htlcs_without_forward_event(&self, per_source_pending_forwards: &mut [(u64, Option<PublicKey>, OutPoint, ChannelId, u128, Vec<(PendingHTLCInfo, u64)>)]) -> bool {
7587
7603
let mut push_forward_event = false;
7588
- 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 {
7604
+ 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 {
7589
7605
let mut new_intercept_events = VecDeque::new();
7590
7606
let mut failed_intercept_forwards = Vec::new();
7591
7607
if !pending_forwards.is_empty() {
@@ -7604,7 +7620,9 @@ where
7604
7620
match forward_htlcs.entry(scid) {
7605
7621
hash_map::Entry::Occupied(mut entry) => {
7606
7622
entry.get_mut().push(HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo {
7607
- prev_short_channel_id, prev_funding_outpoint, prev_channel_id, prev_htlc_id, prev_user_channel_id, forward_info }));
7623
+ prev_short_channel_id, prev_counterparty_node_id, prev_funding_outpoint,
7624
+ prev_channel_id, prev_htlc_id, prev_user_channel_id, forward_info
7625
+ }));
7608
7626
},
7609
7627
hash_map::Entry::Vacant(entry) => {
7610
7628
if !is_our_scid && forward_info.incoming_amt_msat.is_some() &&
@@ -7622,14 +7640,17 @@ where
7622
7640
intercept_id
7623
7641
}, None));
7624
7642
entry.insert(PendingAddHTLCInfo {
7625
- prev_short_channel_id, prev_funding_outpoint, prev_channel_id, prev_htlc_id, prev_user_channel_id, forward_info });
7643
+ prev_short_channel_id, prev_counterparty_node_id, prev_funding_outpoint,
7644
+ prev_channel_id, prev_htlc_id, prev_user_channel_id, forward_info
7645
+ });
7626
7646
},
7627
7647
hash_map::Entry::Occupied(_) => {
7628
7648
let logger = WithContext::from(&self.logger, None, Some(prev_channel_id), Some(forward_info.payment_hash));
7629
7649
log_info!(logger, "Failed to forward incoming HTLC: detected duplicate intercepted payment over short channel id {}", scid);
7630
7650
let htlc_source = HTLCSource::PreviousHopData(HTLCPreviousHopData {
7631
7651
short_channel_id: prev_short_channel_id,
7632
7652
user_channel_id: Some(prev_user_channel_id),
7653
+ counterparty_node_id: prev_counterparty_node_id,
7633
7654
outpoint: prev_funding_outpoint,
7634
7655
channel_id: prev_channel_id,
7635
7656
htlc_id: prev_htlc_id,
@@ -7649,7 +7670,9 @@ where
7649
7670
// payments are being processed.
7650
7671
push_forward_event |= forward_htlcs_empty && decode_update_add_htlcs_empty;
7651
7672
entry.insert(vec!(HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo {
7652
- prev_short_channel_id, prev_funding_outpoint, prev_channel_id, prev_htlc_id, prev_user_channel_id, forward_info })));
7673
+ prev_short_channel_id, prev_counterparty_node_id, prev_funding_outpoint,
7674
+ prev_channel_id, prev_htlc_id, prev_user_channel_id, forward_info
7675
+ })));
7653
7676
}
7654
7677
}
7655
7678
}
@@ -9438,6 +9461,7 @@ where
9438
9461
htlc_id: htlc.prev_htlc_id,
9439
9462
incoming_packet_shared_secret: htlc.forward_info.incoming_shared_secret,
9440
9463
phantom_shared_secret: None,
9464
+ counterparty_node_id: htlc.prev_counterparty_node_id,
9441
9465
outpoint: htlc.prev_funding_outpoint,
9442
9466
channel_id: htlc.prev_channel_id,
9443
9467
blinded_failure: htlc.forward_info.routing.blinded_failure(),
@@ -10533,6 +10557,7 @@ impl_writeable_tlv_based!(HTLCPreviousHopData, {
10533
10557
// Note that by the time we get past the required read for type 2 above, outpoint will be
10534
10558
// filled in, so we can safely unwrap it here.
10535
10559
(9, channel_id, (default_value, ChannelId::v1_from_funding_outpoint(outpoint.0.unwrap()))),
10560
+ (11, counterparty_node_id, option),
10536
10561
});
10537
10562
10538
10563
impl Writeable for ClaimableHTLC {
@@ -10689,6 +10714,7 @@ impl_writeable_tlv_based!(PendingAddHTLCInfo, {
10689
10714
// Note that by the time we get past the required read for type 6 above, prev_funding_outpoint will be
10690
10715
// filled in, so we can safely unwrap it here.
10691
10716
(7, prev_channel_id, (default_value, ChannelId::v1_from_funding_outpoint(prev_funding_outpoint.0.unwrap()))),
10717
+ (9, prev_counterparty_node_id, option),
10692
10718
});
10693
10719
10694
10720
impl Writeable for HTLCForwardInfo {
0 commit comments