Skip to content

Commit 035b8e4

Browse files
committed
Handle if funding output is in a coinbase transaction
1 parent d7f6e34 commit 035b8e4

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

lightning/src/ln/channel.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,9 @@ pub(crate) const MIN_AFFORDABLE_HTLC_COUNT: usize = 4;
479479
/// * `EXPIRE_PREV_CONFIG_TICKS` = convergence_delay / tick_interval
480480
pub(crate) const EXPIRE_PREV_CONFIG_TICKS: usize = 5;
481481

482+
/// Number of blocks needed for an output from a coinbase transaction to be spendable.
483+
pub(crate) const COINBASE_MATURITY: u32 = 100;
484+
482485
struct PendingChannelMonitorUpdate {
483486
update: ChannelMonitorUpdate,
484487
/// In some cases we need to delay letting the [`ChannelMonitorUpdate`] go until after an
@@ -5235,6 +5238,15 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
52355238
}
52365239
}
52375240
}
5241+
5242+
// if this is a coinbase transaction and not a 0-conf channel
5243+
// we should update our min_depth to 100 to handle coinbase maturity
5244+
if tx.is_coin_base() &&
5245+
self.minimum_depth.unwrap_or(0) > 0 &&
5246+
self.minimum_depth.unwrap_or(0) < COINBASE_MATURITY {
5247+
self.minimum_depth = Some(COINBASE_MATURITY);
5248+
}
5249+
52385250
// If we allow 1-conf funding, we may need to check for channel_ready here and
52395251
// send it immediately instead of waiting for a best_block_updated call (which
52405252
// may have already happened for this block).
@@ -5547,6 +5559,15 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
55475559

55485560
self.channel_state = ChannelState::FundingCreated as u32;
55495561
self.channel_id = funding_txo.to_channel_id();
5562+
5563+
// If the funding transaction is a coinbase transaction, we need to set the minimum depth to 100
5564+
// We can skip this if it is a zero-conf channel.
5565+
if funding_transaction.is_coin_base() &&
5566+
self.minimum_depth.unwrap_or(0) > 0 &&
5567+
self.minimum_depth.unwrap_or(0) < COINBASE_MATURITY {
5568+
self.minimum_depth = Some(COINBASE_MATURITY);
5569+
}
5570+
55505571
self.funding_transaction = Some(funding_transaction);
55515572

55525573
Ok(msgs::FundingCreated {

0 commit comments

Comments
 (0)