@@ -52,6 +52,28 @@ use core::ops::Deref;
52
52
use crate :: sync:: Mutex ;
53
53
use bitcoin:: hashes:: hex:: ToHex ;
54
54
55
+ pub ( crate ) enum ChannelReadyStatus {
56
+ ReadyToSend ( msgs:: ChannelReady ) ,
57
+ PendingChannelReady ,
58
+ NotReady
59
+ }
60
+
61
+ impl ChannelReadyStatus {
62
+ pub fn is_ready ( & self ) -> bool {
63
+ match self {
64
+ ChannelReadyStatus :: ReadyToSend ( _) => true ,
65
+ _ => false ,
66
+ }
67
+ }
68
+
69
+ pub fn is_pending_channel_ready ( & self ) -> bool {
70
+ match self {
71
+ ChannelReadyStatus :: PendingChannelReady => true ,
72
+ _ => false ,
73
+ }
74
+ }
75
+ }
76
+
55
77
#[ cfg( test) ]
56
78
pub struct ChannelValueStat {
57
79
pub value_to_self_msat : u64 ,
@@ -2379,7 +2401,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
2379
2401
2380
2402
log_info ! ( logger, "Generated funding_signed for peer for channel {}" , log_bytes!( self . channel_id( ) ) ) ;
2381
2403
2382
- let need_channel_ready = self . check_get_channel_ready ( 0 ) . 0 . is_some ( ) ;
2404
+ let need_channel_ready = self . check_get_channel_ready ( 0 ) . is_ready ( ) ;
2383
2405
self . monitor_updating_paused ( false , false , need_channel_ready, Vec :: new ( ) , Vec :: new ( ) , Vec :: new ( ) ) ;
2384
2406
2385
2407
Ok ( ( msgs:: FundingSigned {
@@ -2467,7 +2489,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
2467
2489
2468
2490
log_info ! ( logger, "Received funding_signed from peer for channel {}" , log_bytes!( self . channel_id( ) ) ) ;
2469
2491
2470
- let need_channel_ready = self . check_get_channel_ready ( 0 ) . 0 . is_some ( ) ;
2492
+ let need_channel_ready = self . check_get_channel_ready ( 0 ) . is_ready ( ) ;
2471
2493
self . monitor_updating_paused ( false , false , need_channel_ready, Vec :: new ( ) , Vec :: new ( ) , Vec :: new ( ) ) ;
2472
2494
Ok ( channel_monitor)
2473
2495
}
@@ -5014,12 +5036,12 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
5014
5036
self . channel_update_status = status;
5015
5037
}
5016
5038
5017
- pub fn check_get_channel_ready ( & mut self , height : u32 ) -> ( Option < msgs :: ChannelReady > , bool ) {
5039
+ pub fn check_get_channel_ready ( & mut self , height : u32 ) -> ChannelReadyStatus {
5018
5040
// Called:
5019
5041
// * always when a new block/transactions are confirmed with the new height
5020
5042
// * when funding is signed with a height of 0
5021
5043
if self . funding_tx_confirmation_height == 0 && self . minimum_depth != Some ( 0 ) {
5022
- return ( None , false ) ;
5044
+ return ChannelReadyStatus :: NotReady ;
5023
5045
}
5024
5046
5025
5047
let funding_tx_confirmations = height as i64 - self . funding_tx_confirmation_height as i64 + 1 ;
@@ -5028,11 +5050,11 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
5028
5050
}
5029
5051
5030
5052
if funding_tx_confirmations < self . minimum_depth . unwrap_or ( 0 ) as i64 {
5031
- return ( None , false ) ;
5053
+ return ChannelReadyStatus :: NotReady ;
5032
5054
}
5033
5055
5034
5056
if self . should_emit_pending_channel_ready_event ( ) {
5035
- return ( None , true ) ;
5057
+ return ChannelReadyStatus :: PendingChannelReady ;
5036
5058
}
5037
5059
5038
5060
let non_shutdown_state = self . channel_state & ( !MULTI_STATE_FLAGS ) ;
@@ -5066,17 +5088,17 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
5066
5088
if self . channel_state & ( ChannelState :: PeerDisconnected as u32 ) == 0 {
5067
5089
let next_per_commitment_point =
5068
5090
self . holder_signer . get_per_commitment_point ( INITIAL_COMMITMENT_NUMBER - 1 , & self . secp_ctx ) ;
5069
- return ( Some ( msgs:: ChannelReady {
5091
+ return ChannelReadyStatus :: ReadyToSend ( msgs:: ChannelReady {
5070
5092
channel_id : self . channel_id ,
5071
5093
next_per_commitment_point,
5072
5094
short_channel_id_alias : Some ( self . outbound_scid_alias ) ,
5073
- } ) , false ) ;
5095
+ } ) ;
5074
5096
}
5075
5097
} else {
5076
5098
self . monitor_pending_channel_ready = true ;
5077
5099
}
5078
5100
}
5079
- ( None , false )
5101
+ ChannelReadyStatus :: NotReady
5080
5102
}
5081
5103
5082
5104
/// When a transaction is confirmed, we check whether it is or spends the funding transaction
@@ -5133,24 +5155,26 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
5133
5155
// If we allow 1-conf funding, we may need to check for channel_ready here and
5134
5156
// send it immediately instead of waiting for a best_block_updated call (which
5135
5157
// may have already happened for this block).
5136
- let ( channel_ready_opt, generate_pending_channel_ready) = self . check_get_channel_ready ( height) ;
5137
-
5138
- if let Some ( channel_ready) = channel_ready_opt {
5139
- log_info ! ( logger, "Sending a channel_ready to our peer for channel {}" , log_bytes!( self . channel_id) ) ;
5140
- let announcement_sigs = self . get_announcement_sigs ( node_signer, genesis_block_hash, user_config, height, logger) ;
5141
- return Ok ( ChainActionUpdates {
5142
- channel_ready_msg : Some ( channel_ready) ,
5143
- announcement_sigs,
5144
- timed_out_htlcs : vec ! [ ] ,
5145
- pending_channel_ready : false
5146
- } ) ;
5147
- } else if generate_pending_channel_ready {
5148
- return Ok ( ChainActionUpdates {
5149
- channel_ready_msg : None ,
5150
- announcement_sigs : None ,
5151
- timed_out_htlcs : vec ! [ ] ,
5152
- pending_channel_ready : true
5153
- } ) ;
5158
+ match self . check_get_channel_ready ( height) {
5159
+ ChannelReadyStatus :: ReadyToSend ( channel_ready) => {
5160
+ log_info ! ( logger, "Sending a channel_ready to our peer for channel {}" , log_bytes!( self . channel_id) ) ;
5161
+ let announcement_sigs = self . get_announcement_sigs ( node_signer, genesis_block_hash, user_config, height, logger) ;
5162
+ return Ok ( ChainActionUpdates {
5163
+ channel_ready_msg : Some ( channel_ready) ,
5164
+ announcement_sigs,
5165
+ timed_out_htlcs : vec ! [ ] ,
5166
+ pending_channel_ready : false
5167
+ } ) ;
5168
+ } ,
5169
+ ChannelReadyStatus :: PendingChannelReady => {
5170
+ return Ok ( ChainActionUpdates {
5171
+ channel_ready_msg : None ,
5172
+ announcement_sigs : None ,
5173
+ timed_out_htlcs : vec ! [ ] ,
5174
+ pending_channel_ready : true
5175
+ } ) ;
5176
+ } ,
5177
+ ChannelReadyStatus :: NotReady => { }
5154
5178
}
5155
5179
}
5156
5180
for inp in tx. input . iter ( ) {
@@ -5213,8 +5237,9 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
5213
5237
5214
5238
self . update_time_counter = cmp:: max ( self . update_time_counter , highest_header_time) ;
5215
5239
5216
- let ( channel_ready_opt, generate_pending_channel_ready) = self . check_get_channel_ready ( height) ;
5217
- if let Some ( channel_ready) = channel_ready_opt {
5240
+ let channel_ready_status = self . check_get_channel_ready ( height) ;
5241
+
5242
+ if let ChannelReadyStatus :: ReadyToSend ( channel_ready) = channel_ready_status {
5218
5243
let announcement_sigs = if let Some ( ( genesis_block_hash, node_signer, user_config) ) = genesis_node_signer {
5219
5244
self . get_announcement_sigs ( node_signer, genesis_block_hash, user_config, height, logger)
5220
5245
} else { None } ;
@@ -5268,7 +5293,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
5268
5293
channel_ready_msg : None ,
5269
5294
timed_out_htlcs,
5270
5295
announcement_sigs,
5271
- pending_channel_ready : generate_pending_channel_ready
5296
+ pending_channel_ready : channel_ready_status . is_pending_channel_ready ( )
5272
5297
} )
5273
5298
}
5274
5299
0 commit comments