Skip to content

Commit 41addd7

Browse files
jkczyzclaude
andcommitted
Add Event::SpliceFailed variant for splice transaction failures
Introduce SpliceFailed event to notify applications when splice transaction construction or negotiation fails. This allows applications to handle failures gracefully and take corrective action or retry. The event includes similar fields to SplicePending but with optional funding_txo and channel_type fields since they may not be available when failures occur early in the process. Additionally includes contributed_inputs and contributed_outputs vectors to provide information about what inputs and outputs were attempted. Uses TLV ID 52 for serialization to maintain proper event ordering and avoid conflicts with other event types. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 7b7b404 commit 41addd7

File tree

1 file changed

+76
-1
lines changed

1 file changed

+76
-1
lines changed

lightning/src/events/mod.rs

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ use bitcoin::hashes::sha256::Hash as Sha256;
4949
use bitcoin::hashes::Hash;
5050
use bitcoin::script::ScriptBuf;
5151
use bitcoin::secp256k1::PublicKey;
52-
use bitcoin::{OutPoint, Transaction};
52+
use bitcoin::{OutPoint, Transaction, TxOut};
5353
use core::ops::Deref;
5454

5555
#[allow(unused_imports)]
@@ -1524,6 +1524,37 @@ pub enum Event {
15241524
/// The features that this channel will operate with.
15251525
channel_type: ChannelTypeFeatures,
15261526
},
1527+
/// Used to indicate that a splice transaction for the given `channel_id` has failed.
1528+
///
1529+
/// This event is emitted when a splice transaction construction or negotiation fails,
1530+
/// allowing applications to handle the failure and potentially retry or take corrective action.
1531+
///
1532+
/// # Failure Behavior and Persistence
1533+
/// This event will eventually be replayed after failures-to-handle (i.e., the event handler
1534+
/// returning `Err(ReplayEvent ())`) and will be persisted across restarts.
1535+
SpliceFailed {
1536+
/// The `channel_id` of the channel for which the splice failed.
1537+
channel_id: ChannelId,
1538+
/// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound
1539+
/// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels if
1540+
/// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
1541+
/// `user_channel_id` will be randomized for an inbound channel.
1542+
///
1543+
/// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
1544+
/// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
1545+
/// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
1546+
user_channel_id: u128,
1547+
/// The `node_id` of the channel counterparty.
1548+
counterparty_node_id: PublicKey,
1549+
/// The outpoint of the channel's splice funding transaction, if one was created.
1550+
funding_txo: Option<OutPoint>,
1551+
/// The features that this channel will operate with, if available.
1552+
channel_type: Option<ChannelTypeFeatures>,
1553+
/// Input outpoints contributed to the splice transaction.
1554+
contributed_inputs: Vec<OutPoint>,
1555+
/// Outputs contributed to the splice transaction.
1556+
contributed_outputs: Vec<TxOut>,
1557+
},
15271558
/// Used to indicate to the user that they can abandon the funding transaction and recycle the
15281559
/// inputs for another purpose.
15291560
///
@@ -2254,6 +2285,26 @@ impl Writeable for Event {
22542285
(9, funding_txo, required),
22552286
});
22562287
},
2288+
&Event::SpliceFailed {
2289+
ref channel_id,
2290+
ref user_channel_id,
2291+
ref counterparty_node_id,
2292+
ref funding_txo,
2293+
ref channel_type,
2294+
ref contributed_inputs,
2295+
ref contributed_outputs,
2296+
} => {
2297+
52u8.write(writer)?;
2298+
write_tlv_fields!(writer, {
2299+
(1, channel_id, required),
2300+
(3, channel_type, option),
2301+
(5, user_channel_id, required),
2302+
(7, counterparty_node_id, required),
2303+
(9, funding_txo, option),
2304+
(11, *contributed_inputs, optional_vec),
2305+
(13, *contributed_outputs, optional_vec),
2306+
});
2307+
},
22572308
// Note that, going forward, all new events must only write data inside of
22582309
// `write_tlv_fields`. Versions 0.0.101+ will ignore odd-numbered events that write
22592310
// data via `write_tlv_fields`.
@@ -2856,6 +2907,30 @@ impl MaybeReadable for Event {
28562907
};
28572908
f()
28582909
},
2910+
52u8 => {
2911+
let mut f = || {
2912+
_init_and_read_len_prefixed_tlv_fields!(reader, {
2913+
(1, channel_id, required),
2914+
(3, channel_type, option),
2915+
(5, user_channel_id, required),
2916+
(7, counterparty_node_id, required),
2917+
(9, funding_txo, option),
2918+
(11, contributed_inputs, optional_vec),
2919+
(13, contributed_outputs, optional_vec),
2920+
});
2921+
2922+
Ok(Some(Event::SpliceFailed {
2923+
channel_id: channel_id.0.unwrap(),
2924+
user_channel_id: user_channel_id.0.unwrap(),
2925+
counterparty_node_id: counterparty_node_id.0.unwrap(),
2926+
funding_txo,
2927+
channel_type,
2928+
contributed_inputs: contributed_inputs.unwrap_or_default(),
2929+
contributed_outputs: contributed_outputs.unwrap_or_default(),
2930+
}))
2931+
};
2932+
f()
2933+
},
28592934
// Versions prior to 0.0.100 did not ignore odd types, instead returning InvalidValue.
28602935
// Version 0.0.100 failed to properly ignore odd types, possibly resulting in corrupt
28612936
// reads.

0 commit comments

Comments
 (0)