@@ -76,7 +76,7 @@ use crate::util::config::{
76
76
};
77
77
use crate::util::errors::APIError;
78
78
use crate::util::logger::{Logger, Record, WithContext};
79
- use crate::util::scid_utils::scid_from_parts;
79
+ use crate::util::scid_utils::{block_from_scid, scid_from_parts} ;
80
80
use crate::util::ser::{
81
81
Readable, ReadableArgs, RequiredWrapper, TransactionU16LenLimited, Writeable, Writer,
82
82
};
@@ -1407,6 +1407,11 @@ pub(crate) const UNFUNDED_CHANNEL_AGE_LIMIT_TICKS: usize = 60;
1407
1407
/// Number of blocks needed for an output from a coinbase transaction to be spendable.
1408
1408
pub(crate) const COINBASE_MATURITY: u32 = 100;
1409
1409
1410
+ /// The number of blocks to wait for a channel_announcement to propagate such that payments using an
1411
+ /// older SCID can still be relayed. Once the spend of the previous funding transaction has reached
1412
+ /// this number of confirmations, the corresponding SCID will be forgotten.
1413
+ const CHANNEL_ANNOUNCEMENT_PROPAGATION_DELAY: u32 = 12;
1414
+
1410
1415
struct PendingChannelMonitorUpdate {
1411
1416
update: ChannelMonitorUpdate,
1412
1417
}
@@ -2413,6 +2418,10 @@ where
2413
2418
// blinded paths instead of simple scid+node_id aliases.
2414
2419
outbound_scid_alias: u64,
2415
2420
2421
+ /// Short channel ids used by any prior FundingScope. These are maintained such that
2422
+ /// ChannelManager can look up the channel for any pending HTLCs.
2423
+ historical_scids: Vec<u64>,
2424
+
2416
2425
// We track whether we already emitted a `ChannelPending` event.
2417
2426
channel_pending_event_emitted: bool,
2418
2427
@@ -3259,6 +3268,7 @@ where
3259
3268
3260
3269
latest_inbound_scid_alias: None,
3261
3270
outbound_scid_alias: 0,
3271
+ historical_scids: Vec::new(),
3262
3272
3263
3273
channel_pending_event_emitted: false,
3264
3274
funding_tx_broadcast_safe_event_emitted: false,
@@ -3501,6 +3511,7 @@ where
3501
3511
3502
3512
latest_inbound_scid_alias: None,
3503
3513
outbound_scid_alias,
3514
+ historical_scids: Vec::new(),
3504
3515
3505
3516
channel_pending_event_emitted: false,
3506
3517
funding_tx_broadcast_safe_event_emitted: false,
@@ -5592,6 +5603,11 @@ where
5592
5603
5593
5604
Ok(())
5594
5605
}
5606
+
5607
+ /// Returns SCIDs that have been associated with the channel's funding transactions.
5608
+ pub fn historical_scids(&self) -> &[u64] {
5609
+ &self.historical_scids[..]
5610
+ }
5595
5611
}
5596
5612
5597
5613
// Internal utility functions for channels
@@ -5789,6 +5805,9 @@ where
5789
5805
#[cfg(splicing)]
5790
5806
macro_rules! promote_splice_funding {
5791
5807
($self: expr, $funding: expr) => {
5808
+ if let Some(scid) = $self.funding.short_channel_id {
5809
+ $self.context.historical_scids.push(scid);
5810
+ }
5792
5811
core::mem::swap(&mut $self.funding, $funding);
5793
5812
$self.pending_splice = None;
5794
5813
$self.pending_funding.clear();
@@ -10597,6 +10616,30 @@ where
10597
10616
pub fn has_pending_splice(&self) -> bool {
10598
10617
self.pending_splice.is_some()
10599
10618
}
10619
+
10620
+ pub fn remove_legacy_scids_before_block(&mut self, height: u32) -> alloc::vec::Drain<u64> {
10621
+ let end = self
10622
+ .funding
10623
+ .get_short_channel_id()
10624
+ .and_then(|current_scid| {
10625
+ let historical_scids = &self.context.historical_scids;
10626
+ historical_scids
10627
+ .iter()
10628
+ .zip(historical_scids.iter().skip(1).chain(core::iter::once(¤t_scid)))
10629
+ .map(|(_, next_scid)| {
10630
+ let funding_height = block_from_scid(*next_scid);
10631
+ let retain_scid =
10632
+ funding_height + CHANNEL_ANNOUNCEMENT_PROPAGATION_DELAY - 1 > height;
10633
+ retain_scid
10634
+ })
10635
+ .position(|retain_scid| retain_scid)
10636
+ })
10637
+ .unwrap_or(0);
10638
+
10639
+ // Drains the oldest historical SCIDs until reaching one without
10640
+ // CHANNEL_ANNOUNCEMENT_PROPAGATION_DELAY confirmations.
10641
+ self.context.historical_scids.drain(0..end)
10642
+ }
10600
10643
}
10601
10644
10602
10645
/// A not-yet-funded outbound (from holder) channel using V1 channel establishment.
@@ -12020,6 +12063,7 @@ where
12020
12063
(57, holding_cell_failure_attribution_data, optional_vec), // Added in 0.2
12021
12064
(58, self.interactive_tx_signing_session, option), // Added in 0.2
12022
12065
(59, self.funding.minimum_depth_override, option), // Added in 0.2
12066
+ (60, self.context.historical_scids, optional_vec), // Added in 0.2
12023
12067
});
12024
12068
12025
12069
Ok(())
@@ -12337,6 +12381,7 @@ where
12337
12381
let mut is_manual_broadcast = None;
12338
12382
12339
12383
let mut pending_funding = Some(Vec::new());
12384
+ let mut historical_scids = Some(Vec::new());
12340
12385
12341
12386
let mut interactive_tx_signing_session: Option<InteractiveTxSigningSession> = None;
12342
12387
@@ -12382,6 +12427,7 @@ where
12382
12427
(57, holding_cell_failure_attribution_data, optional_vec),
12383
12428
(58, interactive_tx_signing_session, option), // Added in 0.2
12384
12429
(59, minimum_depth_override, option), // Added in 0.2
12430
+ (60, historical_scids, optional_vec), // Added in 0.2
12385
12431
});
12386
12432
12387
12433
let holder_signer = signer_provider.derive_channel_signer(channel_keys_id);
@@ -12655,6 +12701,7 @@ where
12655
12701
latest_inbound_scid_alias,
12656
12702
// Later in the ChannelManager deserialization phase we scan for channels and assign scid aliases if its missing
12657
12703
outbound_scid_alias,
12704
+ historical_scids: historical_scids.unwrap(),
12658
12705
12659
12706
funding_tx_broadcast_safe_event_emitted: funding_tx_broadcast_safe_event_emitted.unwrap_or(false),
12660
12707
channel_pending_event_emitted: channel_pending_event_emitted.unwrap_or(true),
0 commit comments