@@ -1424,7 +1424,7 @@ pub(crate) const COINBASE_MATURITY: u32 = 100;
1424
1424
/// The number of blocks to wait for a channel_announcement to propagate such that payments using an
1425
1425
/// older SCID can still be relayed. Once the spend of the previous funding transaction has reached
1426
1426
/// this number of confirmations, the corresponding SCID will be forgotten.
1427
- const CHANNEL_ANNOUNCEMENT_PROPAGATION_DELAY: u32 = 12 ;
1427
+ const CHANNEL_ANNOUNCEMENT_PROPAGATION_DELAY: u32 = 144 ;
1428
1428
1429
1429
struct PendingChannelMonitorUpdate {
1430
1430
update: ChannelMonitorUpdate,
@@ -2156,6 +2156,40 @@ 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
+
2159
2193
/// Wrapper around a [`Transaction`] useful for caching the result of [`Transaction::compute_txid`].
2160
2194
struct ConfirmedTransaction<'a> {
2161
2195
tx: &'a Transaction,
@@ -5551,6 +5585,29 @@ where
5551
5585
self.get_initial_counterparty_commitment_signature(funding, logger)
5552
5586
}
5553
5587
5588
+ fn check_funding_meets_minimum_depth(&self, funding: &FundingScope, height: u32) -> bool {
5589
+ let minimum_depth = self
5590
+ .minimum_depth(funding)
5591
+ .expect("ChannelContext::minimum_depth should be set for FundedChannel");
5592
+
5593
+ // Zero-conf channels always meet the minimum depth.
5594
+ if minimum_depth == 0 {
5595
+ return true;
5596
+ }
5597
+
5598
+ if funding.funding_tx_confirmation_height == 0 {
5599
+ return false;
5600
+ }
5601
+
5602
+ let funding_tx_confirmations =
5603
+ height as i64 - funding.funding_tx_confirmation_height as i64 + 1;
5604
+ if funding_tx_confirmations < minimum_depth as i64 {
5605
+ return false;
5606
+ }
5607
+
5608
+ return true;
5609
+ }
5610
+
5554
5611
#[rustfmt::skip]
5555
5612
fn check_for_funding_tx_confirmed<L: Deref>(
5556
5613
&mut self, funding: &mut FundingScope, block_hash: &BlockHash, height: u32,
@@ -9234,58 +9291,13 @@ where
9234
9291
}
9235
9292
}
9236
9293
9237
- #[cfg(splicing)]
9238
- fn check_get_splice_locked(
9239
- &self, pending_splice: &PendingSplice, funding: &FundingScope, height: u32,
9240
- ) -> Option<msgs::SpliceLocked> {
9241
- if !self.check_funding_meets_minimum_depth(funding, height) {
9242
- return None;
9243
- }
9244
-
9245
- let confirmed_funding_txid = match funding.get_funding_txid() {
9246
- Some(funding_txid) => funding_txid,
9247
- None => {
9248
- debug_assert!(false);
9249
- return None;
9250
- },
9251
- };
9252
-
9253
- match pending_splice.sent_funding_txid {
9254
- Some(sent_funding_txid) if confirmed_funding_txid == sent_funding_txid => None,
9255
- _ => Some(msgs::SpliceLocked {
9256
- channel_id: self.context.channel_id(),
9257
- splice_txid: confirmed_funding_txid,
9258
- }),
9259
- }
9260
- }
9261
-
9262
9294
fn check_funding_meets_minimum_depth(&self, funding: &FundingScope, height: u32) -> bool {
9263
- let minimum_depth = self
9264
- .context
9265
- .minimum_depth(funding)
9266
- .expect("ChannelContext::minimum_depth should be set for FundedChannel");
9267
-
9268
- // Zero-conf channels always meet the minimum depth.
9269
- if minimum_depth == 0 {
9270
- return true;
9271
- }
9272
-
9273
- if funding.funding_tx_confirmation_height == 0 {
9274
- return false;
9275
- }
9276
-
9277
- let funding_tx_confirmations =
9278
- height as i64 - funding.funding_tx_confirmation_height as i64 + 1;
9279
- if funding_tx_confirmations < minimum_depth as i64 {
9280
- return false;
9281
- }
9282
-
9283
- return true;
9295
+ self.context.check_funding_meets_minimum_depth(funding, height)
9284
9296
}
9285
9297
9286
9298
#[cfg(splicing)]
9287
9299
fn maybe_promote_splice_funding<L: Deref>(
9288
- &mut self, splice_txid: Txid, confirmed_funding_index: usize, logger: &L,
9300
+ &mut self, confirmed_funding_index: usize, logger: &L,
9289
9301
) -> bool
9290
9302
where
9291
9303
L::Target: Logger,
@@ -9294,7 +9306,13 @@ where
9294
9306
debug_assert!(confirmed_funding_index < self.pending_funding.len());
9295
9307
9296
9308
let pending_splice = self.pending_splice.as_mut().unwrap();
9297
- pending_splice.sent_funding_txid = Some(splice_txid);
9309
+ let splice_txid = match pending_splice.sent_funding_txid {
9310
+ Some(sent_funding_txid) => sent_funding_txid,
9311
+ None => {
9312
+ debug_assert!(false);
9313
+ return false;
9314
+ },
9315
+ };
9298
9316
9299
9317
if pending_splice.sent_funding_txid == pending_splice.received_funding_txid {
9300
9318
log_info!(
@@ -9305,6 +9323,7 @@ where
9305
9323
);
9306
9324
9307
9325
let funding = self.pending_funding.get_mut(confirmed_funding_index).unwrap();
9326
+ debug_assert_eq!(Some(splice_txid), funding.get_funding_txid());
9308
9327
promote_splice_funding!(self, funding);
9309
9328
9310
9329
return true;
@@ -9394,7 +9413,7 @@ where
9394
9413
9395
9414
#[cfg(splicing)]
9396
9415
if let Some(confirmed_funding_index) = confirmed_funding_index {
9397
- let pending_splice = match self.pending_splice.as_ref () {
9416
+ let pending_splice = match self.pending_splice.as_mut () {
9398
9417
Some(pending_splice) => pending_splice,
9399
9418
None => {
9400
9419
// TODO: Move pending_funding into pending_splice
@@ -9405,7 +9424,7 @@ where
9405
9424
};
9406
9425
let funding = self.pending_funding.get(confirmed_funding_index).unwrap();
9407
9426
9408
- if let Some(splice_locked) = self .check_get_splice_locked(pending_splice , funding, height) {
9427
+ if let Some(splice_locked) = pending_splice .check_get_splice_locked(&self.context , funding, height) {
9409
9428
for &(idx, tx) in txdata.iter() {
9410
9429
if idx > index_in_block {
9411
9430
self.context.check_for_funding_tx_spent(funding, tx, logger)?;
@@ -9419,12 +9438,18 @@ where
9419
9438
&self.context.channel_id,
9420
9439
);
9421
9440
9422
- let announcement_sigs = self
9423
- .maybe_promote_splice_funding(splice_locked.splice_txid, confirmed_funding_index, logger)
9441
+ let funding_promoted =
9442
+ self.maybe_promote_splice_funding(confirmed_funding_index, logger);
9443
+ let funding_txo = funding_promoted.then(|| {
9444
+ self.funding
9445
+ .get_funding_txo()
9446
+ .expect("Splice FundingScope should always have a funding_txo")
9447
+ });
9448
+ let announcement_sigs = funding_promoted
9424
9449
.then(|| self.get_announcement_sigs(node_signer, chain_hash, user_config, height, logger))
9425
9450
.flatten();
9426
9451
9427
- return Ok((Some(FundingConfirmedMessage::Splice(splice_locked)), announcement_sigs));
9452
+ return Ok((Some(FundingConfirmedMessage::Splice(splice_locked, funding_txo )), announcement_sigs));
9428
9453
}
9429
9454
}
9430
9455
@@ -9577,21 +9602,27 @@ where
9577
9602
}
9578
9603
}
9579
9604
9580
- let pending_splice = self.pending_splice.as_ref ().unwrap();
9605
+ let pending_splice = self.pending_splice.as_mut ().unwrap();
9581
9606
let funding = self.pending_funding.get(confirmed_funding_index).unwrap();
9582
- if let Some(splice_locked) = self .check_get_splice_locked(pending_splice , funding, height) {
9607
+ if let Some(splice_locked) = pending_splice .check_get_splice_locked(&self.context , funding, height) {
9583
9608
log_info!(logger, "Sending a splice_locked to our peer for channel {}", &self.context.channel_id);
9584
9609
9585
- let announcement_sigs = self
9586
- .maybe_promote_splice_funding(splice_locked.splice_txid, confirmed_funding_index, logger)
9610
+ let funding_promoted =
9611
+ self.maybe_promote_splice_funding(confirmed_funding_index, logger);
9612
+ let funding_txo = funding_promoted.then(|| {
9613
+ self.funding
9614
+ .get_funding_txo()
9615
+ .expect("Splice FundingScope should always have a funding_txo")
9616
+ });
9617
+ let announcement_sigs = funding_promoted
9587
9618
.then(|| chain_node_signer
9588
9619
.and_then(|(chain_hash, node_signer, user_config)|
9589
9620
self.get_announcement_sigs(node_signer, chain_hash, user_config, height, logger)
9590
9621
)
9591
9622
)
9592
9623
.flatten();
9593
9624
9594
- return Ok((Some(FundingConfirmedMessage::Splice(splice_locked)), timed_out_htlcs, announcement_sigs));
9625
+ return Ok((Some(FundingConfirmedMessage::Splice(splice_locked, funding_txo )), timed_out_htlcs, announcement_sigs));
9595
9626
}
9596
9627
}
9597
9628
@@ -10085,7 +10116,7 @@ where
10085
10116
pub fn splice_locked<NS: Deref, L: Deref>(
10086
10117
&mut self, msg: &msgs::SpliceLocked, node_signer: &NS, chain_hash: ChainHash,
10087
10118
user_config: &UserConfig, best_block: &BestBlock, logger: &L,
10088
- ) -> Result<Option<msgs::AnnouncementSignatures>, ChannelError>
10119
+ ) -> Result<( Option<OutPoint>, Option< msgs::AnnouncementSignatures>) , ChannelError>
10089
10120
where
10090
10121
NS::Target: NodeSigner,
10091
10122
L::Target: Logger,
@@ -10118,13 +10149,18 @@ where
10118
10149
&self.context.channel_id,
10119
10150
);
10120
10151
promote_splice_funding!(self, funding);
10121
- return Ok(self.get_announcement_sigs(
10152
+ let funding_txo = self
10153
+ .funding
10154
+ .get_funding_txo()
10155
+ .expect("Splice FundingScope should always have a funding_txo");
10156
+ let announcement_sigs = self.get_announcement_sigs(
10122
10157
node_signer,
10123
10158
chain_hash,
10124
10159
user_config,
10125
10160
best_block.height,
10126
10161
logger,
10127
- ));
10162
+ );
10163
+ return Ok((Some(funding_txo), announcement_sigs));
10128
10164
}
10129
10165
10130
10166
let err = "unknown splice funding txid";
@@ -10148,7 +10184,7 @@ where
10148
10184
}
10149
10185
10150
10186
pending_splice.received_funding_txid = Some(msg.splice_txid);
10151
- Ok(None)
10187
+ Ok(( None, None) )
10152
10188
}
10153
10189
10154
10190
// Send stuff to our remote peers:
@@ -10899,11 +10935,6 @@ where
10899
10935
}
10900
10936
}
10901
10937
10902
- #[cfg(splicing)]
10903
- pub fn has_pending_splice(&self) -> bool {
10904
- self.pending_splice.is_some()
10905
- }
10906
-
10907
10938
pub fn remove_legacy_scids_before_block(&mut self, height: u32) -> alloc::vec::Drain<u64> {
10908
10939
let end = self
10909
10940
.funding
0 commit comments