@@ -449,6 +449,27 @@ pub(super) struct PendingAddHTLCInfo {
449
449
prev_user_channel_id: u128,
450
450
}
451
451
452
+ impl PendingAddHTLCInfo {
453
+ fn htlc_previous_hop_data(&self) -> HTLCPreviousHopData {
454
+ let phantom_shared_secret = match self.forward_info.routing {
455
+ PendingHTLCRouting::Receive { phantom_shared_secret, .. } => phantom_shared_secret,
456
+ _ => None,
457
+ };
458
+ HTLCPreviousHopData {
459
+ short_channel_id: self.prev_short_channel_id,
460
+ user_channel_id: Some(self.prev_user_channel_id),
461
+ outpoint: self.prev_funding_outpoint,
462
+ channel_id: self.prev_channel_id,
463
+ counterparty_node_id: Some(self.prev_counterparty_node_id),
464
+ htlc_id: self.prev_htlc_id,
465
+ incoming_packet_shared_secret: self.forward_info.incoming_shared_secret,
466
+ phantom_shared_secret,
467
+ blinded_failure: self.forward_info.routing.blinded_failure(),
468
+ cltv_expiry: self.forward_info.routing.incoming_cltv_expiry(),
469
+ }
470
+ }
471
+ }
472
+
452
473
#[cfg_attr(test, derive(Clone, Debug, PartialEq))]
453
474
pub(super) enum HTLCForwardInfo {
454
475
AddHTLC(PendingAddHTLCInfo),
@@ -6294,20 +6315,8 @@ where
6294
6315
err: format!("Payment with intercept id {} not found", log_bytes!(intercept_id.0))
6295
6316
})?;
6296
6317
6297
- if let PendingHTLCRouting::Forward { short_channel_id, incoming_cltv_expiry, .. } = payment.forward_info.routing {
6298
- let htlc_source = HTLCSource::PreviousHopData(HTLCPreviousHopData {
6299
- short_channel_id: payment.prev_short_channel_id,
6300
- user_channel_id: Some(payment.prev_user_channel_id),
6301
- outpoint: payment.prev_funding_outpoint,
6302
- channel_id: payment.prev_channel_id,
6303
- counterparty_node_id: Some(payment.prev_counterparty_node_id),
6304
- htlc_id: payment.prev_htlc_id,
6305
- incoming_packet_shared_secret: payment.forward_info.incoming_shared_secret,
6306
- phantom_shared_secret: None,
6307
- blinded_failure: payment.forward_info.routing.blinded_failure(),
6308
- cltv_expiry: incoming_cltv_expiry,
6309
- });
6310
-
6318
+ if let PendingHTLCRouting::Forward { short_channel_id, .. } = payment.forward_info.routing {
6319
+ let htlc_source = HTLCSource::PreviousHopData(payment.htlc_previous_hop_data());
6311
6320
let reason = HTLCFailReason::from_failure_code(LocalHTLCFailureReason::UnknownNextPeer);
6312
6321
let destination = HTLCHandlingFailureType::InvalidForward { requested_forward_scid: short_channel_id };
6313
6322
self.fail_htlc_backwards_internal(&htlc_source, &payment.forward_info.payment_hash, &reason, destination);
@@ -6629,24 +6638,24 @@ where
6629
6638
) {
6630
6639
for forward_info in forward_infos {
6631
6640
match forward_info {
6632
- HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo {
6633
- prev_short_channel_id,
6634
- prev_htlc_id ,
6635
- prev_channel_id ,
6636
- prev_funding_outpoint ,
6637
- prev_user_channel_id ,
6638
- prev_counterparty_node_id ,
6639
- forward_info:
6640
- PendingHTLCInfo {
6641
- routing,
6642
- incoming_shared_secret ,
6643
- payment_hash ,
6644
- outgoing_amt_msat ,
6645
- outgoing_cltv_value ,
6646
- ..
6647
- },
6648
- }) => {
6649
- let cltv_expiry = routing.incoming_cltv_expiry() ;
6641
+ HTLCForwardInfo::AddHTLC(payment) => {
6642
+ let PendingAddHTLCInfo {
6643
+ prev_short_channel_id ,
6644
+ prev_htlc_id ,
6645
+ prev_channel_id ,
6646
+ prev_funding_outpoint ,
6647
+ prev_user_channel_id ,
6648
+ prev_counterparty_node_id,
6649
+ forward_info:
6650
+ PendingHTLCInfo {
6651
+ ref routing ,
6652
+ incoming_shared_secret ,
6653
+ payment_hash ,
6654
+ outgoing_amt_msat ,
6655
+ outgoing_cltv_value,
6656
+ ..
6657
+ },
6658
+ } = payment ;
6650
6659
let logger = WithContext::from(
6651
6660
&self.logger,
6652
6661
forwarding_counterparty,
@@ -6657,19 +6666,8 @@ where
6657
6666
|msg, reason, err_data, phantom_ss, next_hop_unknown| {
6658
6667
log_info!(logger, "Failed to accept/forward incoming HTLC: {}", msg);
6659
6668
6660
- let htlc_source = HTLCSource::PreviousHopData(HTLCPreviousHopData {
6661
- short_channel_id: prev_short_channel_id,
6662
- user_channel_id: Some(prev_user_channel_id),
6663
- channel_id: prev_channel_id,
6664
- outpoint: prev_funding_outpoint,
6665
- counterparty_node_id: Some(prev_counterparty_node_id),
6666
- htlc_id: prev_htlc_id,
6667
- incoming_packet_shared_secret: incoming_shared_secret,
6668
- phantom_shared_secret: phantom_ss,
6669
- blinded_failure: routing.blinded_failure(),
6670
- cltv_expiry,
6671
- });
6672
-
6669
+ let mut prev_hop = payment.htlc_previous_hop_data();
6670
+ prev_hop.phantom_shared_secret = phantom_ss;
6673
6671
let failure_type = if next_hop_unknown {
6674
6672
HTLCHandlingFailureType::InvalidForward {
6675
6673
requested_forward_scid: short_chan_id,
@@ -6679,7 +6677,7 @@ where
6679
6677
};
6680
6678
6681
6679
failed_forwards.push((
6682
- htlc_source ,
6680
+ HTLCSource::PreviousHopData(prev_hop) ,
6683
6681
payment_hash,
6684
6682
HTLCFailReason::reason(reason, err_data),
6685
6683
failure_type,
@@ -6848,43 +6846,29 @@ where
6848
6846
let mut draining_pending_forwards = pending_forwards.drain(..);
6849
6847
while let Some(forward_info) = draining_pending_forwards.next() {
6850
6848
let queue_fail_htlc_res = match forward_info {
6851
- HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo {
6852
- prev_short_channel_id,
6853
- prev_htlc_id,
6854
- prev_channel_id,
6855
- prev_funding_outpoint,
6856
- prev_user_channel_id,
6857
- prev_counterparty_node_id,
6858
- forward_info:
6859
- PendingHTLCInfo {
6860
- incoming_shared_secret,
6861
- payment_hash,
6862
- outgoing_amt_msat,
6863
- outgoing_cltv_value,
6864
- routing:
6865
- PendingHTLCRouting::Forward {
6866
- ref onion_packet,
6867
- blinded,
6868
- incoming_cltv_expiry,
6869
- ..
6870
- },
6871
- skimmed_fee_msat,
6872
- ..
6849
+ HTLCForwardInfo::AddHTLC(ref payment) => {
6850
+ let htlc_source = HTLCSource::PreviousHopData(payment.htlc_previous_hop_data());
6851
+ let PendingAddHTLCInfo {
6852
+ prev_short_channel_id,
6853
+ forward_info:
6854
+ PendingHTLCInfo {
6855
+ payment_hash,
6856
+ outgoing_amt_msat,
6857
+ outgoing_cltv_value,
6858
+ routing,
6859
+ skimmed_fee_msat,
6860
+ ..
6861
+ },
6862
+ ..
6863
+ } = payment;
6864
+ let (onion_packet, blinded) = match routing {
6865
+ PendingHTLCRouting::Forward { ref onion_packet, blinded, .. } => {
6866
+ (onion_packet, blinded)
6873
6867
},
6874
- }) => {
6875
- let htlc_source = HTLCSource::PreviousHopData(HTLCPreviousHopData {
6876
- short_channel_id: prev_short_channel_id,
6877
- user_channel_id: Some(prev_user_channel_id),
6878
- counterparty_node_id: Some(prev_counterparty_node_id),
6879
- channel_id: prev_channel_id,
6880
- outpoint: prev_funding_outpoint,
6881
- htlc_id: prev_htlc_id,
6882
- incoming_packet_shared_secret: incoming_shared_secret,
6883
- // Phantom payments are only PendingHTLCRouting::Receive.
6884
- phantom_shared_secret: None,
6885
- blinded_failure: blinded.map(|b| b.failure),
6886
- cltv_expiry: incoming_cltv_expiry,
6887
- });
6868
+ _ => {
6869
+ panic!("short_channel_id != 0 should imply any pending_forward entries are of type Forward");
6870
+ },
6871
+ };
6888
6872
let next_blinding_point = blinded.and_then(|b| {
6889
6873
b.next_blinding_override.or_else(|| {
6890
6874
let encrypted_tlvs_ss = self
@@ -6950,7 +6934,7 @@ where
6950
6934
let logger = WithChannelContext::from(
6951
6935
&self.logger,
6952
6936
&optimal_channel.context,
6953
- Some(payment_hash),
6937
+ Some(* payment_hash),
6954
6938
);
6955
6939
let channel_description =
6956
6940
if optimal_channel.funding.get_short_channel_id() == Some(short_chan_id) {
@@ -6961,12 +6945,12 @@ where
6961
6945
log_trace!(logger, "Forwarding HTLC from SCID {} with payment_hash {} and next hop SCID {} over {} channel {} with corresponding peer {}",
6962
6946
prev_short_channel_id, &payment_hash, short_chan_id, channel_description, optimal_channel.context.channel_id(), &counterparty_node_id);
6963
6947
if let Err((reason, msg)) = optimal_channel.queue_add_htlc(
6964
- outgoing_amt_msat,
6965
- payment_hash,
6966
- outgoing_cltv_value,
6948
+ * outgoing_amt_msat,
6949
+ * payment_hash,
6950
+ * outgoing_cltv_value,
6967
6951
htlc_source.clone(),
6968
6952
onion_packet.clone(),
6969
- skimmed_fee_msat,
6953
+ * skimmed_fee_msat,
6970
6954
next_blinding_point,
6971
6955
&self.fee_estimator,
6972
6956
&&logger,
@@ -6991,7 +6975,7 @@ where
6991
6975
};
6992
6976
failed_forwards.push((
6993
6977
htlc_source,
6994
- payment_hash,
6978
+ * payment_hash,
6995
6979
HTLCFailReason::reason(reason, data),
6996
6980
failure_type,
6997
6981
));
@@ -7008,9 +6992,6 @@ where
7008
6992
}
7009
6993
None
7010
6994
},
7011
- HTLCForwardInfo::AddHTLC { .. } => {
7012
- panic!("short_channel_id != 0 should imply any pending_forward entries are of type Forward");
7013
- },
7014
6995
HTLCForwardInfo::FailHTLC { htlc_id, ref err_packet } => {
7015
6996
if let Some(chan) = peer_state
7016
6997
.channel_by_id
@@ -7094,24 +7075,22 @@ where
7094
7075
) {
7095
7076
'next_forwardable_htlc: for forward_info in pending_forwards.drain(..) {
7096
7077
match forward_info {
7097
- HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo {
7098
- prev_short_channel_id,
7099
- prev_htlc_id,
7100
- prev_channel_id,
7101
- prev_funding_outpoint,
7102
- prev_user_channel_id,
7103
- prev_counterparty_node_id,
7104
- forward_info:
7105
- PendingHTLCInfo {
7106
- routing,
7107
- incoming_shared_secret,
7108
- payment_hash,
7109
- incoming_amt_msat,
7110
- outgoing_amt_msat,
7111
- skimmed_fee_msat,
7112
- ..
7113
- },
7114
- }) => {
7078
+ HTLCForwardInfo::AddHTLC(payment) => {
7079
+ let prev_hop = payment.htlc_previous_hop_data();
7080
+ let PendingAddHTLCInfo {
7081
+ prev_channel_id,
7082
+ prev_funding_outpoint,
7083
+ forward_info:
7084
+ PendingHTLCInfo {
7085
+ routing,
7086
+ payment_hash,
7087
+ incoming_amt_msat,
7088
+ outgoing_amt_msat,
7089
+ skimmed_fee_msat,
7090
+ ..
7091
+ },
7092
+ ..
7093
+ } = payment;
7115
7094
let blinded_failure = routing.blinded_failure();
7116
7095
let (
7117
7096
cltv_expiry,
@@ -7183,18 +7162,7 @@ where
7183
7162
},
7184
7163
};
7185
7164
let claimable_htlc = ClaimableHTLC {
7186
- prev_hop: HTLCPreviousHopData {
7187
- short_channel_id: prev_short_channel_id,
7188
- user_channel_id: Some(prev_user_channel_id),
7189
- counterparty_node_id: Some(prev_counterparty_node_id),
7190
- channel_id: prev_channel_id,
7191
- outpoint: prev_funding_outpoint,
7192
- htlc_id: prev_htlc_id,
7193
- incoming_packet_shared_secret: incoming_shared_secret,
7194
- phantom_shared_secret,
7195
- blinded_failure,
7196
- cltv_expiry: Some(cltv_expiry),
7197
- },
7165
+ prev_hop,
7198
7166
// We differentiate the received value from the sender intended value
7199
7167
// if possible so that we don't prematurely mark MPP payments complete
7200
7168
// if routing nodes overpay
@@ -13701,19 +13669,7 @@ where
13701
13669
let mut intercepted_htlcs = self.pending_intercepted_htlcs.lock().unwrap();
13702
13670
intercepted_htlcs.retain(|_, htlc| {
13703
13671
if height >= htlc.forward_info.outgoing_cltv_value - HTLC_FAIL_BACK_BUFFER {
13704
- let prev_hop_data = HTLCSource::PreviousHopData(HTLCPreviousHopData {
13705
- short_channel_id: htlc.prev_short_channel_id,
13706
- user_channel_id: Some(htlc.prev_user_channel_id),
13707
- htlc_id: htlc.prev_htlc_id,
13708
- incoming_packet_shared_secret: htlc.forward_info.incoming_shared_secret,
13709
- phantom_shared_secret: None,
13710
- counterparty_node_id: Some(htlc.prev_counterparty_node_id),
13711
- outpoint: htlc.prev_funding_outpoint,
13712
- channel_id: htlc.prev_channel_id,
13713
- blinded_failure: htlc.forward_info.routing.blinded_failure(),
13714
- cltv_expiry: htlc.forward_info.routing.incoming_cltv_expiry(),
13715
- });
13716
-
13672
+ let prev_hop_data = HTLCSource::PreviousHopData(htlc.htlc_previous_hop_data());
13717
13673
let requested_forward_scid /* intercept scid */ = match htlc.forward_info.routing {
13718
13674
PendingHTLCRouting::Forward { short_channel_id, .. } => short_channel_id,
13719
13675
_ => unreachable!(),
0 commit comments