@@ -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,58 +9132,13 @@ 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)]
9127
9140
fn maybe_promote_splice_funding<L: Deref>(
9128
- &mut self, splice_txid: Txid, confirmed_funding_index: usize, logger: &L,
9141
+ &mut self, confirmed_funding_index: usize, logger: &L,
9129
9142
) -> bool
9130
9143
where
9131
9144
L::Target: Logger,
@@ -9134,7 +9147,13 @@ where
9134
9147
debug_assert!(confirmed_funding_index < self.pending_funding.len());
9135
9148
9136
9149
let pending_splice = self.pending_splice.as_mut().unwrap();
9137
- pending_splice.sent_funding_txid = Some(splice_txid);
9150
+ let splice_txid = match pending_splice.sent_funding_txid {
9151
+ Some(sent_funding_txid) => sent_funding_txid,
9152
+ None => {
9153
+ debug_assert!(false);
9154
+ return false;
9155
+ },
9156
+ };
9138
9157
9139
9158
if pending_splice.sent_funding_txid == pending_splice.received_funding_txid {
9140
9159
log_info!(
@@ -9145,6 +9164,7 @@ where
9145
9164
);
9146
9165
9147
9166
let funding = self.pending_funding.get_mut(confirmed_funding_index).unwrap();
9167
+ debug_assert_eq!(Some(splice_txid), funding.get_funding_txid());
9148
9168
promote_splice_funding!(self, funding);
9149
9169
9150
9170
return true;
@@ -9234,7 +9254,7 @@ where
9234
9254
9235
9255
#[cfg(splicing)]
9236
9256
if let Some(confirmed_funding_index) = confirmed_funding_index {
9237
- let pending_splice = match self.pending_splice.as_ref () {
9257
+ let pending_splice = match self.pending_splice.as_mut () {
9238
9258
Some(pending_splice) => pending_splice,
9239
9259
None => {
9240
9260
// TODO: Move pending_funding into pending_splice
@@ -9245,7 +9265,7 @@ where
9245
9265
};
9246
9266
let funding = self.pending_funding.get(confirmed_funding_index).unwrap();
9247
9267
9248
- 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) {
9249
9269
for &(idx, tx) in txdata.iter() {
9250
9270
if idx > index_in_block {
9251
9271
self.context.check_for_funding_tx_spent(funding, tx, logger)?;
@@ -9260,7 +9280,7 @@ where
9260
9280
);
9261
9281
9262
9282
let announcement_sigs = self
9263
- .maybe_promote_splice_funding(splice_locked.splice_txid, confirmed_funding_index, logger)
9283
+ .maybe_promote_splice_funding(confirmed_funding_index, logger)
9264
9284
.then(|| self.get_announcement_sigs(node_signer, chain_hash, user_config, height, logger))
9265
9285
.flatten();
9266
9286
@@ -9417,13 +9437,13 @@ where
9417
9437
}
9418
9438
}
9419
9439
9420
- let pending_splice = self.pending_splice.as_ref ().unwrap();
9440
+ let pending_splice = self.pending_splice.as_mut ().unwrap();
9421
9441
let funding = self.pending_funding.get(confirmed_funding_index).unwrap();
9422
- if let Some(splice_locked) = self .check_get_splice_locked(pending_splice , funding, height) {
9442
+ if let Some(splice_locked) = pending_splice .check_get_splice_locked(&self.context , funding, height) {
9423
9443
log_info!(logger, "Sending a splice_locked to our peer for channel {}", &self.context.channel_id);
9424
9444
9425
9445
let announcement_sigs = self
9426
- .maybe_promote_splice_funding(splice_locked.splice_txid, confirmed_funding_index, logger)
9446
+ .maybe_promote_splice_funding(confirmed_funding_index, logger)
9427
9447
.then(|| chain_node_signer
9428
9448
.and_then(|(chain_hash, node_signer, user_config)|
9429
9449
self.get_announcement_sigs(node_signer, chain_hash, user_config, height, logger)
0 commit comments