Skip to content

Commit 2388c87

Browse files
committed
Check FundingScope::funding_transaction for coinbase tx
The minimum_depth of a channel is overridden to COINBASE_MATURITY if the funding transaction is the coinbase transaction. However, if this is to be reused for a splice's minimum_depth, it would be a problem since sending splice_locked would be unnecessarily delayed. Now that FundingScope contains the funding transaction, use this to check if it is a coinbase transaction instead of overriding minimum_depth.
1 parent a64922b commit 2388c87

File tree

1 file changed

+26
-17
lines changed

1 file changed

+26
-17
lines changed

lightning/src/ln/channel.rs

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4856,7 +4856,24 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
48564856
}
48574857

48584858
fn check_funding_confirmations(&self, funding: &mut FundingScope, height: u32) -> bool {
4859-
if funding.funding_tx_confirmation_height == 0 && self.minimum_depth != Some(0) {
4859+
let is_coinbase = funding
4860+
.funding_transaction
4861+
.as_ref()
4862+
.map(|tx| tx.is_coinbase())
4863+
.unwrap_or(false);
4864+
4865+
let minimum_depth = {
4866+
// If the funding transaction is a coinbase transaction, we need to set the minimum
4867+
// depth to 100. We can skip this if it is a zero-conf channel.
4868+
let minimum_depth = self.minimum_depth.unwrap_or(0);
4869+
if is_coinbase && minimum_depth > 0 && minimum_depth < COINBASE_MATURITY {
4870+
Some(COINBASE_MATURITY)
4871+
} else {
4872+
self.minimum_depth
4873+
}
4874+
};
4875+
4876+
if funding.funding_tx_confirmation_height == 0 && minimum_depth != Some(0) {
48604877
return false;
48614878
}
48624879

@@ -4865,7 +4882,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
48654882
funding.funding_tx_confirmation_height = 0;
48664883
}
48674884

4868-
if funding_tx_confirmations < self.minimum_depth.unwrap_or(0) as i64 {
4885+
if funding_tx_confirmations < minimum_depth.unwrap_or(0) as i64 {
48694886
return false;
48704887
}
48714888

@@ -8217,20 +8234,20 @@ impl<SP: Deref> FundedChannel<SP> where
82178234
}
82188235
}
82198236

8237+
// The acceptor of v1-established channels doesn't have the funding
8238+
// transaction until it is seen on chain. Set it so that minimum_depth
8239+
// checks can tell if the coinbase transaction was used.
8240+
if self.funding.funding_transaction.is_none() {
8241+
self.funding.funding_transaction = Some(tx.clone());
8242+
}
8243+
82208244
self.funding.funding_tx_confirmation_height = height;
82218245
self.funding.funding_tx_confirmed_in = Some(*block_hash);
82228246
self.funding.short_channel_id = match scid_from_parts(height as u64, index_in_block as u64, txo_idx as u64) {
82238247
Ok(scid) => Some(scid),
82248248
Err(_) => panic!("Block was bogus - either height was > 16 million, had > 16 million transactions, or had > 65k outputs"),
82258249
}
82268250
}
8227-
// If this is a coinbase transaction and not a 0-conf channel
8228-
// we should update our min_depth to 100 to handle coinbase maturity
8229-
if tx.is_coinbase() &&
8230-
self.context.minimum_depth.unwrap_or(0) > 0 &&
8231-
self.context.minimum_depth.unwrap_or(0) < COINBASE_MATURITY {
8232-
self.context.minimum_depth = Some(COINBASE_MATURITY);
8233-
}
82348251
}
82358252
// If we allow 1-conf funding, we may need to check for channel_ready here and
82368253
// send it immediately instead of waiting for a best_block_updated call (which
@@ -9613,14 +9630,6 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
96139630
self.context.channel_state = ChannelState::FundingNegotiated;
96149631
self.context.channel_id = ChannelId::v1_from_funding_outpoint(funding_txo);
96159632

9616-
// If the funding transaction is a coinbase transaction, we need to set the minimum depth to 100.
9617-
// We can skip this if it is a zero-conf channel.
9618-
if funding_transaction.is_coinbase() &&
9619-
self.context.minimum_depth.unwrap_or(0) > 0 &&
9620-
self.context.minimum_depth.unwrap_or(0) < COINBASE_MATURITY {
9621-
self.context.minimum_depth = Some(COINBASE_MATURITY);
9622-
}
9623-
96249633
debug_assert!(self.funding.funding_transaction.is_none());
96259634
self.funding.funding_transaction = Some(funding_transaction);
96269635
self.context.is_batch_funding = Some(()).filter(|_| is_batch_funding);

0 commit comments

Comments
 (0)