Skip to content

Commit 2b207cf

Browse files
jkczyzclaude
andcommitted
Emit SpliceFailed event when funded channels shut down with active splice negotiations
Adds SpliceFailed event emission immediately after ChannelClosed events when a FundedChannel is shut down while having an active splice negotiation. This ensures users are notified when splice operations are terminated due to channel closure. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 908f0f2 commit 2b207cf

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

lightning/src/ln/channel.rs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1188,6 +1188,9 @@ pub(crate) struct ShutdownResult {
11881188
pub(crate) unbroadcasted_funding_tx: Option<Transaction>,
11891189
pub(crate) channel_funding_txo: Option<OutPoint>,
11901190
pub(crate) last_local_balance_msat: u64,
1191+
/// If a splice was in progress when the channel was shut down, this contains
1192+
/// the splice funding information for emitting a SpliceFailed event.
1193+
pub(crate) splice_funding_failed: Option<SpliceFundingFailed>,
11911194
}
11921195

11931196
/// Tracks the transaction number, along with current and next commitment points.
@@ -2667,6 +2670,15 @@ pub(crate) struct SpliceInstructions {
26672670
locktime: u32,
26682671
}
26692672

2673+
impl SpliceInstructions {
2674+
fn into_contributed_inputs_and_outputs(self) -> (Vec<bitcoin::OutPoint>, Vec<TxOut>) {
2675+
(
2676+
self.our_funding_inputs.into_iter().map(|input| input.utxo.outpoint).collect(),
2677+
self.our_funding_outputs,
2678+
)
2679+
}
2680+
}
2681+
26702682
impl_writeable_tlv_based!(SpliceInstructions, {
26712683
(1, adjusted_funding_contribution, required),
26722684
(3, our_funding_inputs, required_vec),
@@ -6021,6 +6033,7 @@ where
60216033
is_manual_broadcast: self.is_manual_broadcast,
60226034
channel_funding_txo: funding.get_funding_txo(),
60236035
last_local_balance_msat: funding.value_to_self_msat,
6036+
splice_funding_failed: None,
60246037
}
60256038
}
60266039

@@ -6805,7 +6818,35 @@ where
68056818
}
68066819

68076820
pub fn force_shutdown(&mut self, closure_reason: ClosureReason) -> ShutdownResult {
6808-
self.context.force_shutdown(&self.funding, closure_reason)
6821+
let splice_funding_failed =
6822+
if matches!(self.context.channel_state, ChannelState::ChannelReady(_)) {
6823+
self.reset_pending_splice_state().or_else(|| {
6824+
self.quiescent_action.take().and_then(|quiescent_action| match quiescent_action
6825+
{
6826+
QuiescentAction::Splice(instructions) => {
6827+
let (inputs, outputs) =
6828+
instructions.into_contributed_inputs_and_outputs();
6829+
Some(SpliceFundingFailed {
6830+
funding_txo: None,
6831+
channel_type: None,
6832+
contributed_inputs: inputs,
6833+
contributed_outputs: outputs,
6834+
})
6835+
},
6836+
#[cfg(any(test, fuzzing))]
6837+
_ => {
6838+
self.quiescent_action = Some(quiescent_action);
6839+
None
6840+
},
6841+
})
6842+
})
6843+
} else {
6844+
None
6845+
};
6846+
6847+
let mut shutdown_result = self.context.force_shutdown(&self.funding, closure_reason);
6848+
shutdown_result.splice_funding_failed = splice_funding_failed;
6849+
shutdown_result
68096850
}
68106851

68116852
fn interactive_tx_constructor_mut(&mut self) -> Option<&mut InteractiveTxConstructor> {
@@ -10335,6 +10376,7 @@ where
1033510376
is_manual_broadcast: self.context.is_manual_broadcast,
1033610377
channel_funding_txo: self.funding.get_funding_txo(),
1033710378
last_local_balance_msat: self.funding.value_to_self_msat,
10379+
splice_funding_failed: None,
1033810380
}
1033910381
}
1034010382

lightning/src/ln/channelmanager.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4515,6 +4515,19 @@ where
45154515
last_local_balance_msat: Some(shutdown_res.last_local_balance_msat),
45164516
}, None));
45174517

4518+
// Emit SpliceFailed event immediately after ChannelClosed if there was an active splice negotiation
4519+
if let Some(splice_funding_failed) = shutdown_res.splice_funding_failed.take() {
4520+
pending_events.push_back((events::Event::SpliceFailed {
4521+
channel_id: shutdown_res.channel_id,
4522+
counterparty_node_id: shutdown_res.counterparty_node_id,
4523+
user_channel_id: shutdown_res.user_channel_id,
4524+
abandoned_funding_txo: splice_funding_failed.funding_txo,
4525+
channel_type: splice_funding_failed.channel_type,
4526+
contributed_inputs: splice_funding_failed.contributed_inputs,
4527+
contributed_outputs: splice_funding_failed.contributed_outputs,
4528+
}, None));
4529+
}
4530+
45184531
if let Some(transaction) = shutdown_res.unbroadcasted_funding_tx {
45194532
let funding_info = if shutdown_res.is_manual_broadcast {
45204533
FundingInfo::OutPoint {

0 commit comments

Comments
 (0)