@@ -2156,6 +2156,41 @@ struct PendingSplice {
21562156 received_funding_txid: Option<Txid>,
21572157}
21582158
2159+ #[cfg(splicing)]
2160+ impl PendingSplice {
2161+ fn check_get_splice_locked<SP: Deref>(
2162+ &mut self, context: &ChannelContext<SP>, funding: &FundingScope, height: u32,
2163+ ) -> Option<msgs::SpliceLocked>
2164+ where
2165+ SP::Target: SignerProvider,
2166+ {
2167+ if !context.check_funding_meets_minimum_depth(funding, height) {
2168+ return None;
2169+ }
2170+
2171+ let confirmed_funding_txid = match funding.get_funding_txid() {
2172+ Some(funding_txid) => funding_txid,
2173+ None => {
2174+ debug_assert!(false);
2175+ return None;
2176+ },
2177+ };
2178+
2179+ match self.sent_funding_txid {
2180+ Some(sent_funding_txid) if confirmed_funding_txid == sent_funding_txid => None,
2181+ _ => {
2182+ let splice_locked = msgs::SpliceLocked {
2183+ channel_id: context.channel_id(),
2184+ splice_txid: confirmed_funding_txid,
2185+ };
2186+ self.sent_funding_txid = Some(splice_locked.splice_txid);
2187+ Some(splice_locked)
2188+ },
2189+ }
2190+ }
2191+
2192+ }
2193+
21592194/// Wrapper around a [`Transaction`] useful for caching the result of [`Transaction::compute_txid`].
21602195struct ConfirmedTransaction<'a> {
21612196 tx: &'a Transaction,
@@ -5525,6 +5560,29 @@ where
55255560 self.get_initial_counterparty_commitment_signature(funding, logger)
55265561 }
55275562
5563+ fn check_funding_meets_minimum_depth(&self, funding: &FundingScope, height: u32) -> bool {
5564+ let minimum_depth = self
5565+ .minimum_depth(funding)
5566+ .expect("ChannelContext::minimum_depth should be set for FundedChannel");
5567+
5568+ // Zero-conf channels always meet the minimum depth.
5569+ if minimum_depth == 0 {
5570+ return true;
5571+ }
5572+
5573+ if funding.funding_tx_confirmation_height == 0 {
5574+ return false;
5575+ }
5576+
5577+ let funding_tx_confirmations =
5578+ height as i64 - funding.funding_tx_confirmation_height as i64 + 1;
5579+ if funding_tx_confirmations < minimum_depth as i64 {
5580+ return false;
5581+ }
5582+
5583+ return true;
5584+ }
5585+
55285586 #[rustfmt::skip]
55295587 fn check_for_funding_tx_confirmed<L: Deref>(
55305588 &mut self, funding: &mut FundingScope, block_hash: &BlockHash, height: u32,
@@ -9074,53 +9132,8 @@ where
90749132 }
90759133 }
90769134
9077- #[cfg(splicing)]
9078- fn check_get_splice_locked(
9079- &self, pending_splice: &PendingSplice, funding: &FundingScope, height: u32,
9080- ) -> Option<msgs::SpliceLocked> {
9081- if !self.check_funding_meets_minimum_depth(funding, height) {
9082- return None;
9083- }
9084-
9085- let confirmed_funding_txid = match funding.get_funding_txid() {
9086- Some(funding_txid) => funding_txid,
9087- None => {
9088- debug_assert!(false);
9089- return None;
9090- },
9091- };
9092-
9093- match pending_splice.sent_funding_txid {
9094- Some(sent_funding_txid) if confirmed_funding_txid == sent_funding_txid => None,
9095- _ => Some(msgs::SpliceLocked {
9096- channel_id: self.context.channel_id(),
9097- splice_txid: confirmed_funding_txid,
9098- }),
9099- }
9100- }
9101-
91029135 fn check_funding_meets_minimum_depth(&self, funding: &FundingScope, height: u32) -> bool {
9103- let minimum_depth = self
9104- .context
9105- .minimum_depth(funding)
9106- .expect("ChannelContext::minimum_depth should be set for FundedChannel");
9107-
9108- // Zero-conf channels always meet the minimum depth.
9109- if minimum_depth == 0 {
9110- return true;
9111- }
9112-
9113- if funding.funding_tx_confirmation_height == 0 {
9114- return false;
9115- }
9116-
9117- let funding_tx_confirmations =
9118- height as i64 - funding.funding_tx_confirmation_height as i64 + 1;
9119- if funding_tx_confirmations < minimum_depth as i64 {
9120- return false;
9121- }
9122-
9123- return true;
9136+ self.context.check_funding_meets_minimum_depth(funding, height)
91249137 }
91259138
91269139 #[cfg(splicing)]
@@ -9232,7 +9245,7 @@ where
92329245
92339246 #[cfg(splicing)]
92349247 if let Some(confirmed_funding_index) = confirmed_funding_index {
9235- let pending_splice = match self.pending_splice.as_ref () {
9248+ let pending_splice = match self.pending_splice.as_mut () {
92369249 Some(pending_splice) => pending_splice,
92379250 None => {
92389251 // TODO: Move pending_funding into pending_splice
@@ -9243,16 +9256,13 @@ where
92439256 };
92449257 let funding = self.pending_funding.get(confirmed_funding_index).unwrap();
92459258
9246- if let Some(splice_locked) = self .check_get_splice_locked(pending_splice , funding, height) {
9259+ if let Some(splice_locked) = pending_splice .check_get_splice_locked(&self.context , funding, height) {
92479260 for &(idx, tx) in txdata.iter() {
92489261 if idx > index_in_block {
92499262 self.context.check_for_funding_tx_spent(funding, tx, logger)?;
92509263 }
92519264 }
92529265
9253- let pending_splice = self.pending_splice.as_mut().unwrap();
9254- pending_splice.sent_funding_txid = Some(splice_locked.splice_txid);
9255-
92569266 log_info!(
92579267 logger,
92589268 "Sending splice_locked txid {} to our peer for channel {}",
@@ -9418,12 +9428,9 @@ where
94189428 }
94199429 }
94209430
9421- let pending_splice = self.pending_splice.as_ref ().unwrap();
9431+ let pending_splice = self.pending_splice.as_mut ().unwrap();
94229432 let funding = self.pending_funding.get(confirmed_funding_index).unwrap();
9423- if let Some(splice_locked) = self.check_get_splice_locked(pending_splice, funding, height) {
9424- let pending_splice = self.pending_splice.as_mut().unwrap();
9425- pending_splice.sent_funding_txid = Some(splice_locked.splice_txid);
9426-
9433+ if let Some(splice_locked) = pending_splice.check_get_splice_locked(&self.context, funding, height) {
94279434 log_info!(logger, "Sending a splice_locked to our peer for channel {}", &self.context.channel_id);
94289435
94299436 let announcement_sigs = self
0 commit comments