@@ -1952,6 +1952,10 @@ pub(super) struct FundingScope {
1952
1952
funding_tx_confirmed_in: Option<BlockHash>,
1953
1953
funding_tx_confirmation_height: u32,
1954
1954
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>,
1955
1959
}
1956
1960
1957
1961
impl Writeable for FundingScope {
@@ -1965,6 +1969,7 @@ impl Writeable for FundingScope {
1965
1969
(11, self.funding_tx_confirmed_in, option),
1966
1970
(13, self.funding_tx_confirmation_height, required),
1967
1971
(15, self.short_channel_id, option),
1972
+ (17, self.minimum_depth_override, option),
1968
1973
});
1969
1974
Ok(())
1970
1975
}
@@ -1981,6 +1986,7 @@ impl Readable for FundingScope {
1981
1986
let mut funding_tx_confirmed_in = None;
1982
1987
let mut funding_tx_confirmation_height = RequiredWrapper(None);
1983
1988
let mut short_channel_id = None;
1989
+ let mut minimum_depth_override = None;
1984
1990
1985
1991
read_tlv_fields!(reader, {
1986
1992
(1, value_to_self_msat, required),
@@ -1991,6 +1997,7 @@ impl Readable for FundingScope {
1991
1997
(11, funding_tx_confirmed_in, option),
1992
1998
(13, funding_tx_confirmation_height, required),
1993
1999
(15, short_channel_id, option),
2000
+ (17, minimum_depth_override, option),
1994
2001
});
1995
2002
1996
2003
Ok(Self {
@@ -2006,6 +2013,7 @@ impl Readable for FundingScope {
2006
2013
funding_tx_confirmed_in,
2007
2014
funding_tx_confirmation_height: funding_tx_confirmation_height.0.unwrap(),
2008
2015
short_channel_id,
2016
+ minimum_depth_override,
2009
2017
#[cfg(any(test, fuzzing))]
2010
2018
next_local_commitment_tx_fee_info_cached: Mutex::new(None),
2011
2019
#[cfg(any(test, fuzzing))]
@@ -3114,6 +3122,7 @@ where
3114
3122
funding_tx_confirmed_in: None,
3115
3123
funding_tx_confirmation_height: 0,
3116
3124
short_channel_id: None,
3125
+ minimum_depth_override: None,
3117
3126
};
3118
3127
let channel_context = ChannelContext {
3119
3128
user_id,
@@ -3355,6 +3364,7 @@ where
3355
3364
funding_tx_confirmed_in: None,
3356
3365
funding_tx_confirmation_height: 0,
3357
3366
short_channel_id: None,
3367
+ minimum_depth_override: None,
3358
3368
};
3359
3369
let channel_context = Self {
3360
3370
user_id,
@@ -5455,7 +5465,9 @@ where
5455
5465
}
5456
5466
5457
5467
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) {
5459
5471
return false;
5460
5472
}
5461
5473
@@ -5465,7 +5477,7 @@ where
5465
5477
funding.funding_tx_confirmation_height = 0;
5466
5478
}
5467
5479
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 {
5469
5481
return false;
5470
5482
}
5471
5483
@@ -8883,7 +8895,7 @@ where
8883
8895
if tx.is_coinbase() &&
8884
8896
self.context.minimum_depth.unwrap_or(0) > 0 &&
8885
8897
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);
8887
8899
}
8888
8900
}
8889
8901
// If we allow 1-conf funding, we may need to check for channel_ready here and
@@ -10323,7 +10335,7 @@ where
10323
10335
if funding_transaction.is_coinbase() &&
10324
10336
self.context.minimum_depth.unwrap_or(0) > 0 &&
10325
10337
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);
10327
10339
}
10328
10340
10329
10341
debug_assert!(self.funding.funding_transaction.is_none());
@@ -11597,7 +11609,8 @@ where
11597
11609
(54, self.pending_funding, optional_vec), // Added in 0.2
11598
11610
(55, removed_htlc_failure_attribution_data, optional_vec), // Added in 0.2
11599
11611
(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
11601
11614
});
11602
11615
11603
11616
Ok(())
@@ -11918,6 +11931,8 @@ where
11918
11931
11919
11932
let mut interactive_tx_signing_session: Option<InteractiveTxSigningSession> = None;
11920
11933
11934
+ let mut minimum_depth_override: Option<u32> = None;
11935
+
11921
11936
read_tlv_fields!(reader, {
11922
11937
(0, announcement_sigs, option),
11923
11938
(1, minimum_depth, option),
@@ -11957,6 +11972,7 @@ where
11957
11972
(55, removed_htlc_failure_attribution_data, optional_vec),
11958
11973
(57, holding_cell_failure_attribution_data, optional_vec),
11959
11974
(58, interactive_tx_signing_session, option), // Added in 0.2
11975
+ (59, minimum_depth_override, option), // Added in 0.2
11960
11976
});
11961
11977
11962
11978
let holder_signer = signer_provider.derive_channel_signer(channel_keys_id);
@@ -12132,6 +12148,7 @@ where
12132
12148
funding_tx_confirmed_in,
12133
12149
funding_tx_confirmation_height,
12134
12150
short_channel_id,
12151
+ minimum_depth_override,
12135
12152
},
12136
12153
pending_funding: pending_funding.unwrap(),
12137
12154
context: ChannelContext {
0 commit comments