Skip to content

Commit 400f795

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 6bb677f commit 400f795

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.
@@ -2669,6 +2672,15 @@ pub(crate) struct SpliceInstructions {
26692672
locktime: u32,
26702673
}
26712674

2675+
impl SpliceInstructions {
2676+
fn into_contributed_inputs_and_outputs(self) -> (Vec<bitcoin::OutPoint>, Vec<TxOut>) {
2677+
(
2678+
self.our_funding_inputs.into_iter().map(|input| input.utxo.outpoint).collect(),
2679+
self.our_funding_outputs,
2680+
)
2681+
}
2682+
}
2683+
26722684
impl_writeable_tlv_based!(SpliceInstructions, {
26732685
(1, adjusted_funding_contribution, required),
26742686
(3, our_funding_inputs, required_vec),
@@ -6023,6 +6035,7 @@ where
60236035
is_manual_broadcast: self.is_manual_broadcast,
60246036
channel_funding_txo: funding.get_funding_txo(),
60256037
last_local_balance_msat: funding.value_to_self_msat,
6038+
splice_funding_failed: None,
60266039
}
60276040
}
60286041

@@ -6795,7 +6808,35 @@ where
67956808
}
67966809

67976810
pub fn force_shutdown(&mut self, closure_reason: ClosureReason) -> ShutdownResult {
6798-
self.context.force_shutdown(&self.funding, closure_reason)
6811+
let splice_funding_failed =
6812+
if matches!(self.context.channel_state, ChannelState::ChannelReady(_)) {
6813+
self.reset_pending_splice_state().or_else(|| {
6814+
self.quiescent_action.take().and_then(|quiescent_action| match quiescent_action
6815+
{
6816+
QuiescentAction::Splice(instructions) => {
6817+
let (inputs, outputs) =
6818+
instructions.into_contributed_inputs_and_outputs();
6819+
Some(SpliceFundingFailed {
6820+
funding_txo: None,
6821+
channel_type: None,
6822+
contributed_inputs: inputs,
6823+
contributed_outputs: outputs,
6824+
})
6825+
},
6826+
#[cfg(any(test, fuzzing))]
6827+
_ => {
6828+
self.quiescent_action = Some(quiescent_action);
6829+
None
6830+
},
6831+
})
6832+
})
6833+
} else {
6834+
None
6835+
};
6836+
6837+
let mut shutdown_result = self.context.force_shutdown(&self.funding, closure_reason);
6838+
shutdown_result.splice_funding_failed = splice_funding_failed;
6839+
shutdown_result
67996840
}
68006841

68016842
fn interactive_tx_constructor_mut(&mut self) -> Option<&mut InteractiveTxConstructor> {
@@ -10331,6 +10372,7 @@ where
1033110372
is_manual_broadcast: self.context.is_manual_broadcast,
1033210373
channel_funding_txo: self.funding.get_funding_txo(),
1033310374
last_local_balance_msat: self.funding.value_to_self_msat,
10375+
splice_funding_failed: None,
1033410376
}
1033510377
}
1033610378

lightning/src/ln/channelmanager.rs

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

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

0 commit comments

Comments
 (0)