Skip to content

Commit 8739bd4

Browse files
committed
Move check_funding_meets_minimum_depth to FundedChannel
This method is only applicable for FundedChannel, so it shouldn't be accessible from ChannelContext.
1 parent a61f1d3 commit 8739bd4

File tree

1 file changed

+39
-39
lines changed

1 file changed

+39
-39
lines changed

lightning/src/ln/channel.rs

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5039,43 +5039,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
50395039
self.get_initial_counterparty_commitment_signature(funding, logger)
50405040
}
50415041

5042-
fn check_funding_meets_minimum_depth(&self, funding: &FundingScope, height: u32) -> bool {
5043-
let minimum_depth = self.minimum_depth
5044-
.expect("ChannelContext::minimum_depth should be set for FundedChannel");
5045-
5046-
// Zero-conf channels always meet the minimum depth.
5047-
if minimum_depth == 0 {
5048-
return true;
5049-
}
5050-
5051-
let is_coinbase = funding
5052-
.funding_transaction
5053-
.as_ref()
5054-
.map(|tx| tx.is_coinbase())
5055-
.unwrap_or(false);
5056-
5057-
let minimum_depth = {
5058-
// If the funding transaction is a coinbase transaction, we need to set the minimum
5059-
// depth to 100.
5060-
if is_coinbase && minimum_depth < COINBASE_MATURITY {
5061-
COINBASE_MATURITY
5062-
} else {
5063-
minimum_depth
5064-
}
5065-
};
5066-
5067-
if funding.funding_tx_confirmation_height == 0 {
5068-
return false;
5069-
}
5070-
5071-
let funding_tx_confirmations = height as i64 - funding.funding_tx_confirmation_height as i64 + 1;
5072-
if funding_tx_confirmations < minimum_depth as i64 {
5073-
return false;
5074-
}
5075-
5076-
return true;
5077-
}
5078-
50795042
fn check_for_funding_tx_confirmed(
50805043
&mut self, funding: &mut FundingScope, block_hash: &BlockHash, height: u32,
50815044
index_in_block: usize, tx: &mut ConfirmedTransaction,
@@ -8518,7 +8481,7 @@ impl<SP: Deref> FundedChannel<SP> where
85188481
// Called:
85198482
// * always when a new block/transactions are confirmed with the new height
85208483
// * when funding is signed with a height of 0
8521-
if !self.context.check_funding_meets_minimum_depth(&self.funding, height) {
8484+
if !self.check_funding_meets_minimum_depth(&self.funding, height) {
85228485
return None;
85238486
}
85248487

@@ -8591,7 +8554,7 @@ impl<SP: Deref> FundedChannel<SP> where
85918554
fn check_get_splice_locked(
85928555
&self, pending_splice: &PendingSplice, funding: &FundingScope, height: u32,
85938556
) -> Option<msgs::SpliceLocked> {
8594-
if !self.context.check_funding_meets_minimum_depth(funding, height) {
8557+
if !self.check_funding_meets_minimum_depth(funding, height) {
85958558
return None;
85968559
}
85978560

@@ -8614,6 +8577,43 @@ impl<SP: Deref> FundedChannel<SP> where
86148577
}
86158578
}
86168579

8580+
fn check_funding_meets_minimum_depth(&self, funding: &FundingScope, height: u32) -> bool {
8581+
let minimum_depth = self.context.minimum_depth
8582+
.expect("ChannelContext::minimum_depth should be set for FundedChannel");
8583+
8584+
// Zero-conf channels always meet the minimum depth.
8585+
if minimum_depth == 0 {
8586+
return true;
8587+
}
8588+
8589+
let is_coinbase = funding
8590+
.funding_transaction
8591+
.as_ref()
8592+
.map(|tx| tx.is_coinbase())
8593+
.unwrap_or(false);
8594+
8595+
let minimum_depth = {
8596+
// If the funding transaction is a coinbase transaction, we need to set the minimum
8597+
// depth to 100.
8598+
if is_coinbase && minimum_depth < COINBASE_MATURITY {
8599+
COINBASE_MATURITY
8600+
} else {
8601+
minimum_depth
8602+
}
8603+
};
8604+
8605+
if funding.funding_tx_confirmation_height == 0 {
8606+
return false;
8607+
}
8608+
8609+
let funding_tx_confirmations = height as i64 - funding.funding_tx_confirmation_height as i64 + 1;
8610+
if funding_tx_confirmations < minimum_depth as i64 {
8611+
return false;
8612+
}
8613+
8614+
return true;
8615+
}
8616+
86178617
#[cfg(splicing)]
86188618
fn maybe_promote_splice_funding(
86198619
&mut self, splice_txid: Txid, confirmed_funding_index: usize,

0 commit comments

Comments
 (0)