@@ -78,7 +78,8 @@ pub struct AvailableBalances {
78
78
pub ( crate ) struct ChainActionUpdates {
79
79
pub ( crate ) channel_ready_msg : Option < msgs:: ChannelReady > ,
80
80
pub ( crate ) timed_out_htlcs : Vec < ( HTLCSource , PaymentHash ) > ,
81
- pub ( crate ) announcement_sigs : Option < msgs:: AnnouncementSignatures >
81
+ pub ( crate ) announcement_sigs : Option < msgs:: AnnouncementSignatures > ,
82
+ pub ( crate ) pending_channel_ready : bool
82
83
}
83
84
84
85
impl ChainActionUpdates {
@@ -87,6 +88,7 @@ impl ChainActionUpdates {
87
88
channel_ready_msg : None ,
88
89
timed_out_htlcs : Vec :: new ( ) ,
89
90
announcement_sigs : None ,
91
+ pending_channel_ready : false ,
90
92
}
91
93
}
92
94
}
@@ -755,6 +757,8 @@ pub(super) struct Channel<Signer: ChannelSigner> {
755
757
756
758
// We track whether we already emitted a `ChannelReady` event.
757
759
channel_ready_event_emitted : bool ,
760
+ // We track whether we already emitted a `PendingChannelReady` event.
761
+ pending_channel_ready_event_emitted : bool ,
758
762
759
763
/// The unique identifier used to re-derive the private key material for the channel through
760
764
/// [`SignerProvider::derive_channel_signer`].
@@ -1129,6 +1133,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
1129
1133
outbound_scid_alias,
1130
1134
1131
1135
channel_ready_event_emitted : false ,
1136
+ pending_channel_ready_event_emitted : false ,
1132
1137
1133
1138
#[ cfg( any( test, fuzzing) ) ]
1134
1139
historical_inbound_htlc_fulfills : HashSet :: new ( ) ,
@@ -1478,6 +1483,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
1478
1483
outbound_scid_alias,
1479
1484
1480
1485
channel_ready_event_emitted : false ,
1486
+ pending_channel_ready_event_emitted : false ,
1481
1487
1482
1488
#[ cfg( any( test, fuzzing) ) ]
1483
1489
historical_inbound_htlc_fulfills : HashSet :: new ( ) ,
@@ -2373,7 +2379,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
2373
2379
2374
2380
log_info ! ( logger, "Generated funding_signed for peer for channel {}" , log_bytes!( self . channel_id( ) ) ) ;
2375
2381
2376
- let need_channel_ready = self . check_get_channel_ready ( 0 ) . is_some ( ) ;
2382
+ let need_channel_ready = self . check_get_channel_ready ( 0 ) . 0 . is_some ( ) ;
2377
2383
self . monitor_updating_paused ( false , false , need_channel_ready, Vec :: new ( ) , Vec :: new ( ) , Vec :: new ( ) ) ;
2378
2384
2379
2385
Ok ( ( msgs:: FundingSigned {
@@ -2461,7 +2467,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
2461
2467
2462
2468
log_info ! ( logger, "Received funding_signed from peer for channel {}" , log_bytes!( self . channel_id( ) ) ) ;
2463
2469
2464
- let need_channel_ready = self . check_get_channel_ready ( 0 ) . is_some ( ) ;
2470
+ let need_channel_ready = self . check_get_channel_ready ( 0 ) . 0 . is_some ( ) ;
2465
2471
self . monitor_updating_paused ( false , false , need_channel_ready, Vec :: new ( ) , Vec :: new ( ) , Vec :: new ( ) ) ;
2466
2472
Ok ( channel_monitor)
2467
2473
}
@@ -4730,6 +4736,16 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
4730
4736
self . channel_ready_event_emitted = true ;
4731
4737
}
4732
4738
4739
+ // Checks whether we should emit a `PendingChannelReady` event.
4740
+ pub ( crate ) fn should_emit_pending_channel_ready_event ( & self ) -> bool {
4741
+ self . requires_manual_readiness_signal && !self . pending_channel_ready_event_emitted
4742
+ }
4743
+
4744
+ // Remembers that we already emitted a `PendingChannelReady` event.
4745
+ pub ( crate ) fn set_pending_channel_ready_event_emitted ( & mut self ) {
4746
+ self . pending_channel_ready_event_emitted = true ;
4747
+ }
4748
+
4733
4749
/// Tracks the number of ticks elapsed since the previous [`ChannelConfig`] was updated. Once
4734
4750
/// [`EXPIRE_PREV_CONFIG_TICKS`] is reached, the previous config is considered expired and will
4735
4751
/// no longer be considered when forwarding HTLCs.
@@ -4994,12 +5010,12 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
4994
5010
self . channel_update_status = status;
4995
5011
}
4996
5012
4997
- fn check_get_channel_ready ( & mut self , height : u32 ) -> Option < msgs:: ChannelReady > {
5013
+ fn check_get_channel_ready ( & mut self , height : u32 ) -> ( Option < msgs:: ChannelReady > , bool ) {
4998
5014
// Called:
4999
5015
// * always when a new block/transactions are confirmed with the new height
5000
5016
// * when funding is signed with a height of 0
5001
5017
if self . funding_tx_confirmation_height == 0 && self . minimum_depth != Some ( 0 ) {
5002
- return None ;
5018
+ return ( None , false ) ;
5003
5019
}
5004
5020
5005
5021
let funding_tx_confirmations = height as i64 - self . funding_tx_confirmation_height as i64 + 1 ;
@@ -5008,7 +5024,11 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
5008
5024
}
5009
5025
5010
5026
if funding_tx_confirmations < self . minimum_depth . unwrap_or ( 0 ) as i64 {
5011
- return None ;
5027
+ return ( None , false ) ;
5028
+ }
5029
+
5030
+ if self . should_emit_pending_channel_ready_event ( ) {
5031
+ return ( None , true ) ;
5012
5032
}
5013
5033
5014
5034
let non_shutdown_state = self . channel_state & ( !MULTI_STATE_FLAGS ) ;
@@ -5042,17 +5062,17 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
5042
5062
if self . channel_state & ( ChannelState :: PeerDisconnected as u32 ) == 0 {
5043
5063
let next_per_commitment_point =
5044
5064
self . holder_signer . get_per_commitment_point ( INITIAL_COMMITMENT_NUMBER - 1 , & self . secp_ctx ) ;
5045
- return Some ( msgs:: ChannelReady {
5065
+ return ( Some ( msgs:: ChannelReady {
5046
5066
channel_id : self . channel_id ,
5047
5067
next_per_commitment_point,
5048
5068
short_channel_id_alias : Some ( self . outbound_scid_alias ) ,
5049
- } ) ;
5069
+ } ) , false ) ;
5050
5070
}
5051
5071
} else {
5052
5072
self . monitor_pending_channel_ready = true ;
5053
5073
}
5054
5074
}
5055
- None
5075
+ ( None , false )
5056
5076
}
5057
5077
5058
5078
/// When a transaction is confirmed, we check whether it is or spends the funding transaction
@@ -5109,13 +5129,23 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
5109
5129
// If we allow 1-conf funding, we may need to check for channel_ready here and
5110
5130
// send it immediately instead of waiting for a best_block_updated call (which
5111
5131
// may have already happened for this block).
5112
- if let Some ( channel_ready) = self . check_get_channel_ready ( height) {
5132
+ let ( channel_ready_opt, generate_pending_channel_ready) = self . check_get_channel_ready ( height) ;
5133
+
5134
+ if let Some ( channel_ready) = channel_ready_opt {
5113
5135
log_info ! ( logger, "Sending a channel_ready to our peer for channel {}" , log_bytes!( self . channel_id) ) ;
5114
5136
let announcement_sigs = self . get_announcement_sigs ( node_signer, genesis_block_hash, user_config, height, logger) ;
5115
5137
return Ok ( ChainActionUpdates {
5116
5138
channel_ready_msg : Some ( channel_ready) ,
5117
5139
announcement_sigs,
5118
- timed_out_htlcs : vec ! [ ]
5140
+ timed_out_htlcs : vec ! [ ] ,
5141
+ pending_channel_ready : false
5142
+ } ) ;
5143
+ } else if generate_pending_channel_ready {
5144
+ return Ok ( ChainActionUpdates {
5145
+ channel_ready_msg : None ,
5146
+ announcement_sigs : None ,
5147
+ timed_out_htlcs : vec ! [ ] ,
5148
+ pending_channel_ready : true
5119
5149
} ) ;
5120
5150
}
5121
5151
}
@@ -5127,11 +5157,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
5127
5157
}
5128
5158
}
5129
5159
}
5130
- Ok ( ChainActionUpdates {
5131
- channel_ready_msg : None ,
5132
- announcement_sigs : None ,
5133
- timed_out_htlcs : vec ! [ ]
5134
- } )
5160
+ Ok ( ChainActionUpdates :: no_updates ( ) )
5135
5161
}
5136
5162
5137
5163
/// When a new block is connected, we check the height of the block against outbound holding
@@ -5183,15 +5209,17 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
5183
5209
5184
5210
self . update_time_counter = cmp:: max ( self . update_time_counter , highest_header_time) ;
5185
5211
5186
- if let Some ( channel_ready) = self . check_get_channel_ready ( height) {
5212
+ let ( channel_ready_opt, generate_pending_channel_ready) = self . check_get_channel_ready ( height) ;
5213
+ if let Some ( channel_ready) = channel_ready_opt {
5187
5214
let announcement_sigs = if let Some ( ( genesis_block_hash, node_signer, user_config) ) = genesis_node_signer {
5188
5215
self . get_announcement_sigs ( node_signer, genesis_block_hash, user_config, height, logger)
5189
5216
} else { None } ;
5190
5217
log_info ! ( logger, "Sending a channel_ready to our peer for channel {}" , log_bytes!( self . channel_id) ) ;
5191
5218
return Ok ( ChainActionUpdates {
5192
5219
channel_ready_msg : Some ( channel_ready) ,
5193
5220
timed_out_htlcs,
5194
- announcement_sigs
5221
+ announcement_sigs,
5222
+ pending_channel_ready : false
5195
5223
} ) ;
5196
5224
}
5197
5225
@@ -5235,7 +5263,8 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
5235
5263
Ok ( ChainActionUpdates {
5236
5264
channel_ready_msg : None ,
5237
5265
timed_out_htlcs,
5238
- announcement_sigs
5266
+ announcement_sigs,
5267
+ pending_channel_ready : generate_pending_channel_ready
5239
5268
} )
5240
5269
}
5241
5270
@@ -6467,6 +6496,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Writeable for Channel<Signer> {
6467
6496
{ Some ( self . holder_max_htlc_value_in_flight_msat ) } else { None } ;
6468
6497
6469
6498
let channel_ready_event_emitted = Some ( self . channel_ready_event_emitted ) ;
6499
+ let pending_channel_ready_event_emitted = Some ( self . pending_channel_ready_event_emitted ) ;
6470
6500
6471
6501
// `user_id` used to be a single u64 value. In order to remain backwards compatible with
6472
6502
// versions prior to 0.0.113, the u128 is serialized as two separate u64 values. Therefore,
@@ -6500,7 +6530,8 @@ impl<Signer: WriteableEcdsaChannelSigner> Writeable for Channel<Signer> {
6500
6530
( 23 , channel_ready_event_emitted, option) ,
6501
6531
( 25 , user_id_high_opt, option) ,
6502
6532
( 27 , self . channel_keys_id, required) ,
6503
- ( 29 , requires_manual_readiness_signal, option)
6533
+ ( 29 , requires_manual_readiness_signal, option) ,
6534
+ ( 31 , pending_channel_ready_event_emitted, option) ,
6504
6535
} ) ;
6505
6536
6506
6537
Ok ( ( ) )
@@ -6773,6 +6804,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
6773
6804
let mut user_id_high_opt: Option < u64 > = None ;
6774
6805
let mut channel_keys_id: Option < [ u8 ; 32 ] > = None ;
6775
6806
let mut requires_manual_readiness_signal: Option < bool > = Some ( false ) ;
6807
+ let mut pending_channel_ready_event_emitted = None ;
6776
6808
6777
6809
read_tlv_fields ! ( reader, {
6778
6810
( 0 , announcement_sigs, option) ,
@@ -6794,6 +6826,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
6794
6826
( 25 , user_id_high_opt, option) ,
6795
6827
( 27 , channel_keys_id, option) ,
6796
6828
( 29 , requires_manual_readiness_signal, option) ,
6829
+ ( 31 , pending_channel_ready_event_emitted, option) ,
6797
6830
} ) ;
6798
6831
6799
6832
let ( channel_keys_id, holder_signer) = if let Some ( channel_keys_id) = channel_keys_id {
@@ -6952,6 +6985,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
6952
6985
outbound_scid_alias : outbound_scid_alias. unwrap_or ( 0 ) ,
6953
6986
6954
6987
channel_ready_event_emitted : channel_ready_event_emitted. unwrap_or ( true ) ,
6988
+ pending_channel_ready_event_emitted : pending_channel_ready_event_emitted. unwrap_or ( true ) ,
6955
6989
6956
6990
#[ cfg( any( test, fuzzing) ) ]
6957
6991
historical_inbound_htlc_fulfills,
0 commit comments