@@ -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
};
@@ -1421,6 +1421,11 @@ pub(crate) const UNFUNDED_CHANNEL_AGE_LIMIT_TICKS: usize = 60;
1421
1421
/// Number of blocks needed for an output from a coinbase transaction to be spendable.
1422
1422
pub(crate) const COINBASE_MATURITY: u32 = 100;
1423
1423
1424
+ /// The number of blocks to wait for a channel_announcement to propagate such that payments using an
1425
+ /// older SCID can still be relayed. Once the spend of the previous funding transaction has reached
1426
+ /// this number of confirmations, the corresponding SCID will be forgotten.
1427
+ const CHANNEL_ANNOUNCEMENT_PROPAGATION_DELAY: u32 = 12;
1428
+
1424
1429
struct PendingChannelMonitorUpdate {
1425
1430
update: ChannelMonitorUpdate,
1426
1431
}
@@ -2425,6 +2430,10 @@ where
2425
2430
// blinded paths instead of simple scid+node_id aliases.
2426
2431
outbound_scid_alias: u64,
2427
2432
2433
+ /// Short channel ids used by any prior FundingScope. These are maintained such that
2434
+ /// ChannelManager can look up the channel for any pending HTLCs.
2435
+ historical_scids: Vec<u64>,
2436
+
2428
2437
// We track whether we already emitted a `ChannelPending` event.
2429
2438
channel_pending_event_emitted: bool,
2430
2439
@@ -3275,6 +3284,7 @@ where
3275
3284
3276
3285
latest_inbound_scid_alias: None,
3277
3286
outbound_scid_alias: 0,
3287
+ historical_scids: Vec::new(),
3278
3288
3279
3289
channel_pending_event_emitted: false,
3280
3290
funding_tx_broadcast_safe_event_emitted: false,
@@ -3517,6 +3527,7 @@ where
3517
3527
3518
3528
latest_inbound_scid_alias: None,
3519
3529
outbound_scid_alias,
3530
+ historical_scids: Vec::new(),
3520
3531
3521
3532
channel_pending_event_emitted: false,
3522
3533
funding_tx_broadcast_safe_event_emitted: false,
@@ -5604,6 +5615,11 @@ where
5604
5615
5605
5616
Ok(())
5606
5617
}
5618
+
5619
+ /// Returns SCIDs that have been associated with the channel's funding transactions.
5620
+ pub fn historical_scids(&self) -> &[u64] {
5621
+ &self.historical_scids[..]
5622
+ }
5607
5623
}
5608
5624
5609
5625
// Internal utility functions for channels
@@ -5805,6 +5821,9 @@ where
5805
5821
#[cfg(splicing)]
5806
5822
macro_rules! promote_splice_funding {
5807
5823
($self: expr, $funding: expr) => {
5824
+ if let Some(scid) = $self.funding.short_channel_id {
5825
+ $self.context.historical_scids.push(scid);
5826
+ }
5808
5827
core::mem::swap(&mut $self.funding, $funding);
5809
5828
$self.pending_splice = None;
5810
5829
$self.pending_funding.clear();
@@ -10643,6 +10662,30 @@ where
10643
10662
pub fn has_pending_splice(&self) -> bool {
10644
10663
self.pending_splice.is_some()
10645
10664
}
10665
+
10666
+ pub fn remove_legacy_scids_before_block(&mut self, height: u32) -> alloc::vec::Drain<u64> {
10667
+ let end = self
10668
+ .funding
10669
+ .get_short_channel_id()
10670
+ .and_then(|current_scid| {
10671
+ let historical_scids = &self.context.historical_scids;
10672
+ historical_scids
10673
+ .iter()
10674
+ .zip(historical_scids.iter().skip(1).chain(core::iter::once(¤t_scid)))
10675
+ .map(|(_, next_scid)| {
10676
+ let funding_height = block_from_scid(*next_scid);
10677
+ let retain_scid =
10678
+ funding_height + CHANNEL_ANNOUNCEMENT_PROPAGATION_DELAY - 1 > height;
10679
+ retain_scid
10680
+ })
10681
+ .position(|retain_scid| retain_scid)
10682
+ })
10683
+ .unwrap_or(0);
10684
+
10685
+ // Drains the oldest historical SCIDs until reaching one without
10686
+ // CHANNEL_ANNOUNCEMENT_PROPAGATION_DELAY confirmations.
10687
+ self.context.historical_scids.drain(0..end)
10688
+ }
10646
10689
}
10647
10690
10648
10691
/// A not-yet-funded outbound (from holder) channel using V1 channel establishment.
@@ -12073,6 +12116,7 @@ where
12073
12116
(57, holding_cell_failure_attribution_data, optional_vec), // Added in 0.2
12074
12117
(58, self.interactive_tx_signing_session, option), // Added in 0.2
12075
12118
(59, self.funding.minimum_depth_override, option), // Added in 0.2
12119
+ (60, self.context.historical_scids, optional_vec), // Added in 0.2
12076
12120
});
12077
12121
12078
12122
Ok(())
@@ -12390,6 +12434,7 @@ where
12390
12434
let mut is_manual_broadcast = None;
12391
12435
12392
12436
let mut pending_funding = Some(Vec::new());
12437
+ let mut historical_scids = Some(Vec::new());
12393
12438
12394
12439
let mut interactive_tx_signing_session: Option<InteractiveTxSigningSession> = None;
12395
12440
@@ -12435,6 +12480,7 @@ where
12435
12480
(57, holding_cell_failure_attribution_data, optional_vec),
12436
12481
(58, interactive_tx_signing_session, option), // Added in 0.2
12437
12482
(59, minimum_depth_override, option), // Added in 0.2
12483
+ (60, historical_scids, optional_vec), // Added in 0.2
12438
12484
});
12439
12485
12440
12486
let holder_signer = signer_provider.derive_channel_signer(channel_keys_id);
@@ -12708,6 +12754,7 @@ where
12708
12754
latest_inbound_scid_alias,
12709
12755
// Later in the ChannelManager deserialization phase we scan for channels and assign scid aliases if its missing
12710
12756
outbound_scid_alias,
12757
+ historical_scids: historical_scids.unwrap(),
12711
12758
12712
12759
funding_tx_broadcast_safe_event_emitted: funding_tx_broadcast_safe_event_emitted.unwrap_or(false),
12713
12760
channel_pending_event_emitted: channel_pending_event_emitted.unwrap_or(true),
0 commit comments