@@ -1477,69 +1477,6 @@ macro_rules! remove_channel {
1477
1477
}
1478
1478
}
1479
1479
1480
- macro_rules! handle_monitor_update_res {
1481
- ( $self: ident, $err: expr, $chan: expr, $action_type: path, $resend_raa: expr, $resend_commitment: expr, $resend_channel_ready: expr, $failed_forwards: expr, $failed_fails: expr, $failed_finalized_fulfills: expr, $chan_id: expr) => {
1482
- match $err {
1483
- ChannelMonitorUpdateStatus :: PermanentFailure => {
1484
- log_error!( $self. logger, "Closing channel {} due to monitor update ChannelMonitorUpdateStatus::PermanentFailure" , log_bytes!( $chan_id[ ..] ) ) ;
1485
- update_maps_on_chan_removal!( $self, $chan) ;
1486
- let res: Result <( ) , _> = Err ( MsgHandleErrInternal :: from_finish_shutdown( "ChannelMonitor storage failure" . to_owned( ) , * $chan_id, $chan. get_user_id( ) ,
1487
- $chan. force_shutdown( false ) , $self. get_channel_update_for_broadcast( & $chan) . ok( ) ) ) ;
1488
- ( res, true )
1489
- } ,
1490
- ChannelMonitorUpdateStatus :: InProgress => {
1491
- log_info!( $self. logger, "Disabling channel {} due to monitor update in progress. On restore will send {} and process {} forwards, {} fails, and {} fulfill finalizations" ,
1492
- log_bytes!( $chan_id[ ..] ) ,
1493
- if $resend_commitment && $resend_raa {
1494
- match $action_type {
1495
- RAACommitmentOrder :: CommitmentFirst => { "commitment then RAA" } ,
1496
- RAACommitmentOrder :: RevokeAndACKFirst => { "RAA then commitment" } ,
1497
- }
1498
- } else if $resend_commitment { "commitment" }
1499
- else if $resend_raa { "RAA" }
1500
- else { "nothing" } ,
1501
- ( & $failed_forwards as & Vec <( PendingHTLCInfo , u64 ) >) . len( ) ,
1502
- ( & $failed_fails as & Vec <( HTLCSource , PaymentHash , HTLCFailReason ) >) . len( ) ,
1503
- ( & $failed_finalized_fulfills as & Vec <HTLCSource >) . len( ) ) ;
1504
- if !$resend_commitment {
1505
- debug_assert!( $action_type == RAACommitmentOrder :: RevokeAndACKFirst || !$resend_raa) ;
1506
- }
1507
- if !$resend_raa {
1508
- debug_assert!( $action_type == RAACommitmentOrder :: CommitmentFirst || !$resend_commitment) ;
1509
- }
1510
- $chan. monitor_updating_paused( $resend_raa, $resend_commitment, $resend_channel_ready, $failed_forwards, $failed_fails, $failed_finalized_fulfills) ;
1511
- ( Err ( MsgHandleErrInternal :: from_chan_no_close( ChannelError :: Ignore ( "Failed to update ChannelMonitor" . to_owned( ) ) , * $chan_id) ) , false )
1512
- } ,
1513
- ChannelMonitorUpdateStatus :: Completed => {
1514
- ( Ok ( ( ) ) , false )
1515
- } ,
1516
- }
1517
- } ;
1518
- ( $self: ident, $err: expr, $entry: expr, $action_type: path, $resend_raa: expr, $resend_commitment: expr, $resend_channel_ready: expr, $failed_forwards: expr, $failed_fails: expr, $failed_finalized_fulfills: expr) => { {
1519
- let ( res, drop) = handle_monitor_update_res!( $self, $err, $entry. get_mut( ) , $action_type, $resend_raa, $resend_commitment, $resend_channel_ready, $failed_forwards, $failed_fails, $failed_finalized_fulfills, $entry. key( ) ) ;
1520
- if drop {
1521
- $entry. remove_entry( ) ;
1522
- }
1523
- res
1524
- } } ;
1525
- ( $self: ident, $err: expr, $entry: expr, $action_type: path, $chan_id: expr, COMMITMENT_UPDATE_ONLY ) => { {
1526
- debug_assert!( $action_type == RAACommitmentOrder :: CommitmentFirst ) ;
1527
- handle_monitor_update_res!( $self, $err, $entry, $action_type, false , true , false , Vec :: new( ) , Vec :: new( ) , Vec :: new( ) , $chan_id)
1528
- } } ;
1529
- ( $self: ident, $err: expr, $entry: expr, $action_type: path, $chan_id: expr, NO_UPDATE ) => {
1530
- handle_monitor_update_res!( $self, $err, $entry, $action_type, false , false , false , Vec :: new( ) , Vec :: new( ) , Vec :: new( ) , $chan_id)
1531
- } ;
1532
- ( $self: ident, $err: expr, $entry: expr, $action_type: path, $resend_channel_ready: expr, OPTIONALLY_RESEND_FUNDING_LOCKED ) => {
1533
- handle_monitor_update_res!( $self, $err, $entry, $action_type, false , false , $resend_channel_ready, Vec :: new( ) , Vec :: new( ) , Vec :: new( ) )
1534
- } ;
1535
- ( $self: ident, $err: expr, $entry: expr, $action_type: path, $resend_raa: expr, $resend_commitment: expr) => {
1536
- handle_monitor_update_res!( $self, $err, $entry, $action_type, $resend_raa, $resend_commitment, false , Vec :: new( ) , Vec :: new( ) , Vec :: new( ) )
1537
- } ;
1538
- ( $self: ident, $err: expr, $entry: expr, $action_type: path, $resend_raa: expr, $resend_commitment: expr, $failed_forwards: expr, $failed_fails: expr) => {
1539
- handle_monitor_update_res!( $self, $err, $entry, $action_type, $resend_raa, $resend_commitment, false , $failed_forwards, $failed_fails, Vec :: new( ) )
1540
- } ;
1541
- }
1542
-
1543
1480
macro_rules! send_channel_ready {
1544
1481
( $self: ident, $pending_msg_events: expr, $channel: expr, $channel_ready_msg: expr) => { {
1545
1482
$pending_msg_events. push( events:: MessageSendEvent :: SendChannelReady {
@@ -1597,9 +1534,9 @@ macro_rules! handle_new_monitor_update {
1597
1534
res
1598
1535
} ,
1599
1536
ChannelMonitorUpdateStatus :: Completed => {
1600
- if $chan. get_next_monitor_update( )
1601
- . expect( "We can't be processing a monitor udpate if it isn't queued" )
1602
- . update_id == $update_id &&
1537
+ if ( $update_id == 0 || $chan. get_next_monitor_update( )
1538
+ . expect( "We can't be processing a monitor update if it isn't queued" )
1539
+ . update_id == $update_id) &&
1603
1540
$chan. get_latest_monitor_update_id( ) == $update_id
1604
1541
{
1605
1542
let mut updates = $chan. monitor_updating_restored( & $self. logger,
@@ -4877,45 +4814,30 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4877
4814
}
4878
4815
4879
4816
fn internal_funding_signed ( & self , counterparty_node_id : & PublicKey , msg : & msgs:: FundingSigned ) -> Result < ( ) , MsgHandleErrInternal > {
4880
- let funding_tx = {
4881
- let best_block = * self . best_block . read ( ) . unwrap ( ) ;
4882
- let mut channel_lock = self . channel_state . lock ( ) . unwrap ( ) ;
4883
- let channel_state = & mut * channel_lock;
4884
- match channel_state. by_id . entry ( msg. channel_id ) {
4885
- hash_map:: Entry :: Occupied ( mut chan) => {
4886
- if chan. get ( ) . get_counterparty_node_id ( ) != * counterparty_node_id {
4887
- return Err ( MsgHandleErrInternal :: send_err_msg_no_close ( "Got a message for a channel from the wrong node!" . to_owned ( ) , msg. channel_id ) ) ;
4888
- }
4889
- let ( monitor, funding_tx, channel_ready) = match chan. get_mut ( ) . funding_signed ( & msg, best_block, & self . logger ) {
4890
- Ok ( update) => update,
4891
- Err ( e) => try_chan_entry ! ( self , Err ( e) , chan) ,
4892
- } ;
4893
- match self . chain_monitor . watch_channel ( chan. get ( ) . get_funding_txo ( ) . unwrap ( ) , monitor) {
4894
- ChannelMonitorUpdateStatus :: Completed => { } ,
4895
- e => {
4896
- let mut res = handle_monitor_update_res ! ( self , e, chan, RAACommitmentOrder :: RevokeAndACKFirst , channel_ready. is_some( ) , OPTIONALLY_RESEND_FUNDING_LOCKED ) ;
4897
- if let Err ( MsgHandleErrInternal { ref mut shutdown_finish, .. } ) = res {
4898
- // We weren't able to watch the channel to begin with, so no updates should be made on
4899
- // it. Previously, full_stack_target found an (unreachable) panic when the
4900
- // monitor update contained within `shutdown_finish` was applied.
4901
- if let Some ( ( ref mut shutdown_finish, _) ) = shutdown_finish {
4902
- shutdown_finish. 0 . take ( ) ;
4903
- }
4904
- }
4905
- return res
4906
- } ,
4907
- }
4908
- if let Some ( msg) = channel_ready {
4909
- send_channel_ready ! ( self , channel_state. pending_msg_events, chan. get( ) , msg) ;
4817
+ let best_block = * self . best_block . read ( ) . unwrap ( ) ;
4818
+ let mut channel_lock = self . channel_state . lock ( ) . unwrap ( ) ;
4819
+ let channel_state = & mut * channel_lock;
4820
+ match channel_state. by_id . entry ( msg. channel_id ) {
4821
+ hash_map:: Entry :: Occupied ( mut chan) => {
4822
+ if chan. get ( ) . get_counterparty_node_id ( ) != * counterparty_node_id {
4823
+ return Err ( MsgHandleErrInternal :: send_err_msg_no_close ( "Got a message for a channel from the wrong node!" . to_owned ( ) , msg. channel_id ) ) ;
4824
+ }
4825
+ let monitor = try_chan_entry ! ( self ,
4826
+ chan. get_mut( ) . funding_signed( & msg, best_block, & self . logger) , chan) ;
4827
+ let update_res = self . chain_monitor . watch_channel ( chan. get ( ) . get_funding_txo ( ) . unwrap ( ) , monitor) ;
4828
+ let mut res = handle_new_monitor_update ! ( self , update_res, 0 , channel_lock, channel_state. pending_msg_events, chan) ;
4829
+ if let Err ( MsgHandleErrInternal { ref mut shutdown_finish, .. } ) = res {
4830
+ // We weren't able to watch the channel to begin with, so no updates should be made on
4831
+ // it. Previously, full_stack_target found an (unreachable) panic when the
4832
+ // monitor update contained within `shutdown_finish` was applied.
4833
+ if let Some ( ( ref mut shutdown_finish, _) ) = shutdown_finish {
4834
+ shutdown_finish. 0 . take ( ) ;
4910
4835
}
4911
- funding_tx
4912
- } ,
4913
- hash_map:: Entry :: Vacant ( _) => return Err ( MsgHandleErrInternal :: send_err_msg_no_close ( "Failed to find corresponding channel" . to_owned ( ) , msg. channel_id ) )
4914
- }
4915
- } ;
4916
- log_info ! ( self . logger, "Broadcasting funding transaction with txid {}" , funding_tx. txid( ) ) ;
4917
- self . tx_broadcaster . broadcast_transaction ( & funding_tx) ;
4918
- Ok ( ( ) )
4836
+ }
4837
+ res
4838
+ } ,
4839
+ hash_map:: Entry :: Vacant ( _) => return Err ( MsgHandleErrInternal :: send_err_msg_no_close ( "Failed to find corresponding channel" . to_owned ( ) , msg. channel_id ) )
4840
+ }
4919
4841
}
4920
4842
4921
4843
fn internal_channel_ready ( & self , counterparty_node_id : & PublicKey , msg : & msgs:: ChannelReady ) -> Result < ( ) , MsgHandleErrInternal > {
0 commit comments