@@ -452,7 +452,7 @@ pub(super) struct PendingAddHTLCInfo {
452
452
// HTLCs.
453
453
//
454
454
// Note that this may be an outbound SCID alias for the associated channel.
455
- prev_short_channel_id : u64,
455
+ prev_outbound_scid_alias : u64,
456
456
prev_htlc_id: u64,
457
457
prev_counterparty_node_id: PublicKey,
458
458
prev_channel_id: ChannelId,
@@ -467,7 +467,7 @@ impl PendingAddHTLCInfo {
467
467
_ => None,
468
468
};
469
469
HTLCPreviousHopData {
470
- short_channel_id : self.prev_short_channel_id ,
470
+ prev_outbound_scid_alias : self.prev_outbound_scid_alias ,
471
471
user_channel_id: Some(self.prev_user_channel_id),
472
472
outpoint: self.prev_funding_outpoint,
473
473
channel_id: self.prev_channel_id,
@@ -735,14 +735,14 @@ impl Default for OptionalOfferPaymentParams {
735
735
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
736
736
/// Uniquely describes an HTLC by its source. Just the guaranteed-unique subset of [`HTLCSource`].
737
737
pub(crate) enum SentHTLCId {
738
- PreviousHopData { short_channel_id : u64, htlc_id: u64 },
738
+ PreviousHopData { prev_outbound_scid_alias : u64, htlc_id: u64 },
739
739
OutboundRoute { session_priv: [u8; SECRET_KEY_SIZE] },
740
740
}
741
741
impl SentHTLCId {
742
742
pub(crate) fn from_source(source: &HTLCSource) -> Self {
743
743
match source {
744
744
HTLCSource::PreviousHopData(hop_data) => Self::PreviousHopData {
745
- short_channel_id : hop_data.short_channel_id ,
745
+ prev_outbound_scid_alias : hop_data.prev_outbound_scid_alias ,
746
746
htlc_id: hop_data.htlc_id,
747
747
},
748
748
HTLCSource::OutboundRoute { session_priv, .. } => {
@@ -753,15 +753,15 @@ impl SentHTLCId {
753
753
}
754
754
impl_writeable_tlv_based_enum!(SentHTLCId,
755
755
(0, PreviousHopData) => {
756
- (0, short_channel_id , required),
756
+ (0, prev_outbound_scid_alias , required),
757
757
(2, htlc_id, required),
758
758
},
759
759
(2, OutboundRoute) => {
760
760
(0, session_priv, required),
761
761
},
762
762
);
763
763
764
- // (src_channel_id , src_counterparty_node_id, src_funding_outpoint, src_chan_id, src_user_chan_id)
764
+ // (src_outbound_scid_alias , src_counterparty_node_id, src_funding_outpoint, src_chan_id, src_user_chan_id)
765
765
type PerSourcePendingForward =
766
766
(u64, PublicKey, OutPoint, ChannelId, u128, Vec<(PendingHTLCInfo, u64)>);
767
767
@@ -792,8 +792,7 @@ mod fuzzy_channelmanager {
792
792
/// Tracks the inbound corresponding to an outbound HTLC
793
793
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
794
794
pub struct HTLCPreviousHopData {
795
- // Note that this may be an outbound SCID alias for the associated channel.
796
- pub short_channel_id: u64,
795
+ pub prev_outbound_scid_alias: u64,
797
796
pub user_channel_id: Option<u128>,
798
797
pub htlc_id: u64,
799
798
pub incoming_packet_shared_secret: [u8; 32],
@@ -2718,11 +2717,8 @@ pub struct ChannelManager<
2718
2717
/// See `ChannelManager` struct-level documentation for lock order requirements.
2719
2718
pending_intercepted_htlcs: Mutex<HashMap<InterceptId, PendingAddHTLCInfo>>,
2720
2719
2721
- /// SCID/SCID Alias -> pending `update_add_htlc`s to decode.
2722
- ///
2723
- /// Note that because we may have an SCID Alias as the key we can have two entries per channel,
2724
- /// though in practice we probably won't be receiving HTLCs for a channel both via the alias
2725
- /// and via the classic SCID.
2720
+ /// Outbound SCID Alias -> pending `update_add_htlc`s to decode.
2721
+ /// We use the scid alias because regular scids may change if a splice occurs.
2726
2722
///
2727
2723
/// Note that no consistency guarantees are made about the existence of a channel with the
2728
2724
/// `short_channel_id` here, nor the `channel_id` in `UpdateAddHTLC`!
@@ -6441,7 +6437,7 @@ where
6441
6437
) -> Result<(), APIError> {
6442
6438
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
6443
6439
6444
- let next_hop_scid = {
6440
+ let outbound_scid_alias = {
6445
6441
let peer_state_lock = self.per_peer_state.read().unwrap();
6446
6442
let peer_state_mutex =
6447
6443
peer_state_lock.get(&next_node_id).ok_or_else(|| APIError::ChannelUnavailable {
@@ -6461,10 +6457,7 @@ where
6461
6457
),
6462
6458
});
6463
6459
}
6464
- funded_chan
6465
- .funding
6466
- .get_short_channel_id()
6467
- .unwrap_or(funded_chan.context.outbound_scid_alias())
6460
+ funded_chan.context.outbound_scid_alias()
6468
6461
} else {
6469
6462
return Err(APIError::ChannelUnavailable {
6470
6463
err: format!(
@@ -6512,7 +6505,7 @@ where
6512
6505
blinded,
6513
6506
incoming_cltv_expiry,
6514
6507
hold_htlc,
6515
- short_channel_id: next_hop_scid ,
6508
+ short_channel_id: outbound_scid_alias ,
6516
6509
}
6517
6510
},
6518
6511
_ => unreachable!(), // Only `PendingHTLCRouting::Forward`s are intercepted
@@ -6527,7 +6520,7 @@ where
6527
6520
};
6528
6521
6529
6522
let mut per_source_pending_forward = [(
6530
- payment.prev_short_channel_id ,
6523
+ payment.prev_outbound_scid_alias ,
6531
6524
payment.prev_counterparty_node_id,
6532
6525
payment.prev_funding_outpoint,
6533
6526
payment.prev_channel_id,
@@ -6588,11 +6581,12 @@ where
6588
6581
}
6589
6582
};
6590
6583
6591
- 'outer_loop: for (incoming_scid , update_add_htlcs) in decode_update_add_htlcs {
6584
+ 'outer_loop: for (incoming_scid_alias , update_add_htlcs) in decode_update_add_htlcs {
6592
6585
// If any decoded update_add_htlcs were processed, we need to persist.
6593
6586
should_persist = true;
6594
- let incoming_channel_details_opt =
6595
- self.do_funded_channel_callback(incoming_scid, |chan: &mut FundedChannel<SP>| {
6587
+ let incoming_channel_details_opt = self.do_funded_channel_callback(
6588
+ incoming_scid_alias,
6589
+ |chan: &mut FundedChannel<SP>| {
6596
6590
let counterparty_node_id = chan.context.get_counterparty_node_id();
6597
6591
let channel_id = chan.context.channel_id();
6598
6592
let funding_txo = chan.funding.get_funding_txo().unwrap();
@@ -6605,7 +6599,8 @@ where
6605
6599
user_channel_id,
6606
6600
accept_underpaying_htlcs,
6607
6601
)
6608
- });
6602
+ },
6603
+ );
6609
6604
let (
6610
6605
incoming_counterparty_node_id,
6611
6606
incoming_channel_id,
@@ -6674,7 +6669,7 @@ where
6674
6669
6675
6670
// Process the HTLC on the incoming channel.
6676
6671
match self.do_funded_channel_callback(
6677
- incoming_scid ,
6672
+ incoming_scid_alias ,
6678
6673
|chan: &mut FundedChannel<SP>| {
6679
6674
let logger = WithChannelContext::from(
6680
6675
&self.logger,
@@ -6747,7 +6742,7 @@ where
6747
6742
// Process all of the forwards and failures for the channel in which the HTLCs were
6748
6743
// proposed to as a batch.
6749
6744
let pending_forwards = (
6750
- incoming_scid ,
6745
+ incoming_scid_alias ,
6751
6746
incoming_counterparty_node_id,
6752
6747
incoming_funding_txo,
6753
6748
incoming_channel_id,
@@ -6769,7 +6764,12 @@ where
6769
6764
}
6770
6765
},
6771
6766
};
6772
- self.forward_htlcs.lock().unwrap().entry(incoming_scid).or_default().push(failure);
6767
+ self.forward_htlcs
6768
+ .lock()
6769
+ .unwrap()
6770
+ .entry(incoming_scid_alias)
6771
+ .or_default()
6772
+ .push(failure);
6773
6773
self.pending_events.lock().unwrap().push_back((
6774
6774
events::Event::HTLCHandlingFailed {
6775
6775
prev_channel_id: incoming_channel_id,
@@ -6906,7 +6906,7 @@ where
6906
6906
match forward_info {
6907
6907
HTLCForwardInfo::AddHTLC(payment) => {
6908
6908
let PendingAddHTLCInfo {
6909
- prev_short_channel_id ,
6909
+ prev_outbound_scid_alias ,
6910
6910
prev_htlc_id,
6911
6911
prev_channel_id,
6912
6912
prev_funding_outpoint,
@@ -7021,7 +7021,7 @@ where
7021
7021
);
7022
7022
match create_res {
7023
7023
Ok(info) => phantom_receives.push((
7024
- prev_short_channel_id ,
7024
+ prev_outbound_scid_alias ,
7025
7025
prev_counterparty_node_id,
7026
7026
prev_funding_outpoint,
7027
7027
prev_channel_id,
@@ -7118,7 +7118,7 @@ where
7118
7118
HTLCForwardInfo::AddHTLC(ref payment) => {
7119
7119
let htlc_source = HTLCSource::PreviousHopData(payment.htlc_previous_hop_data());
7120
7120
let PendingAddHTLCInfo {
7121
- prev_short_channel_id ,
7121
+ prev_outbound_scid_alias ,
7122
7122
forward_info:
7123
7123
PendingHTLCInfo {
7124
7124
payment_hash,
@@ -7212,7 +7212,7 @@ where
7212
7212
"alternate"
7213
7213
};
7214
7214
log_trace!(logger, "Forwarding HTLC from SCID {} with payment_hash {} and next hop SCID {} over {} channel {} with corresponding peer {}",
7215
- prev_short_channel_id , &payment_hash, short_chan_id, channel_description, optimal_channel.context.channel_id(), &counterparty_node_id);
7215
+ prev_outbound_scid_alias , &payment_hash, short_chan_id, channel_description, optimal_channel.context.channel_id(), &counterparty_node_id);
7216
7216
if let Err((reason, msg)) = optimal_channel.queue_add_htlc(
7217
7217
*outgoing_amt_msat,
7218
7218
*payment_hash,
@@ -7461,9 +7461,10 @@ where
7461
7461
let counterparty_node_id = $htlc.prev_hop.counterparty_node_id;
7462
7462
let incoming_packet_shared_secret =
7463
7463
$htlc.prev_hop.incoming_packet_shared_secret;
7464
+ let prev_outbound_scid_alias = $htlc.prev_hop.prev_outbound_scid_alias;
7464
7465
failed_forwards.push((
7465
7466
HTLCSource::PreviousHopData(HTLCPreviousHopData {
7466
- short_channel_id: $htlc.prev_hop.short_channel_id ,
7467
+ prev_outbound_scid_alias ,
7467
7468
user_channel_id: $htlc.prev_hop.user_channel_id,
7468
7469
counterparty_node_id,
7469
7470
channel_id: prev_channel_id,
@@ -8268,7 +8269,7 @@ where
8268
8269
}
8269
8270
},
8270
8271
HTLCSource::PreviousHopData(HTLCPreviousHopData {
8271
- ref short_channel_id ,
8272
+ ref prev_outbound_scid_alias ,
8272
8273
ref htlc_id,
8273
8274
ref incoming_packet_shared_secret,
8274
8275
ref phantom_shared_secret,
@@ -8311,7 +8312,7 @@ where
8311
8312
};
8312
8313
8313
8314
let mut forward_htlcs = self.forward_htlcs.lock().unwrap();
8314
- match forward_htlcs.entry(*short_channel_id ) {
8315
+ match forward_htlcs.entry(*prev_outbound_scid_alias ) {
8315
8316
hash_map::Entry::Occupied(mut entry) => {
8316
8317
entry.get_mut().push(failure);
8317
8318
},
@@ -8574,7 +8575,7 @@ where
8574
8575
) {
8575
8576
let counterparty_node_id = prev_hop.counterparty_node_id.or_else(|| {
8576
8577
let short_to_chan_info = self.short_to_chan_info.read().unwrap();
8577
- short_to_chan_info.get(&prev_hop.short_channel_id ).map(|(cp_id, _)| *cp_id)
8578
+ short_to_chan_info.get(&prev_hop.prev_outbound_scid_alias ).map(|(cp_id, _)| *cp_id)
8578
8579
});
8579
8580
let counterparty_node_id = if let Some(node_id) = counterparty_node_id {
8580
8581
node_id
@@ -9225,19 +9226,19 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
9225
9226
);
9226
9227
9227
9228
let counterparty_node_id = channel.context.get_counterparty_node_id();
9228
- let short_channel_id = channel.funding.get_short_channel_id().unwrap_or(channel. context.outbound_scid_alias() );
9229
+ let outbound_scid_alias = channel.context.outbound_scid_alias();
9229
9230
9230
9231
let mut htlc_forwards = None;
9231
9232
if !pending_forwards.is_empty() {
9232
9233
htlc_forwards = Some((
9233
- short_channel_id , channel.context.get_counterparty_node_id(),
9234
+ outbound_scid_alias , channel.context.get_counterparty_node_id(),
9234
9235
channel.funding.get_funding_txo().unwrap(), channel.context.channel_id(),
9235
9236
channel.context.get_user_id(), pending_forwards
9236
9237
));
9237
9238
}
9238
9239
let mut decode_update_add_htlcs = None;
9239
9240
if !pending_update_adds.is_empty() {
9240
- decode_update_add_htlcs = Some((short_channel_id , pending_update_adds));
9241
+ decode_update_add_htlcs = Some((outbound_scid_alias , pending_update_adds));
9241
9242
}
9242
9243
9243
9244
if channel.context.is_connected() {
@@ -10846,8 +10847,8 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
10846
10847
10847
10848
fn push_decode_update_add_htlcs(&self, mut update_add_htlcs: (u64, Vec<msgs::UpdateAddHTLC>)) {
10848
10849
let mut decode_update_add_htlcs = self.decode_update_add_htlcs.lock().unwrap();
10849
- let scid = update_add_htlcs.0;
10850
- match decode_update_add_htlcs.entry(scid ) {
10850
+ let src_outbound_scid_alias = update_add_htlcs.0;
10851
+ match decode_update_add_htlcs.entry(src_outbound_scid_alias ) {
10851
10852
hash_map::Entry::Occupied(mut e) => {
10852
10853
e.get_mut().append(&mut update_add_htlcs.1);
10853
10854
},
@@ -10860,7 +10861,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
10860
10861
#[inline]
10861
10862
fn forward_htlcs(&self, per_source_pending_forwards: &mut [PerSourcePendingForward]) {
10862
10863
for &mut (
10863
- prev_short_channel_id ,
10864
+ prev_outbound_scid_alias ,
10864
10865
prev_counterparty_node_id,
10865
10866
prev_funding_outpoint,
10866
10867
prev_channel_id,
@@ -10889,7 +10890,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
10889
10890
Some(payment_hash),
10890
10891
);
10891
10892
let pending_add = PendingAddHTLCInfo {
10892
- prev_short_channel_id ,
10893
+ prev_outbound_scid_alias ,
10893
10894
prev_counterparty_node_id,
10894
10895
prev_funding_outpoint,
10895
10896
prev_channel_id,
@@ -15064,7 +15065,7 @@ where
15064
15065
log_trace!(logger, "Releasing held htlc with intercept_id {}", intercept_id);
15065
15066
15066
15067
let mut per_source_pending_forward = [(
15067
- htlc.prev_short_channel_id ,
15068
+ htlc.prev_outbound_scid_alias ,
15068
15069
htlc.prev_counterparty_node_id,
15069
15070
htlc.prev_funding_outpoint,
15070
15071
htlc.prev_channel_id,
@@ -15406,7 +15407,7 @@ impl_writeable_tlv_based_enum!(BlindedFailure,
15406
15407
);
15407
15408
15408
15409
impl_writeable_tlv_based!(HTLCPreviousHopData, {
15409
- (0, short_channel_id , required),
15410
+ (0, prev_outbound_scid_alias , required),
15410
15411
(1, phantom_shared_secret, option),
15411
15412
(2, outpoint, required),
15412
15413
(3, blinded_failure, option),
@@ -15578,7 +15579,7 @@ impl Writeable for HTLCSource {
15578
15579
impl_writeable_tlv_based!(PendingAddHTLCInfo, {
15579
15580
(0, forward_info, required),
15580
15581
(1, prev_user_channel_id, (default_value, 0)),
15581
- (2, prev_short_channel_id , required),
15582
+ (2, prev_outbound_scid_alias , required),
15582
15583
(4, prev_htlc_id, required),
15583
15584
(6, prev_funding_outpoint, required),
15584
15585
// Note that by the time we get past the required read for type 6 above, prev_funding_outpoint will be
@@ -17001,9 +17002,9 @@ where
17001
17002
// still have an entry for this HTLC in `forward_htlcs` or
17002
17003
// `pending_intercepted_htlcs`, we were apparently not persisted after
17003
17004
// the monitor was when forwarding the payment.
17004
- decode_update_add_htlcs.retain(|scid , update_add_htlcs| {
17005
+ decode_update_add_htlcs.retain(|src_outb_alias , update_add_htlcs| {
17005
17006
update_add_htlcs.retain(|update_add_htlc| {
17006
- let matches = *scid == prev_hop_data.short_channel_id &&
17007
+ let matches = *src_outb_alias == prev_hop_data.prev_outbound_scid_alias &&
17007
17008
update_add_htlc.htlc_id == prev_hop_data.htlc_id;
17008
17009
if matches {
17009
17010
log_info!(logger, "Removing pending to-decode HTLC with hash {} as it was forwarded to the closed channel {}",
@@ -17198,7 +17199,7 @@ where
17198
17199
// to replay this claim to get the preimage into the inbound
17199
17200
// edge monitor but the channel is closed (and thus we'll
17200
17201
// immediately panic if we call claim_funds_from_hop).
17201
- if short_to_chan_info.get(&prev_hop.short_channel_id ).is_none() {
17202
+ if short_to_chan_info.get(&prev_hop.prev_outbound_scid_alias ).is_none() {
17202
17203
log_error!(args.logger,
17203
17204
"We need to replay the HTLC claim for payment_hash {} (preimage {}) but cannot do so as the HTLC was forwarded prior to LDK 0.0.124.\
17204
17205
All HTLCs that were forwarded by LDK 0.0.123 and prior must be resolved prior to upgrading to LDK 0.1",
@@ -17324,7 +17325,7 @@ where
17324
17325
if htlc.prev_hop.counterparty_node_id.is_some() {
17325
17326
continue;
17326
17327
}
17327
- if short_to_chan_info.get(&htlc.prev_hop.short_channel_id ).is_some() {
17328
+ if short_to_chan_info.get(&htlc.prev_hop.prev_outbound_scid_alias ).is_some() {
17328
17329
log_error!(args.logger,
17329
17330
"We do not have the required information to claim a pending payment with payment hash {} reliably.\
17330
17331
As long as the channel for the inbound edge of the forward remains open, this may work okay, but we may panic at runtime!\
0 commit comments