@@ -4970,7 +4970,24 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
49704970 }
49714971
49724972 fn check_funding_meets_minimum_depth(&self, funding: &mut FundingScope, height: u32) -> bool {
4973- if funding.funding_tx_confirmation_height == 0 && self.minimum_depth != Some(0) {
4973+ let is_coinbase = funding
4974+ .funding_transaction
4975+ .as_ref()
4976+ .map(|tx| tx.is_coinbase())
4977+ .unwrap_or(false);
4978+
4979+ let minimum_depth = {
4980+ // If the funding transaction is a coinbase transaction, we need to set the minimum
4981+ // depth to 100. We can skip this if it is a zero-conf channel.
4982+ let minimum_depth = self.minimum_depth.unwrap_or(0);
4983+ if is_coinbase && minimum_depth > 0 && minimum_depth < COINBASE_MATURITY {
4984+ Some(COINBASE_MATURITY)
4985+ } else {
4986+ self.minimum_depth
4987+ }
4988+ };
4989+
4990+ if funding.funding_tx_confirmation_height == 0 && minimum_depth != Some(0) {
49744991 return false;
49754992 }
49764993
@@ -4979,7 +4996,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
49794996 funding.funding_tx_confirmation_height = 0;
49804997 }
49814998
4982- if funding_tx_confirmations < self. minimum_depth.unwrap_or(0) as i64 {
4999+ if funding_tx_confirmations < minimum_depth.unwrap_or(0) as i64 {
49835000 return false;
49845001 }
49855002
@@ -8315,20 +8332,20 @@ impl<SP: Deref> FundedChannel<SP> where
83158332 }
83168333 }
83178334
8335+ // The acceptor of v1-established channels doesn't have the funding
8336+ // transaction until it is seen on chain. Set it so that minimum_depth
8337+ // checks can tell if the coinbase transaction was used.
8338+ if self.funding.funding_transaction.is_none() {
8339+ self.funding.funding_transaction = Some(tx.clone());
8340+ }
8341+
83188342 self.funding.funding_tx_confirmation_height = height;
83198343 self.funding.funding_tx_confirmed_in = Some(*block_hash);
83208344 self.funding.short_channel_id = match scid_from_parts(height as u64, index_in_block as u64, txo_idx as u64) {
83218345 Ok(scid) => Some(scid),
83228346 Err(_) => panic!("Block was bogus - either height was > 16 million, had > 16 million transactions, or had > 65k outputs"),
83238347 }
83248348 }
8325- // If this is a coinbase transaction and not a 0-conf channel
8326- // we should update our min_depth to 100 to handle coinbase maturity
8327- if tx.is_coinbase() &&
8328- self.context.minimum_depth.unwrap_or(0) > 0 &&
8329- self.context.minimum_depth.unwrap_or(0) < COINBASE_MATURITY {
8330- self.context.minimum_depth = Some(COINBASE_MATURITY);
8331- }
83328349 }
83338350 // If we allow 1-conf funding, we may need to check for channel_ready here and
83348351 // send it immediately instead of waiting for a best_block_updated call (which
@@ -9721,14 +9738,6 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
97219738 self.context.channel_state = ChannelState::FundingNegotiated;
97229739 self.context.channel_id = ChannelId::v1_from_funding_outpoint(funding_txo);
97239740
9724- // If the funding transaction is a coinbase transaction, we need to set the minimum depth to 100.
9725- // We can skip this if it is a zero-conf channel.
9726- if funding_transaction.is_coinbase() &&
9727- self.context.minimum_depth.unwrap_or(0) > 0 &&
9728- self.context.minimum_depth.unwrap_or(0) < COINBASE_MATURITY {
9729- self.context.minimum_depth = Some(COINBASE_MATURITY);
9730- }
9731-
97329741 debug_assert!(self.funding.funding_transaction.is_none());
97339742 self.funding.funding_transaction = Some(funding_transaction);
97349743 self.context.is_batch_funding = Some(()).filter(|_| is_batch_funding);
0 commit comments