Skip to content

Commit 51380bf

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 c5d7b13 commit 51380bf

File tree

5 files changed

+413
-491
lines changed

5 files changed

+413
-491
lines changed

lightning/src/events/mod.rs

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

0 commit comments

Comments
 (0)