@@ -422,7 +422,7 @@ pub struct ChannelDetails {
422
422
}
423
423
424
424
macro_rules! handle_error {
425
- ( $self: ident, $internal: expr) => {
425
+ ( $self: ident, $internal: expr, $their_node_id : expr ) => {
426
426
match $internal {
427
427
Ok ( msg) => Ok ( msg) ,
428
428
Err ( MsgHandleErrInternal { err, shutdown_finish } ) => {
@@ -435,6 +435,10 @@ macro_rules! handle_error {
435
435
} ) ;
436
436
}
437
437
}
438
+ let mut channel_state = $self. channel_state. lock( ) . unwrap( ) ;
439
+ log_error!( $self, "Got Error because {}" , err. err) ;
440
+ channel_state. pending_msg_events. push( events:: MessageSendEvent :: HandleError { node_id: $their_node_id, action: err. action. clone( ) } ) ;
441
+ // Return error in case higher-API need one
438
442
Err ( err)
439
443
} ,
440
444
}
@@ -1140,20 +1144,9 @@ impl ChannelManager {
1140
1144
return Ok ( ( ) ) ;
1141
1145
} ;
1142
1146
1143
- match handle_error ! ( self , err) {
1147
+ match handle_error ! ( self , err, route . hops . first ( ) . unwrap ( ) . pubkey ) {
1144
1148
Ok ( _) => unreachable ! ( ) ,
1145
- Err ( e) => {
1146
- if let msgs:: ErrorAction :: IgnoreError = e. action {
1147
- } else {
1148
- log_error ! ( self , "Got bad keys: {}!" , e. err) ;
1149
- let mut channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
1150
- channel_state. pending_msg_events . push ( events:: MessageSendEvent :: HandleError {
1151
- node_id : route. hops . first ( ) . unwrap ( ) . pubkey ,
1152
- action : e. action ,
1153
- } ) ;
1154
- }
1155
- Err ( APIError :: ChannelUnavailable { err : e. err } )
1156
- } ,
1149
+ Err ( e) => { Err ( APIError :: ChannelUnavailable { err : e. err } ) }
1157
1150
}
1158
1151
}
1159
1152
@@ -1183,36 +1176,20 @@ impl ChannelManager {
1183
1176
None => return
1184
1177
}
1185
1178
} ;
1186
- match handle_error ! ( self , res) {
1179
+ match handle_error ! ( self , res, chan . get_their_node_id ( ) ) {
1187
1180
Ok ( funding_msg) => {
1188
1181
( chan, funding_msg. 0 , funding_msg. 1 )
1189
1182
} ,
1190
- Err ( e) => {
1191
- log_error ! ( self , "Got bad signatures: {}!" , e. err) ;
1192
- let mut channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
1193
- channel_state. pending_msg_events . push ( events:: MessageSendEvent :: HandleError {
1194
- node_id : chan. get_their_node_id ( ) ,
1195
- action : e. action ,
1196
- } ) ;
1197
- return ;
1198
- } ,
1183
+ Err ( _) => { return ; }
1199
1184
}
1200
1185
} ;
1201
1186
// Because we have exclusive ownership of the channel here we can release the channel_state
1202
1187
// lock before add_update_monitor
1203
1188
if let Err ( e) = self . monitor . add_update_monitor ( chan_monitor. get_funding_txo ( ) . unwrap ( ) , chan_monitor) {
1204
1189
match e {
1205
1190
ChannelMonitorUpdateErr :: PermanentFailure => {
1206
- match handle_error ! ( self , Err ( MsgHandleErrInternal :: from_finish_shutdown( "ChannelMonitor storage failure" , * temporary_channel_id, chan. force_shutdown( ) , None ) ) ) {
1207
- Err ( e) => {
1208
- log_error ! ( self , "Failed to store ChannelMonitor update for funding tx generation" ) ;
1209
- let mut channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
1210
- channel_state. pending_msg_events . push ( events:: MessageSendEvent :: HandleError {
1211
- node_id : chan. get_their_node_id ( ) ,
1212
- action : e. action ,
1213
- } ) ;
1214
- return ;
1215
- } ,
1191
+ match handle_error ! ( self , Err ( MsgHandleErrInternal :: from_finish_shutdown( "ChannelMonitor storage failure" , * temporary_channel_id, chan. force_shutdown( ) , None ) ) , chan. get_their_node_id( ) ) {
1192
+ Err ( _) => { return ; } ,
1216
1193
Ok ( ( ) ) => unreachable ! ( ) ,
1217
1194
}
1218
1195
} ,
@@ -1390,22 +1367,9 @@ impl ChannelManager {
1390
1367
} ,
1391
1368
ChannelError :: CloseDelayBroadcast { .. } => { panic ! ( "Wait is only generated on receipt of channel_reestablish, which is handled by try_chan_entry, we don't bother to support it here" ) ; }
1392
1369
} ;
1393
- match handle_error ! ( self , err) {
1370
+ match handle_error ! ( self , err, their_node_id ) {
1394
1371
Ok ( _) => unreachable ! ( ) ,
1395
- Err ( e) => {
1396
- match e. action {
1397
- msgs:: ErrorAction :: IgnoreError => { } ,
1398
- _ => {
1399
- log_error ! ( self , "Got bad keys: {}!" , e. err) ;
1400
- let mut channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
1401
- channel_state. pending_msg_events . push ( events:: MessageSendEvent :: HandleError {
1402
- node_id : their_node_id,
1403
- action : e. action ,
1404
- } ) ;
1405
- } ,
1406
- }
1407
- continue ;
1408
- } ,
1372
+ Err ( _) => { continue ; } ,
1409
1373
}
1410
1374
}
1411
1375
} ;
@@ -1463,18 +1427,9 @@ impl ChannelManager {
1463
1427
}
1464
1428
1465
1429
for ( their_node_id, err) in handle_errors. drain ( ..) {
1466
- match handle_error ! ( self , err) {
1430
+ match handle_error ! ( self , err, their_node_id ) {
1467
1431
Ok ( _) => { } ,
1468
- Err ( e) => {
1469
- if let msgs:: ErrorAction :: IgnoreError = e. action {
1470
- } else {
1471
- let mut channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
1472
- channel_state. pending_msg_events . push ( events:: MessageSendEvent :: HandleError {
1473
- node_id : their_node_id,
1474
- action : e. action ,
1475
- } ) ;
1476
- }
1477
- } ,
1432
+ Err ( _) => { }
1478
1433
}
1479
1434
}
1480
1435
@@ -1702,18 +1657,9 @@ impl ChannelManager {
1702
1657
return ;
1703
1658
} ;
1704
1659
1705
- match handle_error ! ( self , err) {
1660
+ match handle_error ! ( self , err, their_node_id ) {
1706
1661
Ok ( _) => { } ,
1707
- Err ( e) => {
1708
- if let msgs:: ErrorAction :: IgnoreError = e. action {
1709
- } else {
1710
- let mut channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
1711
- channel_state. pending_msg_events . push ( events:: MessageSendEvent :: HandleError {
1712
- node_id : their_node_id,
1713
- action : e. action ,
1714
- } ) ;
1715
- }
1716
- } ,
1662
+ Err ( _) => { } ,
1717
1663
}
1718
1664
}
1719
1665
@@ -2487,20 +2433,9 @@ impl ChannelManager {
2487
2433
return Ok ( ( ) )
2488
2434
} ;
2489
2435
2490
- match handle_error ! ( self , err) {
2436
+ match handle_error ! ( self , err, their_node_id ) {
2491
2437
Ok ( _) => unreachable ! ( ) ,
2492
- Err ( e) => {
2493
- if let msgs:: ErrorAction :: IgnoreError = e. action {
2494
- } else {
2495
- log_error ! ( self , "Got bad keys: {}!" , e. err) ;
2496
- let mut channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
2497
- channel_state. pending_msg_events . push ( events:: MessageSendEvent :: HandleError {
2498
- node_id : their_node_id,
2499
- action : e. action ,
2500
- } ) ;
2501
- }
2502
- Err ( APIError :: APIMisuseError { err : e. err } )
2503
- } ,
2438
+ Err ( e) => { Err ( APIError :: APIMisuseError { err : e. err } ) }
2504
2439
}
2505
2440
}
2506
2441
}
@@ -2671,84 +2606,84 @@ impl ChainListener for ChannelManager {
2671
2606
2672
2607
impl ChannelMessageHandler for ChannelManager {
2673
2608
//TODO: Handle errors and close channel (or so)
2674
- fn handle_open_channel ( & self , their_node_id : & PublicKey , their_local_features : LocalFeatures , msg : & msgs:: OpenChannel ) -> Result < ( ) , LightningError > {
2609
+ fn handle_open_channel ( & self , their_node_id : & PublicKey , their_local_features : LocalFeatures , msg : & msgs:: OpenChannel ) {
2675
2610
let _ = self . total_consistency_lock . read ( ) . unwrap ( ) ;
2676
- handle_error ! ( self , self . internal_open_channel( their_node_id, their_local_features, msg) )
2611
+ if let Err ( _ ) = handle_error ! ( self , self . internal_open_channel( their_node_id, their_local_features, msg) , * their_node_id ) { }
2677
2612
}
2678
2613
2679
- fn handle_accept_channel ( & self , their_node_id : & PublicKey , their_local_features : LocalFeatures , msg : & msgs:: AcceptChannel ) -> Result < ( ) , LightningError > {
2614
+ fn handle_accept_channel ( & self , their_node_id : & PublicKey , their_local_features : LocalFeatures , msg : & msgs:: AcceptChannel ) {
2680
2615
let _ = self . total_consistency_lock . read ( ) . unwrap ( ) ;
2681
- handle_error ! ( self , self . internal_accept_channel( their_node_id, their_local_features, msg) )
2616
+ if let Err ( _ ) = handle_error ! ( self , self . internal_accept_channel( their_node_id, their_local_features, msg) , * their_node_id ) { }
2682
2617
}
2683
2618
2684
- fn handle_funding_created ( & self , their_node_id : & PublicKey , msg : & msgs:: FundingCreated ) -> Result < ( ) , LightningError > {
2619
+ fn handle_funding_created ( & self , their_node_id : & PublicKey , msg : & msgs:: FundingCreated ) {
2685
2620
let _ = self . total_consistency_lock . read ( ) . unwrap ( ) ;
2686
- handle_error ! ( self , self . internal_funding_created( their_node_id, msg) )
2621
+ if let Err ( _ ) = handle_error ! ( self , self . internal_funding_created( their_node_id, msg) , * their_node_id ) { }
2687
2622
}
2688
2623
2689
- fn handle_funding_signed ( & self , their_node_id : & PublicKey , msg : & msgs:: FundingSigned ) -> Result < ( ) , LightningError > {
2624
+ fn handle_funding_signed ( & self , their_node_id : & PublicKey , msg : & msgs:: FundingSigned ) {
2690
2625
let _ = self . total_consistency_lock . read ( ) . unwrap ( ) ;
2691
- handle_error ! ( self , self . internal_funding_signed( their_node_id, msg) )
2626
+ if let Err ( _ ) = handle_error ! ( self , self . internal_funding_signed( their_node_id, msg) , * their_node_id ) { }
2692
2627
}
2693
2628
2694
- fn handle_funding_locked ( & self , their_node_id : & PublicKey , msg : & msgs:: FundingLocked ) -> Result < ( ) , LightningError > {
2629
+ fn handle_funding_locked ( & self , their_node_id : & PublicKey , msg : & msgs:: FundingLocked ) {
2695
2630
let _ = self . total_consistency_lock . read ( ) . unwrap ( ) ;
2696
- handle_error ! ( self , self . internal_funding_locked( their_node_id, msg) )
2631
+ if let Err ( _ ) = handle_error ! ( self , self . internal_funding_locked( their_node_id, msg) , * their_node_id ) { }
2697
2632
}
2698
2633
2699
- fn handle_shutdown ( & self , their_node_id : & PublicKey , msg : & msgs:: Shutdown ) -> Result < ( ) , LightningError > {
2634
+ fn handle_shutdown ( & self , their_node_id : & PublicKey , msg : & msgs:: Shutdown ) {
2700
2635
let _ = self . total_consistency_lock . read ( ) . unwrap ( ) ;
2701
- handle_error ! ( self , self . internal_shutdown( their_node_id, msg) )
2636
+ if let Err ( _ ) = handle_error ! ( self , self . internal_shutdown( their_node_id, msg) , * their_node_id ) { }
2702
2637
}
2703
2638
2704
- fn handle_closing_signed ( & self , their_node_id : & PublicKey , msg : & msgs:: ClosingSigned ) -> Result < ( ) , LightningError > {
2639
+ fn handle_closing_signed ( & self , their_node_id : & PublicKey , msg : & msgs:: ClosingSigned ) {
2705
2640
let _ = self . total_consistency_lock . read ( ) . unwrap ( ) ;
2706
- handle_error ! ( self , self . internal_closing_signed( their_node_id, msg) )
2641
+ if let Err ( _ ) = handle_error ! ( self , self . internal_closing_signed( their_node_id, msg) , * their_node_id ) { }
2707
2642
}
2708
2643
2709
- fn handle_update_add_htlc ( & self , their_node_id : & PublicKey , msg : & msgs:: UpdateAddHTLC ) -> Result < ( ) , LightningError > {
2644
+ fn handle_update_add_htlc ( & self , their_node_id : & PublicKey , msg : & msgs:: UpdateAddHTLC ) {
2710
2645
let _ = self . total_consistency_lock . read ( ) . unwrap ( ) ;
2711
- handle_error ! ( self , self . internal_update_add_htlc( their_node_id, msg) )
2646
+ if let Err ( _ ) = handle_error ! ( self , self . internal_update_add_htlc( their_node_id, msg) , * their_node_id ) { }
2712
2647
}
2713
2648
2714
- fn handle_update_fulfill_htlc ( & self , their_node_id : & PublicKey , msg : & msgs:: UpdateFulfillHTLC ) -> Result < ( ) , LightningError > {
2649
+ fn handle_update_fulfill_htlc ( & self , their_node_id : & PublicKey , msg : & msgs:: UpdateFulfillHTLC ) {
2715
2650
let _ = self . total_consistency_lock . read ( ) . unwrap ( ) ;
2716
- handle_error ! ( self , self . internal_update_fulfill_htlc( their_node_id, msg) )
2651
+ if let Err ( _ ) = handle_error ! ( self , self . internal_update_fulfill_htlc( their_node_id, msg) , * their_node_id ) { }
2717
2652
}
2718
2653
2719
- fn handle_update_fail_htlc ( & self , their_node_id : & PublicKey , msg : & msgs:: UpdateFailHTLC ) -> Result < ( ) , LightningError > {
2654
+ fn handle_update_fail_htlc ( & self , their_node_id : & PublicKey , msg : & msgs:: UpdateFailHTLC ) {
2720
2655
let _ = self . total_consistency_lock . read ( ) . unwrap ( ) ;
2721
- handle_error ! ( self , self . internal_update_fail_htlc( their_node_id, msg) )
2656
+ if let Err ( _ ) = handle_error ! ( self , self . internal_update_fail_htlc( their_node_id, msg) , * their_node_id ) { }
2722
2657
}
2723
2658
2724
- fn handle_update_fail_malformed_htlc ( & self , their_node_id : & PublicKey , msg : & msgs:: UpdateFailMalformedHTLC ) -> Result < ( ) , LightningError > {
2659
+ fn handle_update_fail_malformed_htlc ( & self , their_node_id : & PublicKey , msg : & msgs:: UpdateFailMalformedHTLC ) {
2725
2660
let _ = self . total_consistency_lock . read ( ) . unwrap ( ) ;
2726
- handle_error ! ( self , self . internal_update_fail_malformed_htlc( their_node_id, msg) )
2661
+ if let Err ( _ ) = handle_error ! ( self , self . internal_update_fail_malformed_htlc( their_node_id, msg) , * their_node_id ) { }
2727
2662
}
2728
2663
2729
- fn handle_commitment_signed ( & self , their_node_id : & PublicKey , msg : & msgs:: CommitmentSigned ) -> Result < ( ) , LightningError > {
2664
+ fn handle_commitment_signed ( & self , their_node_id : & PublicKey , msg : & msgs:: CommitmentSigned ) {
2730
2665
let _ = self . total_consistency_lock . read ( ) . unwrap ( ) ;
2731
- handle_error ! ( self , self . internal_commitment_signed( their_node_id, msg) )
2666
+ if let Err ( _ ) = handle_error ! ( self , self . internal_commitment_signed( their_node_id, msg) , * their_node_id ) { }
2732
2667
}
2733
2668
2734
- fn handle_revoke_and_ack ( & self , their_node_id : & PublicKey , msg : & msgs:: RevokeAndACK ) -> Result < ( ) , LightningError > {
2669
+ fn handle_revoke_and_ack ( & self , their_node_id : & PublicKey , msg : & msgs:: RevokeAndACK ) {
2735
2670
let _ = self . total_consistency_lock . read ( ) . unwrap ( ) ;
2736
- handle_error ! ( self , self . internal_revoke_and_ack( their_node_id, msg) )
2671
+ if let Err ( _ ) = handle_error ! ( self , self . internal_revoke_and_ack( their_node_id, msg) , * their_node_id ) { }
2737
2672
}
2738
2673
2739
- fn handle_update_fee ( & self , their_node_id : & PublicKey , msg : & msgs:: UpdateFee ) -> Result < ( ) , LightningError > {
2674
+ fn handle_update_fee ( & self , their_node_id : & PublicKey , msg : & msgs:: UpdateFee ) {
2740
2675
let _ = self . total_consistency_lock . read ( ) . unwrap ( ) ;
2741
- handle_error ! ( self , self . internal_update_fee( their_node_id, msg) )
2676
+ if let Err ( _ ) = handle_error ! ( self , self . internal_update_fee( their_node_id, msg) , * their_node_id ) { }
2742
2677
}
2743
2678
2744
- fn handle_announcement_signatures ( & self , their_node_id : & PublicKey , msg : & msgs:: AnnouncementSignatures ) -> Result < ( ) , LightningError > {
2679
+ fn handle_announcement_signatures ( & self , their_node_id : & PublicKey , msg : & msgs:: AnnouncementSignatures ) {
2745
2680
let _ = self . total_consistency_lock . read ( ) . unwrap ( ) ;
2746
- handle_error ! ( self , self . internal_announcement_signatures( their_node_id, msg) )
2681
+ if let Err ( _ ) = handle_error ! ( self , self . internal_announcement_signatures( their_node_id, msg) , * their_node_id ) { }
2747
2682
}
2748
2683
2749
- fn handle_channel_reestablish ( & self , their_node_id : & PublicKey , msg : & msgs:: ChannelReestablish ) -> Result < ( ) , LightningError > {
2684
+ fn handle_channel_reestablish ( & self , their_node_id : & PublicKey , msg : & msgs:: ChannelReestablish ) {
2750
2685
let _ = self . total_consistency_lock . read ( ) . unwrap ( ) ;
2751
- handle_error ! ( self , self . internal_channel_reestablish( their_node_id, msg) )
2686
+ if let Err ( _ ) = handle_error ! ( self , self . internal_channel_reestablish( their_node_id, msg) , * their_node_id ) { }
2752
2687
}
2753
2688
2754
2689
fn peer_disconnected ( & self , their_node_id : & PublicKey , no_connection_possible : bool ) {
0 commit comments