@@ -39,6 +39,8 @@ use crate::chain::transaction::{OutPoint, TransactionData};
39
39
use crate::chain::BestBlock;
40
40
use crate::events::bump_transaction::{BASE_INPUT_WEIGHT, EMPTY_SCRIPT_SIG_WEIGHT};
41
41
use crate::events::ClosureReason;
42
+ #[cfg(splicing)]
43
+ use crate::events::FundingInfo;
42
44
use crate::ln::chan_utils;
43
45
use crate::ln::chan_utils::{
44
46
get_commitment_transaction_number_obscure_factor, max_htlcs, second_stage_tx_fees_sat,
@@ -6408,16 +6410,35 @@ where
6408
6410
6409
6411
#[cfg(splicing)]
6410
6412
macro_rules! promote_splice_funding {
6411
- ($self: expr, $funding: expr) => {
6413
+ ($self: expr, $funding: expr) => {{
6414
+ let prev_funding_txid = $self.funding.get_funding_txid();
6412
6415
if let Some(scid) = $self.funding.short_channel_id {
6413
6416
$self.context.historical_scids.push(scid);
6414
6417
}
6415
6418
core::mem::swap(&mut $self.funding, $funding);
6416
6419
$self.interactive_tx_signing_session = None;
6417
6420
$self.pending_splice = None;
6418
- $self.pending_funding.clear();
6419
6421
$self.context.announcement_sigs_state = AnnouncementSigsState::NotSent;
6420
- };
6422
+
6423
+ // The swap above places the previous `FundingScope` into `pending_funding`.
6424
+ let discarded_funding = $self
6425
+ .pending_funding
6426
+ .drain(..)
6427
+ .filter(|funding| funding.get_funding_txid() != prev_funding_txid)
6428
+ .map(|mut funding| {
6429
+ funding
6430
+ .funding_transaction
6431
+ .take()
6432
+ .map(|tx| FundingInfo::Tx { transaction: tx })
6433
+ .unwrap_or_else(|| FundingInfo::OutPoint {
6434
+ outpoint: funding
6435
+ .get_funding_txo()
6436
+ .expect("Negotiated splices must have a known funding outpoint"),
6437
+ })
6438
+ })
6439
+ .collect::<Vec<_>>();
6440
+ discarded_funding
6441
+ }};
6421
6442
}
6422
6443
6423
6444
#[cfg(any(test, fuzzing))]
@@ -6500,6 +6521,7 @@ pub struct SpliceFundingPromotion {
6500
6521
pub funding_txo: OutPoint,
6501
6522
pub monitor_update: Option<ChannelMonitorUpdate>,
6502
6523
pub announcement_sigs: Option<msgs::AnnouncementSignatures>,
6524
+ pub discarded_funding: Vec<FundingInfo>,
6503
6525
}
6504
6526
6505
6527
impl<SP: Deref> FundedChannel<SP>
@@ -9006,23 +9028,25 @@ where
9006
9028
log_trace!(logger, "Regenerating latest commitment update in channel {} with{} {} update_adds, {} update_fulfills, {} update_fails, and {} update_fail_malformeds",
9007
9029
&self.context.channel_id(), if update_fee.is_some() { " update_fee," } else { "" },
9008
9030
update_add_htlcs.len(), update_fulfill_htlcs.len(), update_fail_htlcs.len(), update_fail_malformed_htlcs.len());
9009
- let commitment_signed =
9010
- if let Ok(update) = self.send_commitment_no_state_update(logger) {
9011
- if self.context.signer_pending_commitment_update {
9012
- log_trace!(
9013
- logger,
9014
- "Commitment update generated: clearing signer_pending_commitment_update"
9015
- );
9016
- self.context.signer_pending_commitment_update = false;
9017
- }
9018
- update
9019
- } else {
9020
- if !self.context.signer_pending_commitment_update {
9021
- log_trace!(logger, "Commitment update awaiting signer: setting signer_pending_commitment_update");
9022
- self.context.signer_pending_commitment_update = true;
9023
- }
9024
- return Err(());
9025
- };
9031
+ let commitment_signed = if let Ok(update) = self.send_commitment_no_state_update(logger) {
9032
+ if self.context.signer_pending_commitment_update {
9033
+ log_trace!(
9034
+ logger,
9035
+ "Commitment update generated: clearing signer_pending_commitment_update"
9036
+ );
9037
+ self.context.signer_pending_commitment_update = false;
9038
+ }
9039
+ update
9040
+ } else {
9041
+ if !self.context.signer_pending_commitment_update {
9042
+ log_trace!(
9043
+ logger,
9044
+ "Commitment update awaiting signer: setting signer_pending_commitment_update"
9045
+ );
9046
+ self.context.signer_pending_commitment_update = true;
9047
+ }
9048
+ return Err(());
9049
+ };
9026
9050
Ok(msgs::CommitmentUpdate {
9027
9051
update_add_htlcs,
9028
9052
update_fulfill_htlcs,
@@ -10326,16 +10350,16 @@ where
10326
10350
&self.context.channel_id,
10327
10351
);
10328
10352
10329
- {
10353
+ let discarded_funding = {
10330
10354
// Scope `funding` since it is swapped within `promote_splice_funding` and we don't want
10331
10355
// to unintentionally use it.
10332
10356
let funding = self
10333
10357
.pending_funding
10334
10358
.iter_mut()
10335
10359
.find(|funding| funding.get_funding_txid() == Some(splice_txid))
10336
10360
.unwrap();
10337
- promote_splice_funding!(self, funding);
10338
- }
10361
+ promote_splice_funding!(self, funding)
10362
+ };
10339
10363
10340
10364
let funding_txo = self
10341
10365
.funding
@@ -10356,7 +10380,12 @@ where
10356
10380
let announcement_sigs =
10357
10381
self.get_announcement_sigs(node_signer, chain_hash, user_config, block_height, logger);
10358
10382
10359
- Some(SpliceFundingPromotion { funding_txo, monitor_update, announcement_sigs })
10383
+ Some(SpliceFundingPromotion {
10384
+ funding_txo,
10385
+ monitor_update,
10386
+ announcement_sigs,
10387
+ discarded_funding,
10388
+ })
10360
10389
}
10361
10390
10362
10391
/// When a transaction is confirmed, we check whether it is or spends the funding transaction
@@ -10438,16 +10467,17 @@ where
10438
10467
&self.context.channel_id,
10439
10468
);
10440
10469
10441
- let (funding_txo, monitor_update, announcement_sigs) =
10470
+ let (funding_txo, monitor_update, announcement_sigs, discarded_funding ) =
10442
10471
self.maybe_promote_splice_funding(
10443
10472
node_signer, chain_hash, user_config, height, logger,
10444
10473
).map(|splice_promotion| (
10445
10474
Some(splice_promotion.funding_txo),
10446
10475
splice_promotion.monitor_update,
10447
10476
splice_promotion.announcement_sigs,
10448
- )).unwrap_or((None, None, None));
10477
+ splice_promotion.discarded_funding,
10478
+ )).unwrap_or((None, None, None, Vec::new()));
10449
10479
10450
- return Ok((Some(FundingConfirmedMessage::Splice(splice_locked, funding_txo, monitor_update)), announcement_sigs));
10480
+ return Ok((Some(FundingConfirmedMessage::Splice(splice_locked, funding_txo, monitor_update, discarded_funding )), announcement_sigs));
10451
10481
}
10452
10482
}
10453
10483
}
@@ -10599,7 +10629,7 @@ where
10599
10629
log_info!(logger, "Sending a splice_locked to our peer for channel {}", &self.context.channel_id);
10600
10630
debug_assert!(chain_node_signer.is_some());
10601
10631
10602
- let (funding_txo, monitor_update, announcement_sigs) = chain_node_signer
10632
+ let (funding_txo, monitor_update, announcement_sigs, discarded_funding ) = chain_node_signer
10603
10633
.and_then(|(chain_hash, node_signer, user_config)| {
10604
10634
// We can only promote on blocks connected, which is when we expect
10605
10635
// `chain_node_signer` to be `Some`.
@@ -10609,10 +10639,11 @@ where
10609
10639
Some(splice_promotion.funding_txo),
10610
10640
splice_promotion.monitor_update,
10611
10641
splice_promotion.announcement_sigs,
10642
+ splice_promotion.discarded_funding,
10612
10643
))
10613
- .unwrap_or((None, None, None));
10644
+ .unwrap_or((None, None, None, Vec::new() ));
10614
10645
10615
- return Ok((Some(FundingConfirmedMessage::Splice(splice_locked, funding_txo, monitor_update)), timed_out_htlcs, announcement_sigs));
10646
+ return Ok((Some(FundingConfirmedMessage::Splice(splice_locked, funding_txo, monitor_update, discarded_funding )), timed_out_htlcs, announcement_sigs));
10616
10647
}
10617
10648
}
10618
10649
0 commit comments