@@ -736,6 +736,9 @@ pub(super) struct Channel<Signer: Sign> {
736
736
// don't currently support node id aliases and eventually privacy should be provided with
737
737
// blinded paths instead of simple scid+node_id aliases.
738
738
outbound_scid_alias : u64 ,
739
+
740
+ // We track whether we already emitted a `ChannelReady` event.
741
+ channel_ready_event_emitted : bool ,
739
742
}
740
743
741
744
#[ cfg( any( test, fuzzing) ) ]
@@ -1063,6 +1066,8 @@ impl<Signer: Sign> Channel<Signer> {
1063
1066
latest_inbound_scid_alias : None ,
1064
1067
outbound_scid_alias,
1065
1068
1069
+ channel_ready_event_emitted : false ,
1070
+
1066
1071
#[ cfg( any( test, fuzzing) ) ]
1067
1072
historical_inbound_htlc_fulfills : HashSet :: new ( ) ,
1068
1073
@@ -1397,6 +1402,8 @@ impl<Signer: Sign> Channel<Signer> {
1397
1402
latest_inbound_scid_alias : None ,
1398
1403
outbound_scid_alias,
1399
1404
1405
+ channel_ready_event_emitted : false ,
1406
+
1400
1407
#[ cfg( any( test, fuzzing) ) ]
1401
1408
historical_inbound_htlc_fulfills : HashSet :: new ( ) ,
1402
1409
@@ -4598,6 +4605,16 @@ impl<Signer: Sign> Channel<Signer> {
4598
4605
self . prev_config . map ( |prev_config| prev_config. 0 )
4599
4606
}
4600
4607
4608
+ // Checks whether we should emit a `ChannelReady` event.
4609
+ pub ( crate ) fn should_emit_channel_ready_event ( & mut self ) -> bool {
4610
+ self . is_usable ( ) && !self . channel_ready_event_emitted
4611
+ }
4612
+
4613
+ // Remembers that we already emitted a `ChannelReady` event.
4614
+ pub ( crate ) fn set_channel_ready_event_emitted ( & mut self ) {
4615
+ self . channel_ready_event_emitted = true ;
4616
+ }
4617
+
4601
4618
/// Tracks the number of ticks elapsed since the previous [`ChannelConfig`] was updated. Once
4602
4619
/// [`EXPIRE_PREV_CONFIG_TICKS`] is reached, the previous config is considered expired and will
4603
4620
/// no longer be considered when forwarding HTLCs.
@@ -6230,6 +6247,8 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
6230
6247
if self . holder_max_htlc_value_in_flight_msat != Self :: get_holder_max_htlc_value_in_flight_msat ( self . channel_value_satoshis , & old_max_in_flight_percent_config)
6231
6248
{ Some ( self . holder_max_htlc_value_in_flight_msat ) } else { None } ;
6232
6249
6250
+ let channel_ready_event_emitted = Some ( self . channel_ready_event_emitted ) ;
6251
+
6233
6252
write_tlv_fields ! ( writer, {
6234
6253
( 0 , self . announcement_sigs, option) ,
6235
6254
// minimum_depth and counterparty_selected_channel_reserve_satoshis used to have a
@@ -6252,6 +6271,7 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
6252
6271
( 17 , self . announcement_sigs_state, required) ,
6253
6272
( 19 , self . latest_inbound_scid_alias, option) ,
6254
6273
( 21 , self . outbound_scid_alias, required) ,
6274
+ ( 23 , channel_ready_event_emitted, option) ,
6255
6275
} ) ;
6256
6276
6257
6277
Ok ( ( ) )
@@ -6509,6 +6529,7 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
6509
6529
let mut announcement_sigs_state = Some ( AnnouncementSigsState :: NotSent ) ;
6510
6530
let mut latest_inbound_scid_alias = None ;
6511
6531
let mut outbound_scid_alias = None ;
6532
+ let mut channel_ready_event_emitted = None ;
6512
6533
6513
6534
read_tlv_fields ! ( reader, {
6514
6535
( 0 , announcement_sigs, option) ,
@@ -6526,6 +6547,7 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
6526
6547
( 17 , announcement_sigs_state, option) ,
6527
6548
( 19 , latest_inbound_scid_alias, option) ,
6528
6549
( 21 , outbound_scid_alias, option) ,
6550
+ ( 23 , channel_ready_event_emitted, option) ,
6529
6551
} ) ;
6530
6552
6531
6553
if let Some ( preimages) = preimages_opt {
@@ -6666,6 +6688,8 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
6666
6688
// Later in the ChannelManager deserialization phase we scan for channels and assign scid aliases if its missing
6667
6689
outbound_scid_alias : outbound_scid_alias. unwrap_or ( 0 ) ,
6668
6690
6691
+ channel_ready_event_emitted : channel_ready_event_emitted. unwrap_or ( false ) ,
6692
+
6669
6693
#[ cfg( any( test, fuzzing) ) ]
6670
6694
historical_inbound_htlc_fulfills,
6671
6695
0 commit comments