Skip to content

Commit a9e3b0b

Browse files
committed
Add FundingScope::minimum_depth_override
When a channel is funded using the coinbase transaction, the minimum depth must be at least COINBASE_MATURITY. Instead of overriding it in ChannelContext, add FundingScope::minimum_depth_override for this purpose. Otherwise, if the overridden minimum_depth were reused in a splice's minimum dpeth, then sending splice_locked would be unnecessarily delayed. Later, this can be used to override the minimum depth needed for a splice.
1 parent a3bf741 commit a9e3b0b

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

lightning/src/ln/channel.rs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1952,6 +1952,10 @@ pub(super) struct FundingScope {
19521952
funding_tx_confirmed_in: Option<BlockHash>,
19531953
funding_tx_confirmation_height: u32,
19541954
short_channel_id: Option<u64>,
1955+
1956+
/// The minimum number of confirmations before the funding is locked. If set, this will override
1957+
/// [`ChannelContext::minimum_depth`].
1958+
minimum_depth_override: Option<u32>,
19551959
}
19561960

19571961
impl Writeable for FundingScope {
@@ -1965,6 +1969,7 @@ impl Writeable for FundingScope {
19651969
(11, self.funding_tx_confirmed_in, option),
19661970
(13, self.funding_tx_confirmation_height, required),
19671971
(15, self.short_channel_id, option),
1972+
(17, self.minimum_depth_override, option),
19681973
});
19691974
Ok(())
19701975
}
@@ -1981,6 +1986,7 @@ impl Readable for FundingScope {
19811986
let mut funding_tx_confirmed_in = None;
19821987
let mut funding_tx_confirmation_height = RequiredWrapper(None);
19831988
let mut short_channel_id = None;
1989+
let mut minimum_depth_override = None;
19841990

19851991
read_tlv_fields!(reader, {
19861992
(1, value_to_self_msat, required),
@@ -1991,6 +1997,7 @@ impl Readable for FundingScope {
19911997
(11, funding_tx_confirmed_in, option),
19921998
(13, funding_tx_confirmation_height, required),
19931999
(15, short_channel_id, option),
2000+
(17, minimum_depth_override, option),
19942001
});
19952002

19962003
Ok(Self {
@@ -2006,6 +2013,7 @@ impl Readable for FundingScope {
20062013
funding_tx_confirmed_in,
20072014
funding_tx_confirmation_height: funding_tx_confirmation_height.0.unwrap(),
20082015
short_channel_id,
2016+
minimum_depth_override,
20092017
#[cfg(any(test, fuzzing))]
20102018
next_local_commitment_tx_fee_info_cached: Mutex::new(None),
20112019
#[cfg(any(test, fuzzing))]
@@ -3114,6 +3122,7 @@ where
31143122
funding_tx_confirmed_in: None,
31153123
funding_tx_confirmation_height: 0,
31163124
short_channel_id: None,
3125+
minimum_depth_override: None,
31173126
};
31183127
let channel_context = ChannelContext {
31193128
user_id,
@@ -3355,6 +3364,7 @@ where
33553364
funding_tx_confirmed_in: None,
33563365
funding_tx_confirmation_height: 0,
33573366
short_channel_id: None,
3367+
minimum_depth_override: None,
33583368
};
33593369
let channel_context = Self {
33603370
user_id,
@@ -5455,7 +5465,9 @@ where
54555465
}
54565466

54575467
fn check_funding_meets_minimum_depth(&self, funding: &mut FundingScope, height: u32) -> bool {
5458-
if funding.funding_tx_confirmation_height == 0 && self.minimum_depth != Some(0) {
5468+
let minimum_depth = funding.minimum_depth_override.or(self.minimum_depth);
5469+
5470+
if funding.funding_tx_confirmation_height == 0 && minimum_depth != Some(0) {
54595471
return false;
54605472
}
54615473

@@ -5465,7 +5477,7 @@ where
54655477
funding.funding_tx_confirmation_height = 0;
54665478
}
54675479

5468-
if funding_tx_confirmations < self.minimum_depth.unwrap_or(0) as i64 {
5480+
if funding_tx_confirmations < minimum_depth.unwrap_or(0) as i64 {
54695481
return false;
54705482
}
54715483

@@ -8883,7 +8895,7 @@ where
88838895
if tx.is_coinbase() &&
88848896
self.context.minimum_depth.unwrap_or(0) > 0 &&
88858897
self.context.minimum_depth.unwrap_or(0) < COINBASE_MATURITY {
8886-
self.context.minimum_depth = Some(COINBASE_MATURITY);
8898+
self.funding.minimum_depth_override = Some(COINBASE_MATURITY);
88878899
}
88888900
}
88898901
// If we allow 1-conf funding, we may need to check for channel_ready here and
@@ -10323,7 +10335,7 @@ where
1032310335
if funding_transaction.is_coinbase() &&
1032410336
self.context.minimum_depth.unwrap_or(0) > 0 &&
1032510337
self.context.minimum_depth.unwrap_or(0) < COINBASE_MATURITY {
10326-
self.context.minimum_depth = Some(COINBASE_MATURITY);
10338+
self.funding.minimum_depth_override = Some(COINBASE_MATURITY);
1032710339
}
1032810340

1032910341
debug_assert!(self.funding.funding_transaction.is_none());
@@ -11597,7 +11609,8 @@ where
1159711609
(54, self.pending_funding, optional_vec), // Added in 0.2
1159811610
(55, removed_htlc_failure_attribution_data, optional_vec), // Added in 0.2
1159911611
(57, holding_cell_failure_attribution_data, optional_vec), // Added in 0.2
11600-
(58, self.interactive_tx_signing_session, option) // Added in 0.2
11612+
(58, self.interactive_tx_signing_session, option), // Added in 0.2
11613+
(59, self.funding.minimum_depth_override, option), // Added in 0.2
1160111614
});
1160211615

1160311616
Ok(())
@@ -11918,6 +11931,8 @@ where
1191811931

1191911932
let mut interactive_tx_signing_session: Option<InteractiveTxSigningSession> = None;
1192011933

11934+
let mut minimum_depth_override: Option<u32> = None;
11935+
1192111936
read_tlv_fields!(reader, {
1192211937
(0, announcement_sigs, option),
1192311938
(1, minimum_depth, option),
@@ -11957,6 +11972,7 @@ where
1195711972
(55, removed_htlc_failure_attribution_data, optional_vec),
1195811973
(57, holding_cell_failure_attribution_data, optional_vec),
1195911974
(58, interactive_tx_signing_session, option), // Added in 0.2
11975+
(59, minimum_depth_override, option), // Added in 0.2
1196011976
});
1196111977

1196211978
let holder_signer = signer_provider.derive_channel_signer(channel_keys_id);
@@ -12132,6 +12148,7 @@ where
1213212148
funding_tx_confirmed_in,
1213312149
funding_tx_confirmation_height,
1213412150
short_channel_id,
12151+
minimum_depth_override,
1213512152
},
1213612153
pending_funding: pending_funding.unwrap(),
1213712154
context: ChannelContext {

0 commit comments

Comments
 (0)