@@ -66,7 +66,7 @@ use crate::util::ser::{Readable, ReadableArgs, RequiredWrapper, TransactionU16Le
66
66
use crate::util::logger::{Logger, Record, WithContext};
67
67
use crate::util::errors::APIError;
68
68
use crate::util::config::{UserConfig, ChannelConfig, LegacyChannelConfig, ChannelHandshakeConfig, ChannelHandshakeLimits, MaxDustHTLCExposure};
69
- use crate::util::scid_utils::scid_from_parts;
69
+ use crate::util::scid_utils::{block_from_scid, scid_from_parts} ;
70
70
71
71
use alloc::collections::{btree_map, BTreeMap};
72
72
@@ -1303,6 +1303,11 @@ pub(crate) const UNFUNDED_CHANNEL_AGE_LIMIT_TICKS: usize = 60;
1303
1303
/// Number of blocks needed for an output from a coinbase transaction to be spendable.
1304
1304
pub(crate) const COINBASE_MATURITY: u32 = 100;
1305
1305
1306
+ /// The number of blocks to wait for a channel_announcement to propagate such that payments using an
1307
+ /// older SCID can still be relayed. Once the spend of the previous funding transaction has reached
1308
+ /// this number of confirmations, the corresponding SCID will be forgotten.
1309
+ const CHANNEL_ANNOUNCEMENT_PROPAGATION_DELAY: u32 = 12;
1310
+
1306
1311
struct PendingChannelMonitorUpdate {
1307
1312
update: ChannelMonitorUpdate,
1308
1313
}
@@ -2280,6 +2285,10 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
2280
2285
// blinded paths instead of simple scid+node_id aliases.
2281
2286
outbound_scid_alias: u64,
2282
2287
2288
+ /// Short channel ids used by any prior FundingScope. These are maintained such that
2289
+ /// ChannelManager can look up the channel for any pending HTLCs.
2290
+ historical_scids: Vec<u64>,
2291
+
2283
2292
// We track whether we already emitted a `ChannelPending` event.
2284
2293
channel_pending_event_emitted: bool,
2285
2294
@@ -3097,6 +3106,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
3097
3106
3098
3107
latest_inbound_scid_alias: None,
3099
3108
outbound_scid_alias: 0,
3109
+ historical_scids: Vec::new(),
3100
3110
3101
3111
channel_pending_event_emitted: false,
3102
3112
funding_tx_broadcast_safe_event_emitted: false,
@@ -3338,6 +3348,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
3338
3348
3339
3349
latest_inbound_scid_alias: None,
3340
3350
outbound_scid_alias,
3351
+ historical_scids: Vec::new(),
3341
3352
3342
3353
channel_pending_event_emitted: false,
3343
3354
funding_tx_broadcast_safe_event_emitted: false,
@@ -5392,6 +5403,11 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
5392
5403
5393
5404
Ok(())
5394
5405
}
5406
+
5407
+ /// Returns SCIDs that have been associated with the channel's funding transactions.
5408
+ pub fn historical_scids(&self) -> &[u64] {
5409
+ &self.historical_scids[..]
5410
+ }
5395
5411
}
5396
5412
5397
5413
// Internal utility functions for channels
@@ -5579,6 +5595,9 @@ pub(super) struct FundedChannel<SP: Deref> where SP::Target: SignerProvider {
5579
5595
#[cfg(splicing)]
5580
5596
macro_rules! promote_splice_funding {
5581
5597
($self: expr, $funding: expr) => {
5598
+ if let Some(scid) = $self.funding.short_channel_id {
5599
+ $self.context.historical_scids.push(scid);
5600
+ }
5582
5601
core::mem::swap(&mut $self.funding, $funding);
5583
5602
$self.pending_splice = None;
5584
5603
$self.pending_funding.clear();
@@ -10280,6 +10299,28 @@ impl<SP: Deref> FundedChannel<SP> where
10280
10299
pub fn has_pending_splice(&self) -> bool {
10281
10300
self.pending_splice.is_some()
10282
10301
}
10302
+
10303
+ pub fn remove_legacy_scids_before_block(&mut self, height: u32) -> alloc::vec::Drain<u64> {
10304
+ let end = self.funding
10305
+ .get_short_channel_id()
10306
+ .and_then(|current_scid| {
10307
+ let historical_scids = &self.context.historical_scids;
10308
+ historical_scids
10309
+ .iter()
10310
+ .zip(historical_scids.iter().skip(1).chain(core::iter::once(¤t_scid)))
10311
+ .map(|(_, next_scid)| {
10312
+ let funding_height = block_from_scid(*next_scid);
10313
+ let retain_scid = funding_height + CHANNEL_ANNOUNCEMENT_PROPAGATION_DELAY - 1 > height;
10314
+ retain_scid
10315
+ })
10316
+ .position(|retain_scid| retain_scid)
10317
+ })
10318
+ .unwrap_or(0);
10319
+
10320
+ // Drains the oldest historical SCIDs until reaching one without
10321
+ // CHANNEL_ANNOUNCEMENT_PROPAGATION_DELAY confirmations.
10322
+ self.context.historical_scids.drain(0..end)
10323
+ }
10283
10324
}
10284
10325
10285
10326
/// A not-yet-funded outbound (from holder) channel using V1 channel establishment.
@@ -11658,6 +11699,7 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
11658
11699
(57, holding_cell_failure_attribution_data, optional_vec), // Added in 0.2
11659
11700
(58, self.interactive_tx_signing_session, option), // Added in 0.2
11660
11701
(59, self.funding.minimum_depth_override, option), // Added in 0.2
11702
+ (60, self.context.historical_scids, optional_vec), // Added in 0.2
11661
11703
});
11662
11704
11663
11705
Ok(())
@@ -11973,6 +12015,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
11973
12015
let mut is_manual_broadcast = None;
11974
12016
11975
12017
let mut pending_funding = Some(Vec::new());
12018
+ let mut historical_scids = Some(Vec::new());
11976
12019
11977
12020
let mut interactive_tx_signing_session: Option<InteractiveTxSigningSession> = None;
11978
12021
@@ -12018,6 +12061,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
12018
12061
(57, holding_cell_failure_attribution_data, optional_vec),
12019
12062
(58, interactive_tx_signing_session, option), // Added in 0.2
12020
12063
(59, minimum_depth_override, option), // Added in 0.2
12064
+ (60, historical_scids, optional_vec), // Added in 0.2
12021
12065
});
12022
12066
12023
12067
let holder_signer = signer_provider.derive_channel_signer(channel_keys_id);
@@ -12291,6 +12335,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
12291
12335
latest_inbound_scid_alias,
12292
12336
// Later in the ChannelManager deserialization phase we scan for channels and assign scid aliases if its missing
12293
12337
outbound_scid_alias,
12338
+ historical_scids: historical_scids.unwrap(),
12294
12339
12295
12340
funding_tx_broadcast_safe_event_emitted: funding_tx_broadcast_safe_event_emitted.unwrap_or(false),
12296
12341
channel_pending_event_emitted: channel_pending_event_emitted.unwrap_or(true),
0 commit comments