Skip to content

Commit 956188b

Browse files
committed
Handle if funding output is in a coinbase transaction
1 parent a332bfc commit 956188b

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
// TODO: We should refactor this to be an Inbound/OutboundChannel until initial setup handshaking
483486
// has been completed, and then turn into a Channel to get compiler-time enforcement of things like
484487
// calling channel_id() before we're set up or things like get_outbound_funding_signed on an
@@ -5142,6 +5145,15 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
51425145
}
51435146
}
51445147
}
5148+
5149+
// if this is a coinbase transaction and not a 0-conf channel
5150+
// we should update our min_depth to 100 to handle coinbase maturity
5151+
if tx.is_coin_base() &&
5152+
self.minimum_depth.unwrap_or(0) > 0 &&
5153+
self.minimum_depth.unwrap_or(0) < COINBASE_MATURITY {
5154+
self.minimum_depth = Some(COINBASE_MATURITY);
5155+
}
5156+
51455157
// If we allow 1-conf funding, we may need to check for channel_ready here and
51465158
// send it immediately instead of waiting for a best_block_updated call (which
51475159
// may have already happened for this block).
@@ -5454,6 +5466,15 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
54545466

54555467
self.channel_state = ChannelState::FundingCreated as u32;
54565468
self.channel_id = funding_txo.to_channel_id();
5469+
5470+
// If the funding transaction is a coinbase transaction, we need to set the minimum depth to 100
5471+
// We can skip this if it is a zero-conf channel.
5472+
if funding_transaction.is_coin_base() &&
5473+
self.minimum_depth.unwrap_or(0) > 0 &&
5474+
self.minimum_depth.unwrap_or(0) < COINBASE_MATURITY {
5475+
self.minimum_depth = Some(COINBASE_MATURITY);
5476+
}
5477+
54575478
self.funding_transaction = Some(funding_transaction);
54585479

54595480
Ok(msgs::FundingCreated {

0 commit comments

Comments
 (0)