@@ -1303,69 +1303,6 @@ macro_rules! remove_channel {
1303
1303
}
1304
1304
}
1305
1305
1306
- macro_rules! handle_monitor_update_res {
1307
- ( $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) => {
1308
- match $err {
1309
- ChannelMonitorUpdateStatus :: PermanentFailure => {
1310
- log_error!( $self. logger, "Closing channel {} due to monitor update ChannelMonitorUpdateStatus::PermanentFailure" , log_bytes!( $chan_id[ ..] ) ) ;
1311
- update_maps_on_chan_removal!( $self, $chan) ;
1312
- let res: Result <( ) , _> = Err ( MsgHandleErrInternal :: from_finish_shutdown( "ChannelMonitor storage failure" . to_owned( ) , * $chan_id, $chan. get_user_id( ) ,
1313
- $chan. force_shutdown( false ) , $self. get_channel_update_for_broadcast( & $chan) . ok( ) ) ) ;
1314
- ( res, true )
1315
- } ,
1316
- ChannelMonitorUpdateStatus :: InProgress => {
1317
- log_info!( $self. logger, "Disabling channel {} due to monitor update in progress. On restore will send {} and process {} forwards, {} fails, and {} fulfill finalizations" ,
1318
- log_bytes!( $chan_id[ ..] ) ,
1319
- if $resend_commitment && $resend_raa {
1320
- match $action_type {
1321
- RAACommitmentOrder :: CommitmentFirst => { "commitment then RAA" } ,
1322
- RAACommitmentOrder :: RevokeAndACKFirst => { "RAA then commitment" } ,
1323
- }
1324
- } else if $resend_commitment { "commitment" }
1325
- else if $resend_raa { "RAA" }
1326
- else { "nothing" } ,
1327
- ( & $failed_forwards as & Vec <( PendingHTLCInfo , u64 ) >) . len( ) ,
1328
- ( & $failed_fails as & Vec <( HTLCSource , PaymentHash , HTLCFailReason ) >) . len( ) ,
1329
- ( & $failed_finalized_fulfills as & Vec <HTLCSource >) . len( ) ) ;
1330
- if !$resend_commitment {
1331
- debug_assert!( $action_type == RAACommitmentOrder :: RevokeAndACKFirst || !$resend_raa) ;
1332
- }
1333
- if !$resend_raa {
1334
- debug_assert!( $action_type == RAACommitmentOrder :: CommitmentFirst || !$resend_commitment) ;
1335
- }
1336
- $chan. monitor_updating_paused( $resend_raa, $resend_commitment, $resend_channel_ready, $failed_forwards, $failed_fails, $failed_finalized_fulfills) ;
1337
- ( Err ( MsgHandleErrInternal :: from_chan_no_close( ChannelError :: Ignore ( "Failed to update ChannelMonitor" . to_owned( ) ) , * $chan_id) ) , false )
1338
- } ,
1339
- ChannelMonitorUpdateStatus :: Completed => {
1340
- ( Ok ( ( ) ) , false )
1341
- } ,
1342
- }
1343
- } ;
1344
- ( $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) => { {
1345
- 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( ) ) ;
1346
- if drop {
1347
- $entry. remove_entry( ) ;
1348
- }
1349
- res
1350
- } } ;
1351
- ( $self: ident, $err: expr, $entry: expr, $action_type: path, $chan_id: expr, COMMITMENT_UPDATE_ONLY ) => { {
1352
- debug_assert!( $action_type == RAACommitmentOrder :: CommitmentFirst ) ;
1353
- handle_monitor_update_res!( $self, $err, $entry, $action_type, false , true , false , Vec :: new( ) , Vec :: new( ) , Vec :: new( ) , $chan_id)
1354
- } } ;
1355
- ( $self: ident, $err: expr, $entry: expr, $action_type: path, $chan_id: expr, NO_UPDATE ) => {
1356
- handle_monitor_update_res!( $self, $err, $entry, $action_type, false , false , false , Vec :: new( ) , Vec :: new( ) , Vec :: new( ) , $chan_id)
1357
- } ;
1358
- ( $self: ident, $err: expr, $entry: expr, $action_type: path, $resend_channel_ready: expr, OPTIONALLY_RESEND_FUNDING_LOCKED ) => {
1359
- handle_monitor_update_res!( $self, $err, $entry, $action_type, false , false , $resend_channel_ready, Vec :: new( ) , Vec :: new( ) , Vec :: new( ) )
1360
- } ;
1361
- ( $self: ident, $err: expr, $entry: expr, $action_type: path, $resend_raa: expr, $resend_commitment: expr) => {
1362
- handle_monitor_update_res!( $self, $err, $entry, $action_type, $resend_raa, $resend_commitment, false , Vec :: new( ) , Vec :: new( ) , Vec :: new( ) )
1363
- } ;
1364
- ( $self: ident, $err: expr, $entry: expr, $action_type: path, $resend_raa: expr, $resend_commitment: expr, $failed_forwards: expr, $failed_fails: expr) => {
1365
- handle_monitor_update_res!( $self, $err, $entry, $action_type, $resend_raa, $resend_commitment, false , $failed_forwards, $failed_fails, Vec :: new( ) )
1366
- } ;
1367
- }
1368
-
1369
1306
macro_rules! send_channel_ready {
1370
1307
( $self: ident, $pending_msg_events: expr, $channel: expr, $channel_ready_msg: expr) => { {
1371
1308
$pending_msg_events. push( events:: MessageSendEvent :: SendChannelReady {
@@ -1423,9 +1360,9 @@ macro_rules! handle_new_monitor_update {
1423
1360
res
1424
1361
} ,
1425
1362
ChannelMonitorUpdateStatus :: Completed => {
1426
- if $chan. get_next_monitor_update( )
1427
- . expect( "We can't be processing a monitor udpate if it isn't queued" )
1428
- . update_id == $update_id &&
1363
+ if ( $update_id == 0 || $chan. get_next_monitor_update( )
1364
+ . expect( "We can't be processing a monitor update if it isn't queued" )
1365
+ . update_id == $update_id) &&
1429
1366
$chan. get_latest_monitor_update_id( ) == $update_id
1430
1367
{
1431
1368
let mut updates = $chan. monitor_updating_restored( & $self. logger,
@@ -4369,48 +4306,33 @@ where
4369
4306
}
4370
4307
4371
4308
fn internal_funding_signed ( & self , counterparty_node_id : & PublicKey , msg : & msgs:: FundingSigned ) -> Result < ( ) , MsgHandleErrInternal > {
4372
- let funding_tx = {
4373
- let best_block = * self . best_block . read ( ) . unwrap ( ) ;
4374
- let per_peer_state = self . per_peer_state . read ( ) . unwrap ( ) ;
4375
- let peer_state_mutex_opt = per_peer_state. get ( counterparty_node_id) ;
4376
- if let None = peer_state_mutex_opt {
4377
- return Err ( MsgHandleErrInternal :: send_err_msg_no_close ( format ! ( "Can't find a peer matching the passed counterparty node_id {}" , counterparty_node_id) , msg. channel_id ) )
4378
- }
4309
+ let best_block = * self . best_block . read ( ) . unwrap ( ) ;
4310
+ let per_peer_state = self . per_peer_state . read ( ) . unwrap ( ) ;
4311
+ let peer_state_mutex_opt = per_peer_state. get ( counterparty_node_id) ;
4312
+ if let None = peer_state_mutex_opt {
4313
+ return Err ( MsgHandleErrInternal :: send_err_msg_no_close ( format ! ( "Can't find a peer matching the passed counterparty node_id {}" , counterparty_node_id) , msg. channel_id ) )
4314
+ }
4379
4315
4380
- let mut peer_state_lock = peer_state_mutex_opt. unwrap ( ) . lock ( ) . unwrap ( ) ;
4381
- let peer_state = & mut * peer_state_lock;
4382
- match peer_state. channel_by_id . entry ( msg. channel_id ) {
4383
- hash_map:: Entry :: Occupied ( mut chan) => {
4384
- let ( monitor, funding_tx, channel_ready) = match chan. get_mut ( ) . funding_signed ( & msg, best_block, & self . keys_manager , & self . logger ) {
4385
- Ok ( update) => update,
4386
- Err ( e) => try_chan_entry ! ( self , Err ( e) , chan) ,
4387
- } ;
4388
- match self . chain_monitor . watch_channel ( chan. get ( ) . get_funding_txo ( ) . unwrap ( ) , monitor) {
4389
- ChannelMonitorUpdateStatus :: Completed => { } ,
4390
- e => {
4391
- let mut res = handle_monitor_update_res ! ( self , e, chan, RAACommitmentOrder :: RevokeAndACKFirst , channel_ready. is_some( ) , OPTIONALLY_RESEND_FUNDING_LOCKED ) ;
4392
- if let Err ( MsgHandleErrInternal { ref mut shutdown_finish, .. } ) = res {
4393
- // We weren't able to watch the channel to begin with, so no updates should be made on
4394
- // it. Previously, full_stack_target found an (unreachable) panic when the
4395
- // monitor update contained within `shutdown_finish` was applied.
4396
- if let Some ( ( ref mut shutdown_finish, _) ) = shutdown_finish {
4397
- shutdown_finish. 0 . take ( ) ;
4398
- }
4399
- }
4400
- return res
4401
- } ,
4402
- }
4403
- if let Some ( msg) = channel_ready {
4404
- send_channel_ready ! ( self , peer_state. pending_msg_events, chan. get( ) , msg) ;
4316
+ let mut peer_state_lock = peer_state_mutex_opt. unwrap ( ) . lock ( ) . unwrap ( ) ;
4317
+ let peer_state = & mut * peer_state_lock;
4318
+ match peer_state. channel_by_id . entry ( msg. channel_id ) {
4319
+ hash_map:: Entry :: Occupied ( mut chan) => {
4320
+ let monitor = try_chan_entry ! ( self ,
4321
+ chan. get_mut( ) . funding_signed( & msg, best_block, & self . keys_manager, & self . logger) , chan) ;
4322
+ let update_res = self . chain_monitor . watch_channel ( chan. get ( ) . get_funding_txo ( ) . unwrap ( ) , monitor) ;
4323
+ let mut res = handle_new_monitor_update ! ( self , update_res, 0 , peer_state_lock, peer_state, chan) ;
4324
+ if let Err ( MsgHandleErrInternal { ref mut shutdown_finish, .. } ) = res {
4325
+ // We weren't able to watch the channel to begin with, so no updates should be made on
4326
+ // it. Previously, full_stack_target found an (unreachable) panic when the
4327
+ // monitor update contained within `shutdown_finish` was applied.
4328
+ if let Some ( ( ref mut shutdown_finish, _) ) = shutdown_finish {
4329
+ shutdown_finish. 0 . take ( ) ;
4405
4330
}
4406
- funding_tx
4407
- } ,
4408
- 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 ) )
4409
- }
4410
- } ;
4411
- log_info ! ( self . logger, "Broadcasting funding transaction with txid {}" , funding_tx. txid( ) ) ;
4412
- self . tx_broadcaster . broadcast_transaction ( & funding_tx) ;
4413
- Ok ( ( ) )
4331
+ }
4332
+ res
4333
+ } ,
4334
+ hash_map:: Entry :: Vacant ( _) => return Err ( MsgHandleErrInternal :: send_err_msg_no_close ( "Failed to find corresponding channel" . to_owned ( ) , msg. channel_id ) )
4335
+ }
4414
4336
}
4415
4337
4416
4338
fn internal_channel_ready ( & self , counterparty_node_id : & PublicKey , msg : & msgs:: ChannelReady ) -> Result < ( ) , MsgHandleErrInternal > {
0 commit comments