Skip to content

Commit

Permalink
Add FundingSigned event
Browse files Browse the repository at this point in the history
  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.
  • Loading branch information
jbesraa committed Apr 29, 2024
1 parent 7feebc5 commit cb5e32f
Show file tree
Hide file tree
Showing 5 changed files with 305 additions and 13 deletions.
49 changes: 49 additions & 0 deletions lightning/src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,29 @@ impl_writeable_tlv_based_enum!(PaymentFailureReason,
/// written as it makes no sense to respond to it after reconnecting to peers).
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Event {
/// Used to indicate that the counterparty node has sent `FundingSigned` msg but we are yet to
/// broadcast the funding transaction.
///
/// After you receive this event, you should broadcast the funding transaction and then call
//// [`ChannelManager::funding_transaction_broadcasted`]. <-- not implemtened yet
/// // should we have some timeout for this?
//// [`ChannelManager::funding_transaction_broadcasted`]: crate::ln::channelmanager::ChannelManager::funding_transaction_broadcasted
FundingSigned {
/// The `channel_id` indicating which channel has completed the `FundingSigned` stage.
channel_id: ChannelId,
/// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound
/// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels if
/// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
/// `user_channel_id` will be randomized for an inbound channel. This may be zero for objects
/// serialized with LDK versions prior to 0.0.113.
///
/// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
/// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
/// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
user_channel_id: u128,
/// The funding transaction which was signed by the counterparty.
funding_tx: Transaction,
},
/// Used to indicate that the client should generate a funding transaction with the given
/// parameters and then call [`ChannelManager::funding_transaction_generated`].
/// Generated in [`ChannelManager`] message handling.
Expand Down Expand Up @@ -1404,6 +1427,14 @@ impl Writeable for Event {
35u8.write(writer)?;
// Never write ConnectionNeeded events as buffered onion messages aren't serialized.
},
&Event::FundingSigned { ref channel_id, ref user_channel_id, ref funding_tx } => {
37u8.write(writer)?;
write_tlv_fields!(writer, {
(0, channel_id, required),
(2, user_channel_id, required),
(4, funding_tx, required),
});
},
// Note that, going forward, all new events must only write data inside of
// `write_tlv_fields`. Versions 0.0.101+ will ignore odd-numbered events that write
// data via `write_tlv_fields`.
Expand Down Expand Up @@ -1814,6 +1845,24 @@ impl MaybeReadable for Event {
},
// Note that we do not write a length-prefixed TLV for ConnectionNeeded events.
35u8 => Ok(None),
37u8 => {
let mut f = || {
let mut channel_id = ChannelId::new_zero();
let mut user_channel_id: u128 = 0;
let mut funding_tx = Transaction { version: 2, lock_time: LockTime::ZERO, input: Vec::new(), output: Vec::new() };
read_tlv_fields!(reader, {
(0, channel_id, required),
(2, user_channel_id, required),
(4, funding_tx, required),
});
Ok(Some(Event::FundingSigned {
channel_id,
user_channel_id,
funding_tx,
}))
};
f()
},
// Versions prior to 0.0.100 did not ignore odd types, instead returning InvalidValue.
// Version 0.0.100 failed to properly ignore odd types, possibly resulting in corrupt
// reads.
Expand Down

0 comments on commit cb5e32f

Please sign in to comment.