@@ -1357,69 +1357,6 @@ macro_rules! remove_channel {
13571357 }
13581358}
13591359
1360- macro_rules! handle_monitor_update_res {
1361- ( $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) => {
1362- match $err {
1363- ChannelMonitorUpdateStatus :: PermanentFailure => {
1364- log_error!( $self. logger, "Closing channel {} due to monitor update ChannelMonitorUpdateStatus::PermanentFailure" , log_bytes!( $chan_id[ ..] ) ) ;
1365- update_maps_on_chan_removal!( $self, $chan) ;
1366- let res: Result <( ) , _> = Err ( MsgHandleErrInternal :: from_finish_shutdown( "ChannelMonitor storage failure" . to_owned( ) , * $chan_id, $chan. get_user_id( ) ,
1367- $chan. force_shutdown( false ) , $self. get_channel_update_for_broadcast( & $chan) . ok( ) ) ) ;
1368- ( res, true )
1369- } ,
1370- ChannelMonitorUpdateStatus :: InProgress => {
1371- log_info!( $self. logger, "Disabling channel {} due to monitor update in progress. On restore will send {} and process {} forwards, {} fails, and {} fulfill finalizations" ,
1372- log_bytes!( $chan_id[ ..] ) ,
1373- if $resend_commitment && $resend_raa {
1374- match $action_type {
1375- RAACommitmentOrder :: CommitmentFirst => { "commitment then RAA" } ,
1376- RAACommitmentOrder :: RevokeAndACKFirst => { "RAA then commitment" } ,
1377- }
1378- } else if $resend_commitment { "commitment" }
1379- else if $resend_raa { "RAA" }
1380- else { "nothing" } ,
1381- ( & $failed_forwards as & Vec <( PendingHTLCInfo , u64 ) >) . len( ) ,
1382- ( & $failed_fails as & Vec <( HTLCSource , PaymentHash , HTLCFailReason ) >) . len( ) ,
1383- ( & $failed_finalized_fulfills as & Vec <HTLCSource >) . len( ) ) ;
1384- if !$resend_commitment {
1385- debug_assert!( $action_type == RAACommitmentOrder :: RevokeAndACKFirst || !$resend_raa) ;
1386- }
1387- if !$resend_raa {
1388- debug_assert!( $action_type == RAACommitmentOrder :: CommitmentFirst || !$resend_commitment) ;
1389- }
1390- $chan. monitor_updating_paused( $resend_raa, $resend_commitment, $resend_channel_ready, $failed_forwards, $failed_fails, $failed_finalized_fulfills) ;
1391- ( Err ( MsgHandleErrInternal :: from_chan_no_close( ChannelError :: Ignore ( "Failed to update ChannelMonitor" . to_owned( ) ) , * $chan_id) ) , false )
1392- } ,
1393- ChannelMonitorUpdateStatus :: Completed => {
1394- ( Ok ( ( ) ) , false )
1395- } ,
1396- }
1397- } ;
1398- ( $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) => { {
1399- 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( ) ) ;
1400- if drop {
1401- $entry. remove_entry( ) ;
1402- }
1403- res
1404- } } ;
1405- ( $self: ident, $err: expr, $entry: expr, $action_type: path, $chan_id: expr, COMMITMENT_UPDATE_ONLY ) => { {
1406- debug_assert!( $action_type == RAACommitmentOrder :: CommitmentFirst ) ;
1407- handle_monitor_update_res!( $self, $err, $entry, $action_type, false , true , false , Vec :: new( ) , Vec :: new( ) , Vec :: new( ) , $chan_id)
1408- } } ;
1409- ( $self: ident, $err: expr, $entry: expr, $action_type: path, $chan_id: expr, NO_UPDATE ) => {
1410- handle_monitor_update_res!( $self, $err, $entry, $action_type, false , false , false , Vec :: new( ) , Vec :: new( ) , Vec :: new( ) , $chan_id)
1411- } ;
1412- ( $self: ident, $err: expr, $entry: expr, $action_type: path, $resend_channel_ready: expr, OPTIONALLY_RESEND_FUNDING_LOCKED ) => {
1413- handle_monitor_update_res!( $self, $err, $entry, $action_type, false , false , $resend_channel_ready, Vec :: new( ) , Vec :: new( ) , Vec :: new( ) )
1414- } ;
1415- ( $self: ident, $err: expr, $entry: expr, $action_type: path, $resend_raa: expr, $resend_commitment: expr) => {
1416- handle_monitor_update_res!( $self, $err, $entry, $action_type, $resend_raa, $resend_commitment, false , Vec :: new( ) , Vec :: new( ) , Vec :: new( ) )
1417- } ;
1418- ( $self: ident, $err: expr, $entry: expr, $action_type: path, $resend_raa: expr, $resend_commitment: expr, $failed_forwards: expr, $failed_fails: expr) => {
1419- handle_monitor_update_res!( $self, $err, $entry, $action_type, $resend_raa, $resend_commitment, false , $failed_forwards, $failed_fails, Vec :: new( ) )
1420- } ;
1421- }
1422-
14231360macro_rules! send_channel_ready {
14241361 ( $self: ident, $pending_msg_events: expr, $channel: expr, $channel_ready_msg: expr) => { {
14251362 $pending_msg_events. push( events:: MessageSendEvent :: SendChannelReady {
@@ -4492,49 +4429,34 @@ where
44924429 }
44934430
44944431 fn internal_funding_signed ( & self , counterparty_node_id : & PublicKey , msg : & msgs:: FundingSigned ) -> Result < ( ) , MsgHandleErrInternal > {
4495- let funding_tx = {
4496- let best_block = * self . best_block . read ( ) . unwrap ( ) ;
4497- let per_peer_state = self . per_peer_state . read ( ) . unwrap ( ) ;
4498- let peer_state_mutex = per_peer_state. get ( counterparty_node_id)
4499- . ok_or_else ( || {
4500- debug_assert ! ( false ) ;
4501- MsgHandleErrInternal :: send_err_msg_no_close ( format ! ( "Can't find a peer matching the passed counterparty node_id {}" , counterparty_node_id) , msg. channel_id )
4502- } ) ?;
4432+ let best_block = * self . best_block . read ( ) . unwrap ( ) ;
4433+ let per_peer_state = self . per_peer_state . read ( ) . unwrap ( ) ;
4434+ let peer_state_mutex = per_peer_state. get ( counterparty_node_id)
4435+ . ok_or_else ( || {
4436+ debug_assert ! ( false ) ;
4437+ MsgHandleErrInternal :: send_err_msg_no_close ( format ! ( "Can't find a peer matching the passed counterparty node_id {}" , counterparty_node_id) , msg. channel_id )
4438+ } ) ?;
45034439
4504- let mut peer_state_lock = peer_state_mutex. lock ( ) . unwrap ( ) ;
4505- let peer_state = & mut * peer_state_lock;
4506- match peer_state. channel_by_id . entry ( msg. channel_id ) {
4507- hash_map:: Entry :: Occupied ( mut chan) => {
4508- let ( monitor, funding_tx, channel_ready) = match chan. get_mut ( ) . funding_signed ( & msg, best_block, & self . signer_provider , & self . logger ) {
4509- Ok ( update) => update,
4510- Err ( e) => try_chan_entry ! ( self , Err ( e) , chan) ,
4511- } ;
4512- match self . chain_monitor . watch_channel ( chan. get ( ) . get_funding_txo ( ) . unwrap ( ) , monitor) {
4513- ChannelMonitorUpdateStatus :: Completed => { } ,
4514- e => {
4515- let mut res = handle_monitor_update_res ! ( self , e, chan, RAACommitmentOrder :: RevokeAndACKFirst , channel_ready. is_some( ) , OPTIONALLY_RESEND_FUNDING_LOCKED ) ;
4516- if let Err ( MsgHandleErrInternal { ref mut shutdown_finish, .. } ) = res {
4517- // We weren't able to watch the channel to begin with, so no updates should be made on
4518- // it. Previously, full_stack_target found an (unreachable) panic when the
4519- // monitor update contained within `shutdown_finish` was applied.
4520- if let Some ( ( ref mut shutdown_finish, _) ) = shutdown_finish {
4521- shutdown_finish. 0 . take ( ) ;
4522- }
4523- }
4524- return res
4525- } ,
4526- }
4527- if let Some ( msg) = channel_ready {
4528- send_channel_ready ! ( self , peer_state. pending_msg_events, chan. get( ) , msg) ;
4440+ let mut peer_state_lock = peer_state_mutex. lock ( ) . unwrap ( ) ;
4441+ let peer_state = & mut * peer_state_lock;
4442+ match peer_state. channel_by_id . entry ( msg. channel_id ) {
4443+ hash_map:: Entry :: Occupied ( mut chan) => {
4444+ let monitor = try_chan_entry ! ( self ,
4445+ chan. get_mut( ) . funding_signed( & msg, best_block, & self . signer_provider, & self . logger) , chan) ;
4446+ let update_res = self . chain_monitor . watch_channel ( chan. get ( ) . get_funding_txo ( ) . unwrap ( ) , monitor) ;
4447+ let mut res = handle_new_monitor_update ! ( self , update_res, 0 , peer_state_lock, peer_state, chan) ;
4448+ if let Err ( MsgHandleErrInternal { ref mut shutdown_finish, .. } ) = res {
4449+ // We weren't able to watch the channel to begin with, so no updates should be made on
4450+ // it. Previously, full_stack_target found an (unreachable) panic when the
4451+ // monitor update contained within `shutdown_finish` was applied.
4452+ if let Some ( ( ref mut shutdown_finish, _) ) = shutdown_finish {
4453+ shutdown_finish. 0 . take ( ) ;
45294454 }
4530- funding_tx
4531- } ,
4532- hash_map:: Entry :: Vacant ( _) => return Err ( MsgHandleErrInternal :: send_err_msg_no_close ( format ! ( "Got a message for a channel from the wrong node! No such channel for the passed counterparty_node_id {}" , counterparty_node_id) , msg. channel_id ) )
4533- }
4534- } ;
4535- log_info ! ( self . logger, "Broadcasting funding transaction with txid {}" , funding_tx. txid( ) ) ;
4536- self . tx_broadcaster . broadcast_transaction ( & funding_tx) ;
4537- Ok ( ( ) )
4455+ }
4456+ res
4457+ } ,
4458+ hash_map:: Entry :: Vacant ( _) => return Err ( MsgHandleErrInternal :: send_err_msg_no_close ( "Failed to find corresponding channel" . to_owned ( ) , msg. channel_id ) )
4459+ }
45384460 }
45394461
45404462 fn internal_channel_ready ( & self , counterparty_node_id : & PublicKey , msg : & msgs:: ChannelReady ) -> Result < ( ) , MsgHandleErrInternal > {
0 commit comments