@@ -161,6 +161,16 @@ impl MsgHandleErrInternal {
161
161
}
162
162
}
163
163
#[ inline]
164
+ fn ignore_no_close ( err : & ' static str ) -> Self {
165
+ Self {
166
+ err : HandleError {
167
+ err,
168
+ action : Some ( msgs:: ErrorAction :: IgnoreError ) ,
169
+ } ,
170
+ shutdown_finish : None ,
171
+ }
172
+ }
173
+ #[ inline]
164
174
fn from_no_close ( err : msgs:: HandleError ) -> Self {
165
175
Self { err, shutdown_finish : None }
166
176
}
@@ -381,7 +391,7 @@ pub struct ChannelDetails {
381
391
}
382
392
383
393
macro_rules! handle_error {
384
- ( $self: ident, $internal: expr, $their_node_id : expr ) => {
394
+ ( $self: ident, $internal: expr) => {
385
395
match $internal {
386
396
Ok ( msg) => Ok ( msg) ,
387
397
Err ( MsgHandleErrInternal { err, shutdown_finish } ) => {
@@ -439,17 +449,10 @@ macro_rules! try_chan_entry {
439
449
}
440
450
441
451
macro_rules! return_monitor_err {
442
- ( $self: expr, $err: expr, $channel_state: expr, $entry: expr, $action_type: path) => {
443
- return_monitor_err!( $self, $err, $channel_state, $entry, $action_type, Vec :: new( ) , Vec :: new( ) )
444
- } ;
445
- ( $self: expr, $err: expr, $channel_state: expr, $entry: expr, $action_type: path, $raa_first_dropped_cs: expr) => {
446
- if $action_type != RAACommitmentOrder :: RevokeAndACKFirst { panic!( "Bad return_monitor_err call!" ) ; }
447
- return_monitor_err!( $self, $err, $channel_state, $entry, $action_type, Vec :: new( ) , Vec :: new( ) , $raa_first_dropped_cs)
452
+ ( $self: ident, $err: expr, $channel_state: expr, $entry: expr, $action_type: path, $resend_raa: expr, $resend_commitment: expr) => {
453
+ return_monitor_err!( $self, $err, $channel_state, $entry, $action_type, $resend_raa, $resend_commitment, Vec :: new( ) , Vec :: new( ) )
448
454
} ;
449
- ( $self: expr, $err: expr, $channel_state: expr, $entry: expr, $action_type: path, $failed_forwards: expr, $failed_fails: expr) => {
450
- return_monitor_err!( $self, $err, $channel_state, $entry, $action_type, $failed_forwards, $failed_fails, false )
451
- } ;
452
- ( $self: expr, $err: expr, $channel_state: expr, $entry: expr, $action_type: path, $failed_forwards: expr, $failed_fails: expr, $raa_first_dropped_cs: expr) => {
455
+ ( $self: ident, $err: expr, $channel_state: expr, $entry: expr, $action_type: path, $resend_raa: expr, $resend_commitment: expr, $failed_forwards: expr, $failed_fails: expr) => {
453
456
match $err {
454
457
ChannelMonitorUpdateErr :: PermanentFailure => {
455
458
let ( channel_id, mut chan) = $entry. remove_entry( ) ;
@@ -468,7 +471,7 @@ macro_rules! return_monitor_err {
468
471
return Err ( MsgHandleErrInternal :: from_finish_shutdown( "ChannelMonitor storage failure" , channel_id, chan. force_shutdown( ) , $self. get_channel_update( & chan) . ok( ) ) )
469
472
} ,
470
473
ChannelMonitorUpdateErr :: TemporaryFailure => {
471
- $entry. get_mut( ) . monitor_update_failed( $action_type, $failed_forwards , $failed_fails , $raa_first_dropped_cs ) ;
474
+ $entry. get_mut( ) . monitor_update_failed( $action_type, $resend_raa , $resend_commitment , $failed_forwards , $failed_fails ) ;
472
475
return Err ( MsgHandleErrInternal :: from_chan_no_close( ChannelError :: Ignore ( "Failed to update ChannelMonitor" ) , * $entry. key( ) ) ) ;
473
476
} ,
474
477
}
@@ -477,7 +480,7 @@ macro_rules! return_monitor_err {
477
480
478
481
// Does not break in case of TemporaryFailure!
479
482
macro_rules! maybe_break_monitor_err {
480
- ( $self: expr , $err: expr, $channel_state: expr, $entry: expr, $action_type: path) => {
483
+ ( $self: ident , $err: expr, $channel_state: expr, $entry: expr, $action_type: path, $resend_raa : expr , $resend_commitment : expr ) => {
481
484
match $err {
482
485
ChannelMonitorUpdateErr :: PermanentFailure => {
483
486
let ( channel_id, mut chan) = $entry. remove_entry( ) ;
@@ -487,7 +490,7 @@ macro_rules! maybe_break_monitor_err {
487
490
break Err ( MsgHandleErrInternal :: from_finish_shutdown( "ChannelMonitor storage failure" , channel_id, chan. force_shutdown( ) , $self. get_channel_update( & chan) . ok( ) ) )
488
491
} ,
489
492
ChannelMonitorUpdateErr :: TemporaryFailure => {
490
- $entry. get_mut( ) . monitor_update_failed( $action_type, Vec :: new( ) , Vec :: new( ) , false ) ;
493
+ $entry. get_mut( ) . monitor_update_failed( $action_type, $resend_raa , $resend_commitment , Vec :: new( ) , Vec :: new( ) ) ;
491
494
} ,
492
495
}
493
496
}
@@ -1018,7 +1021,7 @@ impl ChannelManager {
1018
1021
} {
1019
1022
Some ( ( update_add, commitment_signed, chan_monitor) ) => {
1020
1023
if let Err ( e) = self . monitor . add_update_monitor ( chan_monitor. get_funding_txo ( ) . unwrap ( ) , chan_monitor) {
1021
- maybe_break_monitor_err ! ( self , e, channel_state, chan, RAACommitmentOrder :: CommitmentFirst ) ;
1024
+ maybe_break_monitor_err ! ( self , e, channel_state, chan, RAACommitmentOrder :: CommitmentFirst , false , true ) ;
1022
1025
// Note that MonitorUpdateFailed here indicates (per function docs)
1023
1026
// that we will resent the commitment update once we unfree monitor
1024
1027
// updating, so we have to take special care that we don't return
@@ -1044,7 +1047,7 @@ impl ChannelManager {
1044
1047
return Ok ( ( ) ) ;
1045
1048
} ;
1046
1049
1047
- match handle_error ! ( self , err, route . hops . first ( ) . unwrap ( ) . pubkey ) {
1050
+ match handle_error ! ( self , err) {
1048
1051
Ok ( _) => unreachable ! ( ) ,
1049
1052
Err ( e) => {
1050
1053
if let Some ( msgs:: ErrorAction :: IgnoreError ) = e. action {
@@ -1087,7 +1090,7 @@ impl ChannelManager {
1087
1090
None => return
1088
1091
}
1089
1092
} ;
1090
- match handle_error ! ( self , res, chan . get_their_node_id ( ) ) {
1093
+ match handle_error ! ( self , res) {
1091
1094
Ok ( funding_msg) => {
1092
1095
( chan, funding_msg. 0 , funding_msg. 1 )
1093
1096
} ,
@@ -1962,7 +1965,7 @@ impl ChannelManager {
1962
1965
let ( revoke_and_ack, commitment_signed, closing_signed, chan_monitor) =
1963
1966
try_chan_entry ! ( self , chan. get_mut( ) . commitment_signed( & msg, & * self . fee_estimator) , channel_state, chan) ;
1964
1967
if let Err ( e) = self . monitor . add_update_monitor ( chan_monitor. get_funding_txo ( ) . unwrap ( ) , chan_monitor) {
1965
- return_monitor_err ! ( self , e, channel_state, chan, RAACommitmentOrder :: RevokeAndACKFirst , commitment_signed. is_some( ) ) ;
1968
+ return_monitor_err ! ( self , e, channel_state, chan, RAACommitmentOrder :: RevokeAndACKFirst , true , commitment_signed. is_some( ) ) ;
1966
1969
//TODO: Rebroadcast closing_signed if present on monitor update restoration
1967
1970
}
1968
1971
channel_state. pending_msg_events . push ( events:: MessageSendEvent :: SendRevokeAndACK {
@@ -2037,10 +2040,16 @@ impl ChannelManager {
2037
2040
//TODO: here and below MsgHandleErrInternal, #153 case
2038
2041
return Err ( MsgHandleErrInternal :: send_err_msg_no_close ( "Got a message for a channel from the wrong node!" , msg. channel_id ) ) ;
2039
2042
}
2043
+ let was_frozen_for_monitor = chan. get ( ) . is_awaiting_monitor_update ( ) ;
2040
2044
let ( commitment_update, pending_forwards, pending_failures, closing_signed, chan_monitor) =
2041
2045
try_chan_entry ! ( self , chan. get_mut( ) . revoke_and_ack( & msg, & * self . fee_estimator) , channel_state, chan) ;
2042
2046
if let Err ( e) = self . monitor . add_update_monitor ( chan_monitor. get_funding_txo ( ) . unwrap ( ) , chan_monitor) {
2043
- return_monitor_err ! ( self , e, channel_state, chan, RAACommitmentOrder :: CommitmentFirst , pending_forwards, pending_failures) ;
2047
+ if was_frozen_for_monitor {
2048
+ assert ! ( commitment_update. is_none( ) && closing_signed. is_none( ) && pending_forwards. is_empty( ) && pending_failures. is_empty( ) ) ;
2049
+ return Err ( MsgHandleErrInternal :: ignore_no_close ( "Previous monitor update failure prevented responses to RAA" ) ) ;
2050
+ } else {
2051
+ return_monitor_err ! ( self , e, channel_state, chan, RAACommitmentOrder :: CommitmentFirst , false , commitment_update. is_some( ) , pending_forwards, pending_failures) ;
2052
+ }
2044
2053
}
2045
2054
if let Some ( updates) = commitment_update {
2046
2055
channel_state. pending_msg_events . push ( events:: MessageSendEvent :: UpdateHTLCs {
@@ -2147,7 +2156,7 @@ impl ChannelManager {
2147
2156
if commitment_update. is_none ( ) {
2148
2157
order = RAACommitmentOrder :: RevokeAndACKFirst ;
2149
2158
}
2150
- return_monitor_err ! ( self , e, channel_state, chan, order) ;
2159
+ return_monitor_err ! ( self , e, channel_state, chan, order, revoke_and_ack . is_some ( ) , commitment_update . is_some ( ) ) ;
2151
2160
//TODO: Resend the funding_locked if needed once we get the monitor running again
2152
2161
}
2153
2162
}
@@ -2243,7 +2252,7 @@ impl ChannelManager {
2243
2252
return Ok ( ( ) )
2244
2253
} ;
2245
2254
2246
- match handle_error ! ( self , err, their_node_id ) {
2255
+ match handle_error ! ( self , err) {
2247
2256
Ok ( _) => unreachable ! ( ) ,
2248
2257
Err ( e) => {
2249
2258
if let Some ( msgs:: ErrorAction :: IgnoreError ) = e. action {
@@ -2429,82 +2438,82 @@ impl ChannelMessageHandler for ChannelManager {
2429
2438
//TODO: Handle errors and close channel (or so)
2430
2439
fn handle_open_channel ( & self , their_node_id : & PublicKey , msg : & msgs:: OpenChannel ) -> Result < ( ) , HandleError > {
2431
2440
let _ = self . total_consistency_lock . read ( ) . unwrap ( ) ;
2432
- handle_error ! ( self , self . internal_open_channel( their_node_id, msg) , their_node_id )
2441
+ handle_error ! ( self , self . internal_open_channel( their_node_id, msg) )
2433
2442
}
2434
2443
2435
2444
fn handle_accept_channel ( & self , their_node_id : & PublicKey , msg : & msgs:: AcceptChannel ) -> Result < ( ) , HandleError > {
2436
2445
let _ = self . total_consistency_lock . read ( ) . unwrap ( ) ;
2437
- handle_error ! ( self , self . internal_accept_channel( their_node_id, msg) , their_node_id )
2446
+ handle_error ! ( self , self . internal_accept_channel( their_node_id, msg) )
2438
2447
}
2439
2448
2440
2449
fn handle_funding_created ( & self , their_node_id : & PublicKey , msg : & msgs:: FundingCreated ) -> Result < ( ) , HandleError > {
2441
2450
let _ = self . total_consistency_lock . read ( ) . unwrap ( ) ;
2442
- handle_error ! ( self , self . internal_funding_created( their_node_id, msg) , their_node_id )
2451
+ handle_error ! ( self , self . internal_funding_created( their_node_id, msg) )
2443
2452
}
2444
2453
2445
2454
fn handle_funding_signed ( & self , their_node_id : & PublicKey , msg : & msgs:: FundingSigned ) -> Result < ( ) , HandleError > {
2446
2455
let _ = self . total_consistency_lock . read ( ) . unwrap ( ) ;
2447
- handle_error ! ( self , self . internal_funding_signed( their_node_id, msg) , their_node_id )
2456
+ handle_error ! ( self , self . internal_funding_signed( their_node_id, msg) )
2448
2457
}
2449
2458
2450
2459
fn handle_funding_locked ( & self , their_node_id : & PublicKey , msg : & msgs:: FundingLocked ) -> Result < ( ) , HandleError > {
2451
2460
let _ = self . total_consistency_lock . read ( ) . unwrap ( ) ;
2452
- handle_error ! ( self , self . internal_funding_locked( their_node_id, msg) , their_node_id )
2461
+ handle_error ! ( self , self . internal_funding_locked( their_node_id, msg) )
2453
2462
}
2454
2463
2455
2464
fn handle_shutdown ( & self , their_node_id : & PublicKey , msg : & msgs:: Shutdown ) -> Result < ( ) , HandleError > {
2456
2465
let _ = self . total_consistency_lock . read ( ) . unwrap ( ) ;
2457
- handle_error ! ( self , self . internal_shutdown( their_node_id, msg) , their_node_id )
2466
+ handle_error ! ( self , self . internal_shutdown( their_node_id, msg) )
2458
2467
}
2459
2468
2460
2469
fn handle_closing_signed ( & self , their_node_id : & PublicKey , msg : & msgs:: ClosingSigned ) -> Result < ( ) , HandleError > {
2461
2470
let _ = self . total_consistency_lock . read ( ) . unwrap ( ) ;
2462
- handle_error ! ( self , self . internal_closing_signed( their_node_id, msg) , their_node_id )
2471
+ handle_error ! ( self , self . internal_closing_signed( their_node_id, msg) )
2463
2472
}
2464
2473
2465
2474
fn handle_update_add_htlc ( & self , their_node_id : & PublicKey , msg : & msgs:: UpdateAddHTLC ) -> Result < ( ) , msgs:: HandleError > {
2466
2475
let _ = self . total_consistency_lock . read ( ) . unwrap ( ) ;
2467
- handle_error ! ( self , self . internal_update_add_htlc( their_node_id, msg) , their_node_id )
2476
+ handle_error ! ( self , self . internal_update_add_htlc( their_node_id, msg) )
2468
2477
}
2469
2478
2470
2479
fn handle_update_fulfill_htlc ( & self , their_node_id : & PublicKey , msg : & msgs:: UpdateFulfillHTLC ) -> Result < ( ) , HandleError > {
2471
2480
let _ = self . total_consistency_lock . read ( ) . unwrap ( ) ;
2472
- handle_error ! ( self , self . internal_update_fulfill_htlc( their_node_id, msg) , their_node_id )
2481
+ handle_error ! ( self , self . internal_update_fulfill_htlc( their_node_id, msg) )
2473
2482
}
2474
2483
2475
2484
fn handle_update_fail_htlc ( & self , their_node_id : & PublicKey , msg : & msgs:: UpdateFailHTLC ) -> Result < ( ) , HandleError > {
2476
2485
let _ = self . total_consistency_lock . read ( ) . unwrap ( ) ;
2477
- handle_error ! ( self , self . internal_update_fail_htlc( their_node_id, msg) , their_node_id )
2486
+ handle_error ! ( self , self . internal_update_fail_htlc( their_node_id, msg) )
2478
2487
}
2479
2488
2480
2489
fn handle_update_fail_malformed_htlc ( & self , their_node_id : & PublicKey , msg : & msgs:: UpdateFailMalformedHTLC ) -> Result < ( ) , HandleError > {
2481
2490
let _ = self . total_consistency_lock . read ( ) . unwrap ( ) ;
2482
- handle_error ! ( self , self . internal_update_fail_malformed_htlc( their_node_id, msg) , their_node_id )
2491
+ handle_error ! ( self , self . internal_update_fail_malformed_htlc( their_node_id, msg) )
2483
2492
}
2484
2493
2485
2494
fn handle_commitment_signed ( & self , their_node_id : & PublicKey , msg : & msgs:: CommitmentSigned ) -> Result < ( ) , HandleError > {
2486
2495
let _ = self . total_consistency_lock . read ( ) . unwrap ( ) ;
2487
- handle_error ! ( self , self . internal_commitment_signed( their_node_id, msg) , their_node_id )
2496
+ handle_error ! ( self , self . internal_commitment_signed( their_node_id, msg) )
2488
2497
}
2489
2498
2490
2499
fn handle_revoke_and_ack ( & self , their_node_id : & PublicKey , msg : & msgs:: RevokeAndACK ) -> Result < ( ) , HandleError > {
2491
2500
let _ = self . total_consistency_lock . read ( ) . unwrap ( ) ;
2492
- handle_error ! ( self , self . internal_revoke_and_ack( their_node_id, msg) , their_node_id )
2501
+ handle_error ! ( self , self . internal_revoke_and_ack( their_node_id, msg) )
2493
2502
}
2494
2503
2495
2504
fn handle_update_fee ( & self , their_node_id : & PublicKey , msg : & msgs:: UpdateFee ) -> Result < ( ) , HandleError > {
2496
2505
let _ = self . total_consistency_lock . read ( ) . unwrap ( ) ;
2497
- handle_error ! ( self , self . internal_update_fee( their_node_id, msg) , their_node_id )
2506
+ handle_error ! ( self , self . internal_update_fee( their_node_id, msg) )
2498
2507
}
2499
2508
2500
2509
fn handle_announcement_signatures ( & self , their_node_id : & PublicKey , msg : & msgs:: AnnouncementSignatures ) -> Result < ( ) , HandleError > {
2501
2510
let _ = self . total_consistency_lock . read ( ) . unwrap ( ) ;
2502
- handle_error ! ( self , self . internal_announcement_signatures( their_node_id, msg) , their_node_id )
2511
+ handle_error ! ( self , self . internal_announcement_signatures( their_node_id, msg) )
2503
2512
}
2504
2513
2505
2514
fn handle_channel_reestablish ( & self , their_node_id : & PublicKey , msg : & msgs:: ChannelReestablish ) -> Result < ( ) , HandleError > {
2506
2515
let _ = self . total_consistency_lock . read ( ) . unwrap ( ) ;
2507
- handle_error ! ( self , self . internal_channel_reestablish( their_node_id, msg) , their_node_id )
2516
+ handle_error ! ( self , self . internal_channel_reestablish( their_node_id, msg) )
2508
2517
}
2509
2518
2510
2519
fn peer_disconnected ( & self , their_node_id : & PublicKey , no_connection_possible : bool ) {
0 commit comments