Skip to content

Commit 451c60e

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 f1f5f1b commit 451c60e

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
@@ -4975,6 +4975,14 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
49754975
}
49764976

49774977
fn check_funding_meets_minimum_depth(&self, funding: &FundingScope, height: u32) -> bool {
4978+
let minimum_depth = self.minimum_depth
4979+
.expect("ChannelContext::minimum_depth should be set for FundedChannel");
4980+
4981+
// Zero-conf channels always meet the minimum depth.
4982+
if minimum_depth == 0 {
4983+
return true;
4984+
}
4985+
49784986
let is_coinbase = funding
49794987
.funding_transaction
49804988
.as_ref()
@@ -4983,21 +4991,20 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
49834991

49844992
let minimum_depth = {
49854993
// If the funding transaction is a coinbase transaction, we need to set the minimum
4986-
// depth to 100. We can skip this if it is a zero-conf channel.
4987-
let minimum_depth = self.minimum_depth.unwrap_or(0);
4988-
if is_coinbase && minimum_depth > 0 && minimum_depth < COINBASE_MATURITY {
4989-
Some(COINBASE_MATURITY)
4994+
// depth to 100.
4995+
if is_coinbase && minimum_depth < COINBASE_MATURITY {
4996+
COINBASE_MATURITY
49904997
} else {
4991-
self.minimum_depth
4998+
minimum_depth
49924999
}
49935000
};
49945001

4995-
if funding.funding_tx_confirmation_height == 0 && minimum_depth != Some(0) {
5002+
if funding.funding_tx_confirmation_height == 0 {
49965003
return false;
49975004
}
49985005

49995006
let funding_tx_confirmations = height as i64 - funding.funding_tx_confirmation_height as i64 + 1;
5000-
if funding_tx_confirmations < minimum_depth.unwrap_or(0) as i64 {
5007+
if funding_tx_confirmations < minimum_depth as i64 {
50015008
return false;
50025009
}
50035010

0 commit comments

Comments
 (0)