Skip to content

Commit 3b06a34

Browse files
committed
Handle if funding output is in a coinbase transaction
1 parent b5e5435 commit 3b06a34

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

lightning/src/ln/channel.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,9 @@ pub(crate) const MIN_AFFORDABLE_HTLC_COUNT: usize = 4;
478478
/// * `EXPIRE_PREV_CONFIG_TICKS` = convergence_delay / tick_interval
479479
pub(crate) const EXPIRE_PREV_CONFIG_TICKS: usize = 5;
480480

481+
/// Number of blocks needed for an output from a coinbase transaction to be spendable.
482+
pub(crate) const COINBASE_MATURITY: u32 = 100;
483+
481484
// TODO: We should refactor this to be an Inbound/OutboundChannel until initial setup handshaking
482485
// has been completed, and then turn into a Channel to get compiler-time enforcement of things like
483486
// calling channel_id() before we're set up or things like get_outbound_funding_signed on an
@@ -5373,7 +5376,15 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
53735376

53745377
self.channel_state = ChannelState::FundingCreated as u32;
53755378
self.channel_id = funding_txo.to_channel_id();
5376-
self.funding_transaction = Some(funding_transaction);
5379+
self.funding_transaction = Some(funding_transaction.clone());
5380+
5381+
// If the funding transaction is a coinbase transaction, we need to set the minimum depth to 100
5382+
// We can skip this if it is a zero-conf channel.
5383+
if funding_transaction.is_coin_base() &&
5384+
self.minimum_depth.unwrap_or(0) > 0 &&
5385+
self.minimum_depth.unwrap_or(0) < COINBASE_MATURITY {
5386+
self.minimum_depth = Some(COINBASE_MATURITY);
5387+
}
53775388

53785389
Ok(msgs::FundingCreated {
53795390
temporary_channel_id,

0 commit comments

Comments
 (0)