@@ -39,6 +39,8 @@ use crate::chain::transaction::{OutPoint, TransactionData};
3939use crate::chain::BestBlock;
4040use crate::events::bump_transaction::{BASE_INPUT_WEIGHT, EMPTY_SCRIPT_SIG_WEIGHT};
4141use crate::events::ClosureReason;
42+ #[cfg(splicing)]
43+ use crate::events::FundingInfo;
4244use crate::ln::chan_utils;
4345use crate::ln::chan_utils::{
4446 get_commitment_transaction_number_obscure_factor, max_htlcs, second_stage_tx_fees_sat,
@@ -6408,16 +6410,35 @@ where
64086410
64096411#[cfg(splicing)]
64106412macro_rules! promote_splice_funding {
6411- ($self: expr, $funding: expr) => {
6413+ ($self: expr, $funding: expr) => {{
6414+ let prev_funding_txid = $self.funding.get_funding_txid();
64126415 if let Some(scid) = $self.funding.short_channel_id {
64136416 $self.context.historical_scids.push(scid);
64146417 }
64156418 core::mem::swap(&mut $self.funding, $funding);
64166419 $self.interactive_tx_signing_session = None;
64176420 $self.pending_splice = None;
6418- $self.pending_funding.clear();
64196421 $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+ }};
64216442}
64226443
64236444#[cfg(any(test, fuzzing))]
@@ -6500,6 +6521,7 @@ pub struct SpliceFundingPromotion {
65006521 pub funding_txo: OutPoint,
65016522 pub monitor_update: Option<ChannelMonitorUpdate>,
65026523 pub announcement_sigs: Option<msgs::AnnouncementSignatures>,
6524+ pub discarded_funding: Vec<FundingInfo>,
65036525}
65046526
65056527impl<SP: Deref> FundedChannel<SP>
@@ -9006,23 +9028,25 @@ where
90069028 log_trace!(logger, "Regenerating latest commitment update in channel {} with{} {} update_adds, {} update_fulfills, {} update_fails, and {} update_fail_malformeds",
90079029 &self.context.channel_id(), if update_fee.is_some() { " update_fee," } else { "" },
90089030 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+ };
90269050 Ok(msgs::CommitmentUpdate {
90279051 update_add_htlcs,
90289052 update_fulfill_htlcs,
@@ -10326,16 +10350,16 @@ where
1032610350 &self.context.channel_id,
1032710351 );
1032810352
10329- {
10353+ let discarded_funding = {
1033010354 // Scope `funding` since it is swapped within `promote_splice_funding` and we don't want
1033110355 // to unintentionally use it.
1033210356 let funding = self
1033310357 .pending_funding
1033410358 .iter_mut()
1033510359 .find(|funding| funding.get_funding_txid() == Some(splice_txid))
1033610360 .unwrap();
10337- promote_splice_funding!(self, funding);
10338- }
10361+ promote_splice_funding!(self, funding)
10362+ };
1033910363
1034010364 let funding_txo = self
1034110365 .funding
@@ -10356,7 +10380,12 @@ where
1035610380 let announcement_sigs =
1035710381 self.get_announcement_sigs(node_signer, chain_hash, user_config, block_height, logger);
1035810382
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+ })
1036010389 }
1036110390
1036210391 /// When a transaction is confirmed, we check whether it is or spends the funding transaction
@@ -10438,16 +10467,17 @@ where
1043810467 &self.context.channel_id,
1043910468 );
1044010469
10441- let (funding_txo, monitor_update, announcement_sigs) =
10470+ let (funding_txo, monitor_update, announcement_sigs, discarded_funding ) =
1044210471 self.maybe_promote_splice_funding(
1044310472 node_signer, chain_hash, user_config, height, logger,
1044410473 ).map(|splice_promotion| (
1044510474 Some(splice_promotion.funding_txo),
1044610475 splice_promotion.monitor_update,
1044710476 splice_promotion.announcement_sigs,
10448- )).unwrap_or((None, None, None));
10477+ splice_promotion.discarded_funding,
10478+ )).unwrap_or((None, None, None, Vec::new()));
1044910479
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));
1045110481 }
1045210482 }
1045310483 }
@@ -10599,7 +10629,7 @@ where
1059910629 log_info!(logger, "Sending a splice_locked to our peer for channel {}", &self.context.channel_id);
1060010630 debug_assert!(chain_node_signer.is_some());
1060110631
10602- let (funding_txo, monitor_update, announcement_sigs) = chain_node_signer
10632+ let (funding_txo, monitor_update, announcement_sigs, discarded_funding ) = chain_node_signer
1060310633 .and_then(|(chain_hash, node_signer, user_config)| {
1060410634 // We can only promote on blocks connected, which is when we expect
1060510635 // `chain_node_signer` to be `Some`.
@@ -10609,10 +10639,11 @@ where
1060910639 Some(splice_promotion.funding_txo),
1061010640 splice_promotion.monitor_update,
1061110641 splice_promotion.announcement_sigs,
10642+ splice_promotion.discarded_funding,
1061210643 ))
10613- .unwrap_or((None, None, None));
10644+ .unwrap_or((None, None, None, Vec::new() ));
1061410645
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));
1061610647 }
1061710648 }
1061810649
0 commit comments