Skip to content

Commit 21adde1

Browse files
committed
Special case 0-conf in check_funding_meets_minimum_depth
0-conf channels always meet the funding minimum depth once accepted. Special case this in check_funding_meets_minimum_depth such that it isn't implicit in later calculations. Since a minimum depth is always set when the channel is accepted, expect this to be the case in the method since it should only be called on a ChannelContext in a FundedChannel.
1 parent ad694a8 commit 21adde1

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

lightning/src/ln/channel.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5010,6 +5010,14 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
50105010
}
50115011

50125012
fn check_funding_meets_minimum_depth(&self, funding: &FundingScope, height: u32) -> bool {
5013+
let minimum_depth = self.minimum_depth
5014+
.expect("ChannelContext::minimum_depth should be set for FundedChannel");
5015+
5016+
// Zero-conf channels always meet the minimum depth.
5017+
if minimum_depth == 0 {
5018+
return true;
5019+
}
5020+
50135021
let is_coinbase = funding
50145022
.funding_transaction
50155023
.as_ref()
@@ -5018,21 +5026,20 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
50185026

50195027
let minimum_depth = {
50205028
// If the funding transaction is a coinbase transaction, we need to set the minimum
5021-
// depth to 100. We can skip this if it is a zero-conf channel.
5022-
let minimum_depth = self.minimum_depth.unwrap_or(0);
5023-
if is_coinbase && minimum_depth > 0 && minimum_depth < COINBASE_MATURITY {
5024-
Some(COINBASE_MATURITY)
5029+
// depth to 100.
5030+
if is_coinbase && minimum_depth < COINBASE_MATURITY {
5031+
COINBASE_MATURITY
50255032
} else {
5026-
self.minimum_depth
5033+
minimum_depth
50275034
}
50285035
};
50295036

5030-
if funding.funding_tx_confirmation_height == 0 && minimum_depth != Some(0) {
5037+
if funding.funding_tx_confirmation_height == 0 {
50315038
return false;
50325039
}
50335040

50345041
let funding_tx_confirmations = height as i64 - funding.funding_tx_confirmation_height as i64 + 1;
5035-
if funding_tx_confirmations < minimum_depth.unwrap_or(0) as i64 {
5042+
if funding_tx_confirmations < minimum_depth as i64 {
50365043
return false;
50375044
}
50385045

0 commit comments

Comments
 (0)