Skip to content

Commit cb5e32f

Browse files
committed
Add FundingSigned event
If `manually_broadcast_outbound_channels` is set, LDK will emit this event after the counterparty node send the `FundingSigned` msg without broadcasting the funding transaction.
1 parent 7feebc5 commit cb5e32f

File tree

5 files changed

+305
-13
lines changed

5 files changed

+305
-13
lines changed

lightning/src/events/mod.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,29 @@ impl_writeable_tlv_based_enum!(PaymentFailureReason,
497497
/// written as it makes no sense to respond to it after reconnecting to peers).
498498
#[derive(Clone, Debug, PartialEq, Eq)]
499499
pub enum Event {
500+
/// Used to indicate that the counterparty node has sent `FundingSigned` msg but we are yet to
501+
/// broadcast the funding transaction.
502+
///
503+
/// After you receive this event, you should broadcast the funding transaction and then call
504+
//// [`ChannelManager::funding_transaction_broadcasted`]. <-- not implemtened yet
505+
/// // should we have some timeout for this?
506+
//// [`ChannelManager::funding_transaction_broadcasted`]: crate::ln::channelmanager::ChannelManager::funding_transaction_broadcasted
507+
FundingSigned {
508+
/// The `channel_id` indicating which channel has completed the `FundingSigned` stage.
509+
channel_id: ChannelId,
510+
/// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound
511+
/// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels if
512+
/// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
513+
/// `user_channel_id` will be randomized for an inbound channel. This may be zero for objects
514+
/// serialized with LDK versions prior to 0.0.113.
515+
///
516+
/// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
517+
/// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
518+
/// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
519+
user_channel_id: u128,
520+
/// The funding transaction which was signed by the counterparty.
521+
funding_tx: Transaction,
522+
},
500523
/// Used to indicate that the client should generate a funding transaction with the given
501524
/// parameters and then call [`ChannelManager::funding_transaction_generated`].
502525
/// Generated in [`ChannelManager`] message handling.
@@ -1404,6 +1427,14 @@ impl Writeable for Event {
14041427
35u8.write(writer)?;
14051428
// Never write ConnectionNeeded events as buffered onion messages aren't serialized.
14061429
},
1430+
&Event::FundingSigned { ref channel_id, ref user_channel_id, ref funding_tx } => {
1431+
37u8.write(writer)?;
1432+
write_tlv_fields!(writer, {
1433+
(0, channel_id, required),
1434+
(2, user_channel_id, required),
1435+
(4, funding_tx, required),
1436+
});
1437+
},
14071438
// Note that, going forward, all new events must only write data inside of
14081439
// `write_tlv_fields`. Versions 0.0.101+ will ignore odd-numbered events that write
14091440
// data via `write_tlv_fields`.
@@ -1814,6 +1845,24 @@ impl MaybeReadable for Event {
18141845
},
18151846
// Note that we do not write a length-prefixed TLV for ConnectionNeeded events.
18161847
35u8 => Ok(None),
1848+
37u8 => {
1849+
let mut f = || {
1850+
let mut channel_id = ChannelId::new_zero();
1851+
let mut user_channel_id: u128 = 0;
1852+
let mut funding_tx = Transaction { version: 2, lock_time: LockTime::ZERO, input: Vec::new(), output: Vec::new() };
1853+
read_tlv_fields!(reader, {
1854+
(0, channel_id, required),
1855+
(2, user_channel_id, required),
1856+
(4, funding_tx, required),
1857+
});
1858+
Ok(Some(Event::FundingSigned {
1859+
channel_id,
1860+
user_channel_id,
1861+
funding_tx,
1862+
}))
1863+
};
1864+
f()
1865+
},
18171866
// Versions prior to 0.0.100 did not ignore odd types, instead returning InvalidValue.
18181867
// Version 0.0.100 failed to properly ignore odd types, possibly resulting in corrupt
18191868
// reads.

0 commit comments

Comments
 (0)