@@ -478,6 +478,9 @@ pub(crate) const MIN_AFFORDABLE_HTLC_COUNT: usize = 4;
478
478
/// * `EXPIRE_PREV_CONFIG_TICKS` = convergence_delay / tick_interval
479
479
pub ( crate ) const EXPIRE_PREV_CONFIG_TICKS : usize = 5 ;
480
480
481
+ /// Number of blocks needed for an output from a coinbase transaction to be spendable.
482
+ const COINBASE_MATURITY : u32 = 100 ;
483
+
481
484
// TODO: We should refactor this to be an Inbound/OutboundChannel until initial setup handshaking
482
485
// has been completed, and then turn into a Channel to get compiler-time enforcement of things like
483
486
// calling channel_id() before we're set up or things like get_outbound_funding_signed on an
@@ -4964,6 +4967,14 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
4964
4967
self . funding_tx_confirmation_height = 0 ;
4965
4968
}
4966
4969
4970
+ // If funding transaction is coinbase, we need to wait for 100 blocks before
4971
+ // it is spendable. However, we can ignore this rule if the channel is 0-conf.
4972
+ if self . funding_transaction . as_ref ( ) . map ( |t| t. is_coin_base ( ) ) . unwrap_or ( false ) &&
4973
+ funding_tx_confirmations <= COINBASE_MATURITY as i64 &&
4974
+ self . minimum_depth . unwrap_or ( 0 ) > 0 {
4975
+ return None ;
4976
+ }
4977
+
4967
4978
if funding_tx_confirmations < self . minimum_depth . unwrap_or ( 0 ) as i64 {
4968
4979
return None ;
4969
4980
}
@@ -5375,6 +5386,14 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
5375
5386
self . channel_id = funding_txo. to_channel_id ( ) ;
5376
5387
self . funding_transaction = Some ( funding_transaction) ;
5377
5388
5389
+ // If the funding transaction is a coinbase transaction, we need to set the minimum depth to 100
5390
+ // We can skip this if it is a zero-conf channel.
5391
+ if funding_transaction. is_coin_base ( ) &&
5392
+ self . minimum_depth . unwrap_or ( 0 ) > 0 &&
5393
+ self . minimum_depth . unwrap_or ( 0 ) < COINBASE_MATURITY {
5394
+ self . minimum_depth = Some ( COINBASE_MATURITY ) ;
5395
+ }
5396
+
5378
5397
Ok ( msgs:: FundingCreated {
5379
5398
temporary_channel_id,
5380
5399
funding_txid : funding_txo. txid ,
0 commit comments