@@ -1825,6 +1825,10 @@ pub(super) struct FundingScope {
18251825 funding_tx_confirmed_in: Option<BlockHash>,
18261826 funding_tx_confirmation_height: u32,
18271827 short_channel_id: Option<u64>,
1828+
1829+ /// The minimum number of confirmations before the funding is locked. If set, this will override
1830+ /// [`ChannelContext::minimum_depth`].
1831+ minimum_depth_override: Option<u32>,
18281832}
18291833
18301834impl Writeable for FundingScope {
@@ -1838,6 +1842,7 @@ impl Writeable for FundingScope {
18381842 (11, self.funding_tx_confirmed_in, option),
18391843 (13, self.funding_tx_confirmation_height, required),
18401844 (15, self.short_channel_id, option),
1845+ (17, self.minimum_depth_override, option),
18411846 });
18421847 Ok(())
18431848 }
@@ -1853,6 +1858,7 @@ impl Readable for FundingScope {
18531858 let mut funding_tx_confirmed_in = None;
18541859 let mut funding_tx_confirmation_height = RequiredWrapper(None);
18551860 let mut short_channel_id = None;
1861+ let mut minimum_depth_override = None;
18561862
18571863 read_tlv_fields!(reader, {
18581864 (1, value_to_self_msat, required),
@@ -1863,6 +1869,7 @@ impl Readable for FundingScope {
18631869 (11, funding_tx_confirmed_in, option),
18641870 (13, funding_tx_confirmation_height, required),
18651871 (15, short_channel_id, option),
1872+ (17, minimum_depth_override, option),
18661873 });
18671874
18681875 Ok(Self {
@@ -1878,6 +1885,7 @@ impl Readable for FundingScope {
18781885 funding_tx_confirmed_in,
18791886 funding_tx_confirmation_height: funding_tx_confirmation_height.0.unwrap(),
18801887 short_channel_id,
1888+ minimum_depth_override,
18811889 #[cfg(any(test, fuzzing))]
18821890 next_local_commitment_tx_fee_info_cached: Mutex::new(None),
18831891 #[cfg(any(test, fuzzing))]
@@ -2952,6 +2960,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
29522960 funding_tx_confirmed_in: None,
29532961 funding_tx_confirmation_height: 0,
29542962 short_channel_id: None,
2963+ minimum_depth_override: None,
29552964 };
29562965 let channel_context = ChannelContext {
29572966 user_id,
@@ -3192,6 +3201,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
31923201 funding_tx_confirmed_in: None,
31933202 funding_tx_confirmation_height: 0,
31943203 short_channel_id: None,
3204+ minimum_depth_override: None,
31953205 };
31963206 let channel_context = Self {
31973207 user_id,
@@ -5257,7 +5267,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
52575267 }
52585268
52595269 fn check_funding_meets_minimum_depth(&self, funding: &mut FundingScope, height: u32) -> bool {
5260- if funding.funding_tx_confirmation_height == 0 && self.minimum_depth != Some(0) {
5270+ let minimum_depth = funding.minimum_depth_override.or(self.minimum_depth);
5271+
5272+ if funding.funding_tx_confirmation_height == 0 && minimum_depth != Some(0) {
52615273 return false;
52625274 }
52635275
@@ -5266,7 +5278,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
52665278 funding.funding_tx_confirmation_height = 0;
52675279 }
52685280
5269- if funding_tx_confirmations < self. minimum_depth.unwrap_or(0) as i64 {
5281+ if funding_tx_confirmations < minimum_depth.unwrap_or(0) as i64 {
52705282 return false;
52715283 }
52725284
@@ -8604,7 +8616,7 @@ impl<SP: Deref> FundedChannel<SP> where
86048616 if tx.is_coinbase() &&
86058617 self.context.minimum_depth.unwrap_or(0) > 0 &&
86068618 self.context.minimum_depth.unwrap_or(0) < COINBASE_MATURITY {
8607- self.context.minimum_depth = Some(COINBASE_MATURITY);
8619+ self.funding.minimum_depth_override = Some(COINBASE_MATURITY);
86088620 }
86098621 }
86108622 // If we allow 1-conf funding, we may need to check for channel_ready here and
@@ -10008,7 +10020,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
1000810020 if funding_transaction.is_coinbase() &&
1000910021 self.context.minimum_depth.unwrap_or(0) > 0 &&
1001010022 self.context.minimum_depth.unwrap_or(0) < COINBASE_MATURITY {
10011- self.context.minimum_depth = Some(COINBASE_MATURITY);
10023+ self.funding.minimum_depth_override = Some(COINBASE_MATURITY);
1001210024 }
1001310025
1001410026 debug_assert!(self.funding.funding_transaction.is_none());
@@ -11246,7 +11258,8 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
1124611258 (54, self.pending_funding, optional_vec), // Added in 0.2
1124711259 (55, removed_htlc_failure_attribution_data, optional_vec), // Added in 0.2
1124811260 (57, holding_cell_failure_attribution_data, optional_vec), // Added in 0.2
11249- (58, self.interactive_tx_signing_session, option) // Added in 0.2
11261+ (58, self.interactive_tx_signing_session, option), // Added in 0.2
11262+ (59, self.funding.minimum_depth_override, option), // Added in 0.2
1125011263 });
1125111264
1125211265 Ok(())
@@ -11565,6 +11578,8 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1156511578
1156611579 let mut interactive_tx_signing_session: Option<InteractiveTxSigningSession> = None;
1156711580
11581+ let mut minimum_depth_override: Option<u32> = None;
11582+
1156811583 read_tlv_fields!(reader, {
1156911584 (0, announcement_sigs, option),
1157011585 (1, minimum_depth, option),
@@ -11604,6 +11619,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1160411619 (55, removed_htlc_failure_attribution_data, optional_vec),
1160511620 (57, holding_cell_failure_attribution_data, optional_vec),
1160611621 (58, interactive_tx_signing_session, option), // Added in 0.2
11622+ (59, minimum_depth_override, option), // Added in 0.2
1160711623 });
1160811624
1160911625 let holder_signer = signer_provider.derive_channel_signer(channel_keys_id);
@@ -11779,6 +11795,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1177911795 funding_tx_confirmed_in,
1178011796 funding_tx_confirmation_height,
1178111797 short_channel_id,
11798+ minimum_depth_override,
1178211799 },
1178311800 pending_funding: pending_funding.unwrap(),
1178411801 context: ChannelContext {
0 commit comments