@@ -736,6 +736,9 @@ pub(super) struct Channel<Signer: Sign> {
736736 // don't currently support node id aliases and eventually privacy should be provided with
737737 // blinded paths instead of simple scid+node_id aliases.
738738 outbound_scid_alias : u64 ,
739+
740+ // We track whether we already emitted a `ChannelReady` event.
741+ channel_ready_event_emitted : bool ,
739742}
740743
741744#[ cfg( any( test, fuzzing) ) ]
@@ -1063,6 +1066,8 @@ impl<Signer: Sign> Channel<Signer> {
10631066 latest_inbound_scid_alias : None ,
10641067 outbound_scid_alias,
10651068
1069+ channel_ready_event_emitted : false ,
1070+
10661071 #[ cfg( any( test, fuzzing) ) ]
10671072 historical_inbound_htlc_fulfills : HashSet :: new ( ) ,
10681073
@@ -1397,6 +1402,8 @@ impl<Signer: Sign> Channel<Signer> {
13971402 latest_inbound_scid_alias : None ,
13981403 outbound_scid_alias,
13991404
1405+ channel_ready_event_emitted : false ,
1406+
14001407 #[ cfg( any( test, fuzzing) ) ]
14011408 historical_inbound_htlc_fulfills : HashSet :: new ( ) ,
14021409
@@ -4598,6 +4605,16 @@ impl<Signer: Sign> Channel<Signer> {
45984605 self . prev_config . map ( |prev_config| prev_config. 0 )
45994606 }
46004607
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+
46014618 /// Tracks the number of ticks elapsed since the previous [`ChannelConfig`] was updated. Once
46024619 /// [`EXPIRE_PREV_CONFIG_TICKS`] is reached, the previous config is considered expired and will
46034620 /// no longer be considered when forwarding HTLCs.
@@ -6230,6 +6247,8 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
62306247 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)
62316248 { Some ( self . holder_max_htlc_value_in_flight_msat ) } else { None } ;
62326249
6250+ let channel_ready_event_emitted = Some ( self . channel_ready_event_emitted ) ;
6251+
62336252 write_tlv_fields ! ( writer, {
62346253 ( 0 , self . announcement_sigs, option) ,
62356254 // minimum_depth and counterparty_selected_channel_reserve_satoshis used to have a
@@ -6252,6 +6271,7 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
62526271 ( 17 , self . announcement_sigs_state, required) ,
62536272 ( 19 , self . latest_inbound_scid_alias, option) ,
62546273 ( 21 , self . outbound_scid_alias, required) ,
6274+ ( 23 , channel_ready_event_emitted, option) ,
62556275 } ) ;
62566276
62576277 Ok ( ( ) )
@@ -6509,6 +6529,7 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
65096529 let mut announcement_sigs_state = Some ( AnnouncementSigsState :: NotSent ) ;
65106530 let mut latest_inbound_scid_alias = None ;
65116531 let mut outbound_scid_alias = None ;
6532+ let mut channel_ready_event_emitted = None ;
65126533
65136534 read_tlv_fields ! ( reader, {
65146535 ( 0 , announcement_sigs, option) ,
@@ -6526,6 +6547,7 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
65266547 ( 17 , announcement_sigs_state, option) ,
65276548 ( 19 , latest_inbound_scid_alias, option) ,
65286549 ( 21 , outbound_scid_alias, option) ,
6550+ ( 23 , channel_ready_event_emitted, option) ,
65296551 } ) ;
65306552
65316553 if let Some ( preimages) = preimages_opt {
@@ -6666,6 +6688,8 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
66666688 // Later in the ChannelManager deserialization phase we scan for channels and assign scid aliases if its missing
66676689 outbound_scid_alias : outbound_scid_alias. unwrap_or ( 0 ) ,
66686690
6691+ channel_ready_event_emitted : channel_ready_event_emitted. unwrap_or ( false ) ,
6692+
66696693 #[ cfg( any( test, fuzzing) ) ]
66706694 historical_inbound_htlc_fulfills,
66716695
0 commit comments