Skip to content

Commit c5cadfb

Browse files
committed
Add ChannelEstablished event
This adds a `ChannelEstablished` event that will be emitted as soon as a new channel becomes usable, i.e., after both sides have sent `channel_ready`.
1 parent 969574c commit c5cadfb

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

lightning/src/util/events.rs

+51
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,27 @@ pub enum Event {
505505
/// transaction.
506506
claim_from_onchain_tx: bool,
507507
},
508+
/// Used to indicate that a previously opened channel with the given `channel_id` is ready to
509+
/// be used. This event is emitted either when the funding transaction has been confirmed
510+
/// on-chain, or, in case of a 0conf channel, when both parties have confirmed the channel
511+
/// establishment.
512+
ChannelEstablished {
513+
/// The channel_id of the channel that is ready.
514+
channel_id: [u8; 32],
515+
/// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound
516+
/// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels if
517+
/// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
518+
/// `user_channel_id` will be 0 for an inbound channel.
519+
///
520+
/// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
521+
/// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
522+
/// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
523+
user_channel_id: u64,
524+
/// The node_id of the channel counterparty.
525+
counterparty_node_id: PublicKey,
526+
/// The features that this channel will operate with.
527+
channel_type: ChannelTypeFeatures,
528+
},
508529
/// Used to indicate that a previously opened channel with the given `channel_id` is in the
509530
/// process of closure.
510531
ChannelClosed {
@@ -753,6 +774,15 @@ impl Writeable for Event {
753774
(2, failed_next_destination, required),
754775
})
755776
},
777+
&Event::ChannelEstablished { ref channel_id, ref user_channel_id, ref counterparty_node_id, ref channel_type } => {
778+
27u8.write(writer)?;
779+
write_tlv_fields!(writer, {
780+
(0, channel_id, required),
781+
(1, user_channel_id, required),
782+
(2, counterparty_node_id, required),
783+
(3, channel_type, required),
784+
});
785+
},
756786
// Note that, going forward, all new events must only write data inside of
757787
// `write_tlv_fields`. Versions 0.0.101+ will ignore odd-numbered events that write
758788
// data via `write_tlv_fields`.
@@ -1033,6 +1063,27 @@ impl MaybeReadable for Event {
10331063
};
10341064
f()
10351065
},
1066+
27u8 => {
1067+
let f = || {
1068+
let mut channel_id = [0; 32];
1069+
let mut user_channel_id: u64 = 0;
1070+
let mut counterparty_node_id_opt = None;
1071+
let mut channel_type_opt = None;
1072+
read_tlv_fields!(reader, {
1073+
(0, channel_id, required),
1074+
(1, user_channel_id, required),
1075+
(2, counterparty_node_id_opt, option),
1076+
(3, channel_type_opt, option),
1077+
});
1078+
1079+
Ok(Some(Event::ChannelEstablished { channel_id,
1080+
user_channel_id,
1081+
counterparty_node_id: counterparty_node_id_opt.unwrap(),
1082+
channel_type: channel_type_opt.unwrap()
1083+
}))
1084+
};
1085+
f()
1086+
},
10361087
// Versions prior to 0.0.100 did not ignore odd types, instead returning InvalidValue.
10371088
// Version 0.0.100 failed to properly ignore odd types, possibly resulting in corrupt
10381089
// reads.

0 commit comments

Comments
 (0)