@@ -1964,6 +1964,10 @@ pub(super) struct FundingScope {
1964
1964
funding_tx_confirmed_in: Option<BlockHash>,
1965
1965
funding_tx_confirmation_height: u32,
1966
1966
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>,
1967
1971
}
1968
1972
1969
1973
impl Writeable for FundingScope {
@@ -1977,6 +1981,7 @@ impl Writeable for FundingScope {
1977
1981
(11, self.funding_tx_confirmed_in, option),
1978
1982
(13, self.funding_tx_confirmation_height, required),
1979
1983
(15, self.short_channel_id, option),
1984
+ (17, self.minimum_depth_override, option),
1980
1985
});
1981
1986
Ok(())
1982
1987
}
@@ -1993,6 +1998,7 @@ impl Readable for FundingScope {
1993
1998
let mut funding_tx_confirmed_in = None;
1994
1999
let mut funding_tx_confirmation_height = RequiredWrapper(None);
1995
2000
let mut short_channel_id = None;
2001
+ let mut minimum_depth_override = None;
1996
2002
1997
2003
read_tlv_fields!(reader, {
1998
2004
(1, value_to_self_msat, required),
@@ -2003,6 +2009,7 @@ impl Readable for FundingScope {
2003
2009
(11, funding_tx_confirmed_in, option),
2004
2010
(13, funding_tx_confirmation_height, required),
2005
2011
(15, short_channel_id, option),
2012
+ (17, minimum_depth_override, option),
2006
2013
});
2007
2014
2008
2015
Ok(Self {
@@ -2018,6 +2025,7 @@ impl Readable for FundingScope {
2018
2025
funding_tx_confirmed_in,
2019
2026
funding_tx_confirmation_height: funding_tx_confirmation_height.0.unwrap(),
2020
2027
short_channel_id,
2028
+ minimum_depth_override,
2021
2029
#[cfg(any(test, fuzzing))]
2022
2030
next_local_commitment_tx_fee_info_cached: Mutex::new(None),
2023
2031
#[cfg(any(test, fuzzing))]
@@ -3130,6 +3138,7 @@ where
3130
3138
funding_tx_confirmed_in: None,
3131
3139
funding_tx_confirmation_height: 0,
3132
3140
short_channel_id: None,
3141
+ minimum_depth_override: None,
3133
3142
};
3134
3143
let channel_context = ChannelContext {
3135
3144
user_id,
@@ -3371,6 +3380,7 @@ where
3371
3380
funding_tx_confirmed_in: None,
3372
3381
funding_tx_confirmation_height: 0,
3373
3382
short_channel_id: None,
3383
+ minimum_depth_override: None,
3374
3384
};
3375
3385
let channel_context = Self {
3376
3386
user_id,
@@ -5467,7 +5477,9 @@ where
5467
5477
}
5468
5478
5469
5479
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) {
5471
5483
return false;
5472
5484
}
5473
5485
@@ -5477,7 +5489,7 @@ where
5477
5489
funding.funding_tx_confirmation_height = 0;
5478
5490
}
5479
5491
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 {
5481
5493
return false;
5482
5494
}
5483
5495
@@ -8927,7 +8939,7 @@ where
8927
8939
if tx.is_coinbase() &&
8928
8940
self.context.minimum_depth.unwrap_or(0) > 0 &&
8929
8941
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);
8931
8943
}
8932
8944
}
8933
8945
// If we allow 1-conf funding, we may need to check for channel_ready here and
@@ -10369,7 +10381,7 @@ where
10369
10381
if funding_transaction.is_coinbase() &&
10370
10382
self.context.minimum_depth.unwrap_or(0) > 0 &&
10371
10383
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);
10373
10385
}
10374
10386
10375
10387
debug_assert!(self.funding.funding_transaction.is_none());
@@ -11650,7 +11662,8 @@ where
11650
11662
(54, self.pending_funding, optional_vec), // Added in 0.2
11651
11663
(55, removed_htlc_failure_attribution_data, optional_vec), // Added in 0.2
11652
11664
(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
11654
11667
});
11655
11668
11656
11669
Ok(())
@@ -11971,6 +11984,8 @@ where
11971
11984
11972
11985
let mut interactive_tx_signing_session: Option<InteractiveTxSigningSession> = None;
11973
11986
11987
+ let mut minimum_depth_override: Option<u32> = None;
11988
+
11974
11989
read_tlv_fields!(reader, {
11975
11990
(0, announcement_sigs, option),
11976
11991
(1, minimum_depth, option),
@@ -12010,6 +12025,7 @@ where
12010
12025
(55, removed_htlc_failure_attribution_data, optional_vec),
12011
12026
(57, holding_cell_failure_attribution_data, optional_vec),
12012
12027
(58, interactive_tx_signing_session, option), // Added in 0.2
12028
+ (59, minimum_depth_override, option), // Added in 0.2
12013
12029
});
12014
12030
12015
12031
let holder_signer = signer_provider.derive_channel_signer(channel_keys_id);
@@ -12185,6 +12201,7 @@ where
12185
12201
funding_tx_confirmed_in,
12186
12202
funding_tx_confirmation_height,
12187
12203
short_channel_id,
12204
+ minimum_depth_override,
12188
12205
},
12189
12206
pending_funding: pending_funding.unwrap(),
12190
12207
context: ChannelContext {
0 commit comments