Skip to content

Commit 27be59b

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 19b775a commit 27be59b

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
@@ -1964,6 +1964,10 @@ pub(super) struct FundingScope {
19641964
funding_tx_confirmed_in: Option<BlockHash>,
19651965
funding_tx_confirmation_height: u32,
19661966
short_channel_id: Option<u64>,
1967+
1968+
/// The minimum number of confirmations before the funding is locked. If set, this will override
1969+
/// [`ChannelContext::minimum_depth`].
1970+
minimum_depth_override: Option<u32>,
19671971
}
19681972

19691973
impl Writeable for FundingScope {
@@ -1977,6 +1981,7 @@ impl Writeable for FundingScope {
19771981
(11, self.funding_tx_confirmed_in, option),
19781982
(13, self.funding_tx_confirmation_height, required),
19791983
(15, self.short_channel_id, option),
1984+
(17, self.minimum_depth_override, option),
19801985
});
19811986
Ok(())
19821987
}
@@ -1993,6 +1998,7 @@ impl Readable for FundingScope {
19931998
let mut funding_tx_confirmed_in = None;
19941999
let mut funding_tx_confirmation_height = RequiredWrapper(None);
19952000
let mut short_channel_id = None;
2001+
let mut minimum_depth_override = None;
19962002

19972003
read_tlv_fields!(reader, {
19982004
(1, value_to_self_msat, required),
@@ -2003,6 +2009,7 @@ impl Readable for FundingScope {
20032009
(11, funding_tx_confirmed_in, option),
20042010
(13, funding_tx_confirmation_height, required),
20052011
(15, short_channel_id, option),
2012+
(17, minimum_depth_override, option),
20062013
});
20072014

20082015
Ok(Self {
@@ -2018,6 +2025,7 @@ impl Readable for FundingScope {
20182025
funding_tx_confirmed_in,
20192026
funding_tx_confirmation_height: funding_tx_confirmation_height.0.unwrap(),
20202027
short_channel_id,
2028+
minimum_depth_override,
20212029
#[cfg(any(test, fuzzing))]
20222030
next_local_commitment_tx_fee_info_cached: Mutex::new(None),
20232031
#[cfg(any(test, fuzzing))]
@@ -3130,6 +3138,7 @@ where
31303138
funding_tx_confirmed_in: None,
31313139
funding_tx_confirmation_height: 0,
31323140
short_channel_id: None,
3141+
minimum_depth_override: None,
31333142
};
31343143
let channel_context = ChannelContext {
31353144
user_id,
@@ -3371,6 +3380,7 @@ where
33713380
funding_tx_confirmed_in: None,
33723381
funding_tx_confirmation_height: 0,
33733382
short_channel_id: None,
3383+
minimum_depth_override: None,
33743384
};
33753385
let channel_context = Self {
33763386
user_id,
@@ -5467,7 +5477,9 @@ where
54675477
}
54685478

54695479
fn check_funding_meets_minimum_depth(&self, funding: &mut FundingScope, height: u32) -> bool {
5470-
if funding.funding_tx_confirmation_height == 0 && self.minimum_depth != Some(0) {
5480+
let minimum_depth = funding.minimum_depth_override.or(self.minimum_depth);
5481+
5482+
if funding.funding_tx_confirmation_height == 0 && minimum_depth != Some(0) {
54715483
return false;
54725484
}
54735485

@@ -5477,7 +5489,7 @@ where
54775489
funding.funding_tx_confirmation_height = 0;
54785490
}
54795491

5480-
if funding_tx_confirmations < self.minimum_depth.unwrap_or(0) as i64 {
5492+
if funding_tx_confirmations < minimum_depth.unwrap_or(0) as i64 {
54815493
return false;
54825494
}
54835495

@@ -8927,7 +8939,7 @@ where
89278939
if tx.is_coinbase() &&
89288940
self.context.minimum_depth.unwrap_or(0) > 0 &&
89298941
self.context.minimum_depth.unwrap_or(0) < COINBASE_MATURITY {
8930-
self.context.minimum_depth = Some(COINBASE_MATURITY);
8942+
self.funding.minimum_depth_override = Some(COINBASE_MATURITY);
89318943
}
89328944
}
89338945
// If we allow 1-conf funding, we may need to check for channel_ready here and
@@ -10369,7 +10381,7 @@ where
1036910381
if funding_transaction.is_coinbase() &&
1037010382
self.context.minimum_depth.unwrap_or(0) > 0 &&
1037110383
self.context.minimum_depth.unwrap_or(0) < COINBASE_MATURITY {
10372-
self.context.minimum_depth = Some(COINBASE_MATURITY);
10384+
self.funding.minimum_depth_override = Some(COINBASE_MATURITY);
1037310385
}
1037410386

1037510387
debug_assert!(self.funding.funding_transaction.is_none());
@@ -11650,7 +11662,8 @@ where
1165011662
(54, self.pending_funding, optional_vec), // Added in 0.2
1165111663
(55, removed_htlc_failure_attribution_data, optional_vec), // Added in 0.2
1165211664
(57, holding_cell_failure_attribution_data, optional_vec), // Added in 0.2
11653-
(58, self.interactive_tx_signing_session, option) // Added in 0.2
11665+
(58, self.interactive_tx_signing_session, option), // Added in 0.2
11666+
(59, self.funding.minimum_depth_override, option), // Added in 0.2
1165411667
});
1165511668

1165611669
Ok(())
@@ -11971,6 +11984,8 @@ where
1197111984

1197211985
let mut interactive_tx_signing_session: Option<InteractiveTxSigningSession> = None;
1197311986

11987+
let mut minimum_depth_override: Option<u32> = None;
11988+
1197411989
read_tlv_fields!(reader, {
1197511990
(0, announcement_sigs, option),
1197611991
(1, minimum_depth, option),
@@ -12010,6 +12025,7 @@ where
1201012025
(55, removed_htlc_failure_attribution_data, optional_vec),
1201112026
(57, holding_cell_failure_attribution_data, optional_vec),
1201212027
(58, interactive_tx_signing_session, option), // Added in 0.2
12028+
(59, minimum_depth_override, option), // Added in 0.2
1201312029
});
1201412030

1201512031
let holder_signer = signer_provider.derive_channel_signer(channel_keys_id);
@@ -12185,6 +12201,7 @@ where
1218512201
funding_tx_confirmed_in,
1218612202
funding_tx_confirmation_height,
1218712203
short_channel_id,
12204+
minimum_depth_override,
1218812205
},
1218912206
pending_funding: pending_funding.unwrap(),
1219012207
context: ChannelContext {

0 commit comments

Comments
 (0)