@@ -135,9 +135,13 @@ pub(super) use self::channel_held_info::*;
135
135
136
136
type ShutdownResult = ( Vec < Transaction > , Vec < ( HTLCSource , [ u8 ; 32 ] ) > ) ;
137
137
138
+ /// Error type returned across the channel_state mutex boundary. When an Err is generated for a
139
+ /// Channel, we generally end up with a ChannelError::Close for which we have to close the channel
140
+ /// immediately (ie with no further calls on it made). Thus, this step happens inside a
141
+ /// channel_state lock. We then return the set of things that need to be done outside the lock in
142
+ /// this struct and call handle_error!() on it.
138
143
struct MsgHandleErrInternal {
139
144
err : msgs:: HandleError ,
140
- needs_channel_force_close : bool ,
141
145
shutdown_finish : Option < ( ShutdownResult , Option < msgs:: ChannelUpdate > ) > ,
142
146
}
143
147
impl MsgHandleErrInternal {
@@ -153,29 +157,12 @@ impl MsgHandleErrInternal {
153
157
} ,
154
158
} ) ,
155
159
} ,
156
- needs_channel_force_close : false ,
157
- shutdown_finish : None ,
158
- }
159
- }
160
- #[ inline]
161
- fn send_err_msg_close_chan ( err : & ' static str , channel_id : [ u8 ; 32 ] ) -> Self {
162
- Self {
163
- err : HandleError {
164
- err,
165
- action : Some ( msgs:: ErrorAction :: SendErrorMessage {
166
- msg : msgs:: ErrorMessage {
167
- channel_id,
168
- data : err. to_string ( )
169
- } ,
170
- } ) ,
171
- } ,
172
- needs_channel_force_close : true ,
173
160
shutdown_finish : None ,
174
161
}
175
162
}
176
163
#[ inline]
177
164
fn from_no_close ( err : msgs:: HandleError ) -> Self {
178
- Self { err, needs_channel_force_close : false , shutdown_finish : None }
165
+ Self { err, shutdown_finish : None }
179
166
}
180
167
#[ inline]
181
168
fn from_finish_shutdown ( err : & ' static str , channel_id : [ u8 ; 32 ] , shutdown_res : ShutdownResult , channel_update : Option < msgs:: ChannelUpdate > ) -> Self {
@@ -189,7 +176,6 @@ impl MsgHandleErrInternal {
189
176
} ,
190
177
} ) ,
191
178
} ,
192
- needs_channel_force_close : false ,
193
179
shutdown_finish : Some ( ( shutdown_res, channel_update) ) ,
194
180
}
195
181
}
@@ -211,7 +197,6 @@ impl MsgHandleErrInternal {
211
197
} ) ,
212
198
} ,
213
199
} ,
214
- needs_channel_force_close : false ,
215
200
shutdown_finish : None ,
216
201
}
217
202
}
@@ -405,28 +390,7 @@ macro_rules! handle_error {
405
390
( $self: ident, $internal: expr, $their_node_id: expr) => {
406
391
match $internal {
407
392
Ok ( msg) => Ok ( msg) ,
408
- Err ( MsgHandleErrInternal { err, needs_channel_force_close, shutdown_finish } ) => {
409
- if needs_channel_force_close {
410
- match & err. action {
411
- & Some ( msgs:: ErrorAction :: DisconnectPeer { msg: Some ( ref msg) } ) => {
412
- if msg. channel_id == [ 0 ; 32 ] {
413
- $self. peer_disconnected( & $their_node_id, true ) ;
414
- } else {
415
- $self. force_close_channel( & msg. channel_id) ;
416
- }
417
- } ,
418
- & Some ( msgs:: ErrorAction :: DisconnectPeer { msg: None } ) => { } ,
419
- & Some ( msgs:: ErrorAction :: IgnoreError ) => { } ,
420
- & Some ( msgs:: ErrorAction :: SendErrorMessage { ref msg } ) => {
421
- if msg. channel_id == [ 0 ; 32 ] {
422
- $self. peer_disconnected( & $their_node_id, true ) ;
423
- } else {
424
- $self. force_close_channel( & msg. channel_id) ;
425
- }
426
- } ,
427
- & None => { } ,
428
- }
429
- }
393
+ Err ( MsgHandleErrInternal { err, shutdown_finish } ) => {
430
394
if let Some ( ( shutdown_res, update_option) ) = shutdown_finish {
431
395
$self. finish_force_close_channel( shutdown_res) ;
432
396
if let Some ( update) = update_option {
@@ -2301,7 +2265,7 @@ impl ChannelManager {
2301
2265
return Err ( MsgHandleErrInternal :: send_err_msg_no_close ( "Got a message for a channel from the wrong node!" , msg. channel_id ) ) ;
2302
2266
}
2303
2267
if ( msg. failure_code & 0x8000 ) == 0 {
2304
- return Err ( MsgHandleErrInternal :: send_err_msg_close_chan ( "Got update_fail_malformed_htlc with BADONION not set" , msg . channel_id ) ) ;
2268
+ try_chan_entry ! ( self , Err ( ChannelError :: Close ( "Got update_fail_malformed_htlc with BADONION not set" ) ) , channel_state , chan ) ;
2305
2269
}
2306
2270
try_chan_entry ! ( self , chan. get_mut( ) . update_fail_malformed_htlc( & msg, HTLCFailReason :: Reason { failure_code: msg. failure_code, data: Vec :: new( ) } ) , channel_state, chan) ;
2307
2271
Ok ( ( ) )
@@ -2461,9 +2425,10 @@ impl ChannelManager {
2461
2425
2462
2426
let were_node_one = announcement. node_id_1 == our_node_id;
2463
2427
let msghash = Message :: from_slice ( & Sha256dHash :: from_data ( & announcement. encode ( ) [ ..] ) [ ..] ) . unwrap ( ) ;
2464
- let bad_sig_action = MsgHandleErrInternal :: send_err_msg_close_chan ( "Bad announcement_signatures node_signature" , msg. channel_id ) ;
2465
- secp_call ! ( self . secp_ctx. verify( & msghash, & msg. node_signature, if were_node_one { & announcement. node_id_2 } else { & announcement. node_id_1 } ) , bad_sig_action) ;
2466
- secp_call ! ( self . secp_ctx. verify( & msghash, & msg. bitcoin_signature, if were_node_one { & announcement. bitcoin_key_2 } else { & announcement. bitcoin_key_1 } ) , bad_sig_action) ;
2428
+ if self . secp_ctx . verify ( & msghash, & msg. node_signature , if were_node_one { & announcement. node_id_2 } else { & announcement. node_id_1 } ) . is_err ( ) ||
2429
+ self . secp_ctx . verify ( & msghash, & msg. bitcoin_signature , if were_node_one { & announcement. bitcoin_key_2 } else { & announcement. bitcoin_key_1 } ) . is_err ( ) {
2430
+ try_chan_entry ! ( self , Err ( ChannelError :: Close ( "Bad announcement_signatures node_signature" ) ) , channel_state, chan) ;
2431
+ }
2467
2432
2468
2433
let our_node_sig = self . secp_ctx . sign ( & msghash, & self . our_network_key ) ;
2469
2434
0 commit comments