@@ -4856,7 +4856,24 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4856
4856
}
4857
4857
4858
4858
fn check_funding_confirmations(&self, funding: &mut FundingScope, height: u32) -> bool {
4859
- if funding.funding_tx_confirmation_height == 0 && self.minimum_depth != Some(0) {
4859
+ let is_coinbase = funding
4860
+ .funding_transaction
4861
+ .as_ref()
4862
+ .map(|tx| tx.is_coinbase())
4863
+ .unwrap_or(false);
4864
+
4865
+ let minimum_depth = {
4866
+ // If the funding transaction is a coinbase transaction, we need to set the minimum
4867
+ // depth to 100. We can skip this if it is a zero-conf channel.
4868
+ let minimum_depth = self.minimum_depth.unwrap_or(0);
4869
+ if is_coinbase && minimum_depth > 0 && minimum_depth < COINBASE_MATURITY {
4870
+ Some(COINBASE_MATURITY)
4871
+ } else {
4872
+ self.minimum_depth
4873
+ }
4874
+ };
4875
+
4876
+ if funding.funding_tx_confirmation_height == 0 && minimum_depth != Some(0) {
4860
4877
return false;
4861
4878
}
4862
4879
@@ -4865,7 +4882,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4865
4882
funding.funding_tx_confirmation_height = 0;
4866
4883
}
4867
4884
4868
- if funding_tx_confirmations < self. minimum_depth.unwrap_or(0) as i64 {
4885
+ if funding_tx_confirmations < minimum_depth.unwrap_or(0) as i64 {
4869
4886
return false;
4870
4887
}
4871
4888
@@ -8217,20 +8234,20 @@ impl<SP: Deref> FundedChannel<SP> where
8217
8234
}
8218
8235
}
8219
8236
8237
+ // The acceptor of v1-established channels doesn't have the funding
8238
+ // transaction until it is seen on chain. Set it so that minimum_depth
8239
+ // checks can tell if the coinbase transaction was used.
8240
+ if self.funding.funding_transaction.is_none() {
8241
+ self.funding.funding_transaction = Some(tx.clone());
8242
+ }
8243
+
8220
8244
self.funding.funding_tx_confirmation_height = height;
8221
8245
self.funding.funding_tx_confirmed_in = Some(*block_hash);
8222
8246
self.funding.short_channel_id = match scid_from_parts(height as u64, index_in_block as u64, txo_idx as u64) {
8223
8247
Ok(scid) => Some(scid),
8224
8248
Err(_) => panic!("Block was bogus - either height was > 16 million, had > 16 million transactions, or had > 65k outputs"),
8225
8249
}
8226
8250
}
8227
- // If this is a coinbase transaction and not a 0-conf channel
8228
- // we should update our min_depth to 100 to handle coinbase maturity
8229
- if tx.is_coinbase() &&
8230
- self.context.minimum_depth.unwrap_or(0) > 0 &&
8231
- self.context.minimum_depth.unwrap_or(0) < COINBASE_MATURITY {
8232
- self.context.minimum_depth = Some(COINBASE_MATURITY);
8233
- }
8234
8251
}
8235
8252
// If we allow 1-conf funding, we may need to check for channel_ready here and
8236
8253
// send it immediately instead of waiting for a best_block_updated call (which
@@ -9613,14 +9630,6 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
9613
9630
self.context.channel_state = ChannelState::FundingNegotiated;
9614
9631
self.context.channel_id = ChannelId::v1_from_funding_outpoint(funding_txo);
9615
9632
9616
- // If the funding transaction is a coinbase transaction, we need to set the minimum depth to 100.
9617
- // We can skip this if it is a zero-conf channel.
9618
- if funding_transaction.is_coinbase() &&
9619
- self.context.minimum_depth.unwrap_or(0) > 0 &&
9620
- self.context.minimum_depth.unwrap_or(0) < COINBASE_MATURITY {
9621
- self.context.minimum_depth = Some(COINBASE_MATURITY);
9622
- }
9623
-
9624
9633
debug_assert!(self.funding.funding_transaction.is_none());
9625
9634
self.funding.funding_transaction = Some(funding_transaction);
9626
9635
self.context.is_batch_funding = Some(()).filter(|_| is_batch_funding);
0 commit comments