Skip to content

Commit 6830eff

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 fc9dd39 commit 6830eff

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)]
@@ -1436,6 +1436,37 @@ pub enum Event {
14361436
/// The features that this channel will operate with.
14371437
channel_type: ChannelTypeFeatures,
14381438
},
1439+
/// Used to indicate that a splice transaction for the given `channel_id` has failed.
1440+
///
1441+
/// This event is emitted when a splice transaction construction or negotiation fails,
1442+
/// allowing applications to handle the failure and potentially retry or take corrective action.
1443+
///
1444+
/// # Failure Behavior and Persistence
1445+
/// This event will eventually be replayed after failures-to-handle (i.e., the event handler
1446+
/// returning `Err(ReplayEvent ())`) and will be persisted across restarts.
1447+
SpliceFailed {
1448+
/// The `channel_id` of the channel for which the splice failed.
1449+
channel_id: ChannelId,
1450+
/// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound
1451+
/// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels if
1452+
/// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
1453+
/// `user_channel_id` will be randomized for an inbound channel.
1454+
///
1455+
/// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
1456+
/// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
1457+
/// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
1458+
user_channel_id: u128,
1459+
/// The `node_id` of the channel counterparty.
1460+
counterparty_node_id: PublicKey,
1461+
/// The outpoint of the channel's splice funding transaction, if one was created.
1462+
funding_txo: Option<OutPoint>,
1463+
/// The features that this channel will operate with, if available.
1464+
channel_type: Option<ChannelTypeFeatures>,
1465+
/// Input outpoints contributed to the splice transaction.
1466+
contributed_inputs: Vec<OutPoint>,
1467+
/// Outputs contributed to the splice transaction.
1468+
contributed_outputs: Vec<TxOut>,
1469+
},
14391470
/// Used to indicate that a channel with the given `channel_id` is ready to be used. This event
14401471
/// is emitted when
14411472
/// - the initial funding transaction has been confirmed on-chain to an acceptable depth
@@ -2198,6 +2229,26 @@ impl Writeable for Event {
21982229
(9, funding_txo, required),
21992230
});
22002231
},
2232+
&Event::SpliceFailed {
2233+
ref channel_id,
2234+
ref user_channel_id,
2235+
ref counterparty_node_id,
2236+
ref funding_txo,
2237+
ref channel_type,
2238+
ref contributed_inputs,
2239+
ref contributed_outputs,
2240+
} => {
2241+
52u8.write(writer)?;
2242+
write_tlv_fields!(writer, {
2243+
(1, channel_id, required),
2244+
(3, channel_type, option),
2245+
(5, user_channel_id, required),
2246+
(7, counterparty_node_id, required),
2247+
(9, funding_txo, option),
2248+
(11, *contributed_inputs, optional_vec),
2249+
(13, *contributed_outputs, optional_vec),
2250+
});
2251+
},
22012252
&Event::ConnectionNeeded { .. } => {
22022253
35u8.write(writer)?;
22032254
// Never write ConnectionNeeded events as buffered onion messages aren't serialized.
@@ -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)