@@ -4851,7 +4851,24 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4851
4851
}
4852
4852
4853
4853
fn check_funding_confirmations(&self, funding: &mut FundingScope, height: u32) -> bool {
4854
- if funding.funding_tx_confirmation_height == 0 && self.minimum_depth != Some(0) {
4854
+ let is_coinbase = funding
4855
+ .funding_transaction
4856
+ .as_ref()
4857
+ .map(|tx| tx.is_coinbase())
4858
+ .unwrap_or(false);
4859
+
4860
+ let minimum_depth = {
4861
+ // If the funding transaction is a coinbase transaction, we need to set the minimum
4862
+ // depth to 100. We can skip this if it is a zero-conf channel.
4863
+ let minimum_depth = self.minimum_depth.unwrap_or(0);
4864
+ if is_coinbase && minimum_depth > 0 && minimum_depth < COINBASE_MATURITY {
4865
+ Some(COINBASE_MATURITY)
4866
+ } else {
4867
+ self.minimum_depth
4868
+ }
4869
+ };
4870
+
4871
+ if funding.funding_tx_confirmation_height == 0 && minimum_depth != Some(0) {
4855
4872
return false;
4856
4873
}
4857
4874
@@ -4860,7 +4877,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4860
4877
funding.funding_tx_confirmation_height = 0;
4861
4878
}
4862
4879
4863
- if funding_tx_confirmations < self. minimum_depth.unwrap_or(0) as i64 {
4880
+ if funding_tx_confirmations < minimum_depth.unwrap_or(0) as i64 {
4864
4881
return false;
4865
4882
}
4866
4883
@@ -8212,20 +8229,20 @@ impl<SP: Deref> FundedChannel<SP> where
8212
8229
}
8213
8230
}
8214
8231
8232
+ // The acceptor of v1-established channels doesn't have the funding
8233
+ // transaction until it is seen on chain. Set it so that minimum_depth
8234
+ // checks can tell if the coinbase transaction was used.
8235
+ if self.funding.funding_transaction.is_none() {
8236
+ self.funding.funding_transaction = Some(tx.clone());
8237
+ }
8238
+
8215
8239
self.funding.funding_tx_confirmation_height = height;
8216
8240
self.funding.funding_tx_confirmed_in = Some(*block_hash);
8217
8241
self.funding.short_channel_id = match scid_from_parts(height as u64, index_in_block as u64, txo_idx as u64) {
8218
8242
Ok(scid) => Some(scid),
8219
8243
Err(_) => panic!("Block was bogus - either height was > 16 million, had > 16 million transactions, or had > 65k outputs"),
8220
8244
}
8221
8245
}
8222
- // If this is a coinbase transaction and not a 0-conf channel
8223
- // we should update our min_depth to 100 to handle coinbase maturity
8224
- if tx.is_coinbase() &&
8225
- self.context.minimum_depth.unwrap_or(0) > 0 &&
8226
- self.context.minimum_depth.unwrap_or(0) < COINBASE_MATURITY {
8227
- self.context.minimum_depth = Some(COINBASE_MATURITY);
8228
- }
8229
8246
}
8230
8247
// If we allow 1-conf funding, we may need to check for channel_ready here and
8231
8248
// 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