Skip to content

Commit 135605f

Browse files
committed
Rework ChannelManager::funding_transaction_signed
Previously, we'd emit a `FundingTransactionReadyForSigning` event once the initial `commitment_signed` is exchanged for a splicing/dual-funding attempt and require users to call back with their signed inputs using `ChannelManager::funding_transaction_signed`. While this approach worked in practice, it prevents us from abandoning a splice if we cannot or no longer wish to sign as the splice has already been committed to by this point. This commit reworks the API such that this is now possible. After exchanging `tx_complete`, we will no longer immediately send our initial `commitment_signed`. We will now emit the `FundingTransactionReadyForSigning` event and wait for the user to call back before releasing both our initial `commitment_signed` and our `tx_signatures`. As a result, the event is now persisted, as there is only one possible path in which it is generated. Note that we continue to only emit the event if a local contribution to negotiated transaction was made. Future work will expose a cancellation API such that we can abandon splice attempts safely (we can just force close the channel with dual-funding).
1 parent de384ff commit 135605f

File tree

5 files changed

+459
-474
lines changed

5 files changed

+459
-474
lines changed

lightning/src/events/mod.rs

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1835,7 +1835,7 @@ pub enum Event {
18351835
///
18361836
/// # Failure Behavior and Persistence
18371837
/// This event will eventually be replayed after failures-to-handle (i.e., the event handler
1838-
/// returning `Err(ReplayEvent ())`), but will only be regenerated as needed after restarts.
1838+
/// returning `Err(ReplayEvent ())`) and will be persisted across restarts.
18391839
///
18401840
/// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
18411841
/// [`ChannelManager::funding_transaction_signed`]: crate::ln::channelmanager::ChannelManager::funding_transaction_signed
@@ -2304,10 +2304,19 @@ impl Writeable for Event {
23042304
47u8.write(writer)?;
23052305
// Never write StaticInvoiceRequested events as buffered onion messages aren't serialized.
23062306
},
2307-
&Event::FundingTransactionReadyForSigning { .. } => {
2308-
49u8.write(writer)?;
2309-
// We never write out FundingTransactionReadyForSigning events as they will be regenerated when
2310-
// necessary.
2307+
&Event::FundingTransactionReadyForSigning {
2308+
ref channel_id,
2309+
ref counterparty_node_id,
2310+
ref user_channel_id,
2311+
ref unsigned_transaction,
2312+
} => {
2313+
48u8.write(writer)?;
2314+
write_tlv_fields!(writer, {
2315+
(1, channel_id, required),
2316+
(3, counterparty_node_id, required),
2317+
(5, user_channel_id, required),
2318+
(7, unsigned_transaction, required),
2319+
});
23112320
},
23122321
&Event::SplicePending {
23132322
ref channel_id,
@@ -2930,8 +2939,24 @@ impl MaybeReadable for Event {
29302939
45u8 => Ok(None),
29312940
// Note that we do not write a length-prefixed TLV for StaticInvoiceRequested events.
29322941
47u8 => Ok(None),
2933-
// Note that we do not write a length-prefixed TLV for FundingTransactionReadyForSigning events.
2934-
49u8 => Ok(None),
2942+
48u8 => {
2943+
let mut f = || {
2944+
_init_and_read_len_prefixed_tlv_fields!(reader, {
2945+
(1, channel_id, required),
2946+
(3, counterparty_node_id, required),
2947+
(5, user_channel_id, required),
2948+
(7, unsigned_transaction, required),
2949+
});
2950+
2951+
Ok(Some(Event::FundingTransactionReadyForSigning {
2952+
channel_id: channel_id.0.unwrap(),
2953+
user_channel_id: user_channel_id.0.unwrap(),
2954+
counterparty_node_id: counterparty_node_id.0.unwrap(),
2955+
unsigned_transaction: unsigned_transaction.0.unwrap(),
2956+
}))
2957+
};
2958+
f()
2959+
},
29352960
50u8 => {
29362961
let mut f = || {
29372962
_init_and_read_len_prefixed_tlv_fields!(reader, {

0 commit comments

Comments
 (0)