Skip to content

Commit c5a477e

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

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

lightning/src/ln/channel.rs

Lines changed: 19 additions & 0 deletions
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+
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
@@ -4964,6 +4967,14 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
49644967
self.funding_tx_confirmation_height = 0;
49654968
}
49664969

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+
49674978
if funding_tx_confirmations < self.minimum_depth.unwrap_or(0) as i64 {
49684979
return None;
49694980
}
@@ -5375,6 +5386,14 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
53755386
self.channel_id = funding_txo.to_channel_id();
53765387
self.funding_transaction = Some(funding_transaction);
53775388

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+
53785397
Ok(msgs::FundingCreated {
53795398
temporary_channel_id,
53805399
funding_txid: funding_txo.txid,

0 commit comments

Comments
 (0)