@@ -2156,6 +2156,41 @@ struct PendingSplice {
2156
2156
received_funding_txid: Option<Txid>,
2157
2157
}
2158
2158
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
+
2159
2194
/// Wrapper around a [`Transaction`] useful for caching the result of [`Transaction::compute_txid`].
2160
2195
struct ConfirmedTransaction<'a> {
2161
2196
tx: &'a Transaction,
@@ -5525,6 +5560,29 @@ where
5525
5560
self.get_initial_counterparty_commitment_signature(funding, logger)
5526
5561
}
5527
5562
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
+
5528
5586
#[rustfmt::skip]
5529
5587
fn check_for_funding_tx_confirmed<L: Deref>(
5530
5588
&mut self, funding: &mut FundingScope, block_hash: &BlockHash, height: u32,
@@ -9074,53 +9132,8 @@ where
9074
9132
}
9075
9133
}
9076
9134
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
-
9102
9135
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)
9124
9137
}
9125
9138
9126
9139
#[cfg(splicing)]
@@ -9241,7 +9254,7 @@ where
9241
9254
9242
9255
#[cfg(splicing)]
9243
9256
if let Some(confirmed_funding_index) = confirmed_funding_index {
9244
- let pending_splice = match self.pending_splice.as_ref () {
9257
+ let pending_splice = match self.pending_splice.as_mut () {
9245
9258
Some(pending_splice) => pending_splice,
9246
9259
None => {
9247
9260
// TODO: Move pending_funding into pending_splice
@@ -9252,16 +9265,13 @@ where
9252
9265
};
9253
9266
let funding = self.pending_funding.get(confirmed_funding_index).unwrap();
9254
9267
9255
- if let Some(splice_locked) = self .check_get_splice_locked(pending_splice , funding, height) {
9268
+ if let Some(splice_locked) = pending_splice .check_get_splice_locked(&self.context , funding, height) {
9256
9269
for &(idx, tx) in txdata.iter() {
9257
9270
if idx > index_in_block {
9258
9271
self.context.check_for_funding_tx_spent(funding, tx, logger)?;
9259
9272
}
9260
9273
}
9261
9274
9262
- let pending_splice = self.pending_splice.as_mut().unwrap();
9263
- pending_splice.sent_funding_txid = Some(splice_locked.splice_txid);
9264
-
9265
9275
log_info!(
9266
9276
logger,
9267
9277
"Sending splice_locked txid {} to our peer for channel {}",
@@ -9427,12 +9437,9 @@ where
9427
9437
}
9428
9438
}
9429
9439
9430
- let pending_splice = self.pending_splice.as_ref ().unwrap();
9440
+ let pending_splice = self.pending_splice.as_mut ().unwrap();
9431
9441
let funding = self.pending_funding.get(confirmed_funding_index).unwrap();
9432
- if let Some(splice_locked) = self.check_get_splice_locked(pending_splice, funding, height) {
9433
- let pending_splice = self.pending_splice.as_mut().unwrap();
9434
- pending_splice.sent_funding_txid = Some(splice_locked.splice_txid);
9435
-
9442
+ if let Some(splice_locked) = pending_splice.check_get_splice_locked(&self.context, funding, height) {
9436
9443
log_info!(logger, "Sending a splice_locked to our peer for channel {}", &self.context.channel_id);
9437
9444
9438
9445
let announcement_sigs = self
0 commit comments