Skip to content

Commit 80c8f6e

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 dd0164a commit 80c8f6e

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
@@ -5005,7 +5005,24 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
50055005
}
50065006

50075007
fn check_funding_meets_minimum_depth(&self, funding: &mut FundingScope, height: u32) -> bool {
5008-
if funding.funding_tx_confirmation_height == 0 && self.minimum_depth != Some(0) {
5008+
let is_coinbase = funding
5009+
.funding_transaction
5010+
.as_ref()
5011+
.map(|tx| tx.is_coinbase())
5012+
.unwrap_or(false);
5013+
5014+
let minimum_depth = {
5015+
// If the funding transaction is a coinbase transaction, we need to set the minimum
5016+
// depth to 100. We can skip this if it is a zero-conf channel.
5017+
let minimum_depth = self.minimum_depth.unwrap_or(0);
5018+
if is_coinbase && minimum_depth > 0 && minimum_depth < COINBASE_MATURITY {
5019+
Some(COINBASE_MATURITY)
5020+
} else {
5021+
self.minimum_depth
5022+
}
5023+
};
5024+
5025+
if funding.funding_tx_confirmation_height == 0 && minimum_depth != Some(0) {
50095026
return false;
50105027
}
50115028

@@ -5014,7 +5031,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
50145031
funding.funding_tx_confirmation_height = 0;
50155032
}
50165033

5017-
if funding_tx_confirmations < self.minimum_depth.unwrap_or(0) as i64 {
5034+
if funding_tx_confirmations < minimum_depth.unwrap_or(0) as i64 {
50185035
return false;
50195036
}
50205037

@@ -8473,20 +8490,20 @@ impl<SP: Deref> FundedChannel<SP> where
84738490
}
84748491
}
84758492

8493+
// The acceptor of v1-established channels doesn't have the funding
8494+
// transaction until it is seen on chain. Set it so that minimum_depth
8495+
// checks can tell if the coinbase transaction was used.
8496+
if self.funding.funding_transaction.is_none() {
8497+
self.funding.funding_transaction = Some(tx.clone());
8498+
}
8499+
84768500
self.funding.funding_tx_confirmation_height = height;
84778501
self.funding.funding_tx_confirmed_in = Some(*block_hash);
84788502
self.funding.short_channel_id = match scid_from_parts(height as u64, index_in_block as u64, txo_idx as u64) {
84798503
Ok(scid) => Some(scid),
84808504
Err(_) => panic!("Block was bogus - either height was > 16 million, had > 16 million transactions, or had > 65k outputs"),
84818505
}
84828506
}
8483-
// If this is a coinbase transaction and not a 0-conf channel
8484-
// we should update our min_depth to 100 to handle coinbase maturity
8485-
if tx.is_coinbase() &&
8486-
self.context.minimum_depth.unwrap_or(0) > 0 &&
8487-
self.context.minimum_depth.unwrap_or(0) < COINBASE_MATURITY {
8488-
self.context.minimum_depth = Some(COINBASE_MATURITY);
8489-
}
84908507
}
84918508
// If we allow 1-conf funding, we may need to check for channel_ready here and
84928509
// send it immediately instead of waiting for a best_block_updated call (which
@@ -9894,14 +9911,6 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
98949911
self.context.channel_state = ChannelState::FundingNegotiated(FundingNegotiatedFlags::new());
98959912
self.context.channel_id = ChannelId::v1_from_funding_outpoint(funding_txo);
98969913

9897-
// If the funding transaction is a coinbase transaction, we need to set the minimum depth to 100.
9898-
// We can skip this if it is a zero-conf channel.
9899-
if funding_transaction.is_coinbase() &&
9900-
self.context.minimum_depth.unwrap_or(0) > 0 &&
9901-
self.context.minimum_depth.unwrap_or(0) < COINBASE_MATURITY {
9902-
self.context.minimum_depth = Some(COINBASE_MATURITY);
9903-
}
9904-
99059914
debug_assert!(self.funding.funding_transaction.is_none());
99069915
self.funding.funding_transaction = Some(funding_transaction);
99079916
self.context.is_batch_funding = Some(()).filter(|_| is_batch_funding);

0 commit comments

Comments
 (0)