Skip to content

Commit dd2e394

Browse files
jkczyzclaude
andcommitted
Add SpliceFailed event
Once a splice has been successfully initiated, but prior to signing any negotiated funding transaction, it may fail. Add an event used to indicate this and which UTXOs can be reused. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 4bc0e46 commit dd2e394

File tree

1 file changed

+79
-1
lines changed

1 file changed

+79
-1
lines changed

lightning/src/events/mod.rs

Lines changed: 79 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)]
@@ -1533,6 +1533,40 @@ pub enum Event {
15331533
/// features that the channel was opened with, but in the future splices may change them.
15341534
channel_type: ChannelTypeFeatures,
15351535
},
1536+
/// Used to indicate that a splice for the given `channel_id` has failed.
1537+
///
1538+
/// This event may be emitted if a splice fails after it has been initiated but prior to signing
1539+
/// any negotiated funding transaction.
1540+
///
1541+
/// Any UTXOs contributed to be spent by the funding transaction may be reused and will be
1542+
/// given in `contributed_inputs`.
1543+
///
1544+
/// # Failure Behavior and Persistence
1545+
/// This event will eventually be replayed after failures-to-handle (i.e., the event handler
1546+
/// returning `Err(ReplayEvent ())`) and will be persisted across restarts.
1547+
SpliceFailed {
1548+
/// The `channel_id` of the channel for which the splice failed.
1549+
channel_id: ChannelId,
1550+
/// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound
1551+
/// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels if
1552+
/// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
1553+
/// `user_channel_id` will be randomized for an inbound channel.
1554+
///
1555+
/// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
1556+
/// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
1557+
/// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
1558+
user_channel_id: u128,
1559+
/// The `node_id` of the channel counterparty.
1560+
counterparty_node_id: PublicKey,
1561+
/// The outpoint of the channel's splice funding transaction, if one was created.
1562+
funding_txo: Option<OutPoint>,
1563+
/// The features that this channel will operate with, if available.
1564+
channel_type: Option<ChannelTypeFeatures>,
1565+
/// UTXOs spent as inputs contributed to the splice transaction.
1566+
contributed_inputs: Vec<OutPoint>,
1567+
/// Outputs contributed to the splice transaction.
1568+
contributed_outputs: Vec<TxOut>,
1569+
},
15361570
/// Used to indicate to the user that they can abandon the funding transaction and recycle the
15371571
/// inputs for another purpose.
15381572
///
@@ -2275,6 +2309,26 @@ impl Writeable for Event {
22752309
(9, funding_txo, required),
22762310
});
22772311
},
2312+
&Event::SpliceFailed {
2313+
ref channel_id,
2314+
ref user_channel_id,
2315+
ref counterparty_node_id,
2316+
ref funding_txo,
2317+
ref channel_type,
2318+
ref contributed_inputs,
2319+
ref contributed_outputs,
2320+
} => {
2321+
52u8.write(writer)?;
2322+
write_tlv_fields!(writer, {
2323+
(1, channel_id, required),
2324+
(3, channel_type, option),
2325+
(5, user_channel_id, required),
2326+
(7, counterparty_node_id, required),
2327+
(9, funding_txo, option),
2328+
(11, *contributed_inputs, optional_vec),
2329+
(13, *contributed_outputs, optional_vec),
2330+
});
2331+
},
22782332
// Note that, going forward, all new events must only write data inside of
22792333
// `write_tlv_fields`. Versions 0.0.101+ will ignore odd-numbered events that write
22802334
// data via `write_tlv_fields`.
@@ -2877,6 +2931,30 @@ impl MaybeReadable for Event {
28772931
};
28782932
f()
28792933
},
2934+
52u8 => {
2935+
let mut f = || {
2936+
_init_and_read_len_prefixed_tlv_fields!(reader, {
2937+
(1, channel_id, required),
2938+
(3, channel_type, option),
2939+
(5, user_channel_id, required),
2940+
(7, counterparty_node_id, required),
2941+
(9, funding_txo, option),
2942+
(11, contributed_inputs, optional_vec),
2943+
(13, contributed_outputs, optional_vec),
2944+
});
2945+
2946+
Ok(Some(Event::SpliceFailed {
2947+
channel_id: channel_id.0.unwrap(),
2948+
user_channel_id: user_channel_id.0.unwrap(),
2949+
counterparty_node_id: counterparty_node_id.0.unwrap(),
2950+
funding_txo,
2951+
channel_type,
2952+
contributed_inputs: contributed_inputs.unwrap_or_default(),
2953+
contributed_outputs: contributed_outputs.unwrap_or_default(),
2954+
}))
2955+
};
2956+
f()
2957+
},
28802958
// Versions prior to 0.0.100 did not ignore odd types, instead returning InvalidValue.
28812959
// Version 0.0.100 failed to properly ignore odd types, possibly resulting in corrupt
28822960
// reads.

0 commit comments

Comments
 (0)