Skip to content

Commit 7c0bf42

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 9b5d5c3 commit 7c0bf42

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
@@ -4851,7 +4851,24 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
48514851
}
48524852

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

@@ -4860,7 +4877,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
48604877
funding.funding_tx_confirmation_height = 0;
48614878
}
48624879

4863-
if funding_tx_confirmations < self.minimum_depth.unwrap_or(0) as i64 {
4880+
if funding_tx_confirmations < minimum_depth.unwrap_or(0) as i64 {
48644881
return false;
48654882
}
48664883

@@ -8212,20 +8229,20 @@ impl<SP: Deref> FundedChannel<SP> where
82128229
}
82138230
}
82148231

8232+
// The acceptor of v1-established channels doesn't have the funding
8233+
// transaction until it is seen on chain. Set it so that minimum_depth
8234+
// checks can tell if the coinbase transaction was used.
8235+
if self.funding.funding_transaction.is_none() {
8236+
self.funding.funding_transaction = Some(tx.clone());
8237+
}
8238+
82158239
self.funding.funding_tx_confirmation_height = height;
82168240
self.funding.funding_tx_confirmed_in = Some(*block_hash);
82178241
self.funding.short_channel_id = match scid_from_parts(height as u64, index_in_block as u64, txo_idx as u64) {
82188242
Ok(scid) => Some(scid),
82198243
Err(_) => panic!("Block was bogus - either height was > 16 million, had > 16 million transactions, or had > 65k outputs"),
82208244
}
82218245
}
8222-
// If this is a coinbase transaction and not a 0-conf channel
8223-
// we should update our min_depth to 100 to handle coinbase maturity
8224-
if tx.is_coinbase() &&
8225-
self.context.minimum_depth.unwrap_or(0) > 0 &&
8226-
self.context.minimum_depth.unwrap_or(0) < COINBASE_MATURITY {
8227-
self.context.minimum_depth = Some(COINBASE_MATURITY);
8228-
}
82298246
}
82308247
// If we allow 1-conf funding, we may need to check for channel_ready here and
82318248
// 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)