@@ -4241,55 +4241,27 @@ where
4241
4241
}
4242
4242
4243
4243
fn internal_funding_created ( & self , counterparty_node_id : & PublicKey , msg : & msgs:: FundingCreated ) -> Result < ( ) , MsgHandleErrInternal > {
4244
+ let best_block = * self . best_block . read ( ) . unwrap ( ) ;
4245
+
4244
4246
let per_peer_state = self . per_peer_state . read ( ) . unwrap ( ) ;
4245
4247
let peer_state_mutex_opt = per_peer_state. get ( counterparty_node_id) ;
4246
4248
if let None = peer_state_mutex_opt {
4247
4249
return Err ( MsgHandleErrInternal :: send_err_msg_no_close ( format ! ( "Can't find a peer matching the passed counterparty node_id {}" , counterparty_node_id) , msg. temporary_channel_id ) )
4248
4250
}
4249
- let ( ( funding_msg , monitor , mut channel_ready ) , mut chan ) = {
4250
- let best_block = * self . best_block . read ( ) . unwrap ( ) ;
4251
- let mut peer_state_lock = peer_state_mutex_opt . unwrap ( ) . lock ( ) . unwrap ( ) ;
4252
- let peer_state = & mut * peer_state_lock ;
4251
+
4252
+ let mut peer_state_lock = peer_state_mutex_opt . unwrap ( ) . lock ( ) . unwrap ( ) ;
4253
+ let peer_state = & mut * peer_state_lock ;
4254
+ let ( ( funding_msg , monitor ) , chan ) =
4253
4255
match peer_state. channel_by_id . entry ( msg. temporary_channel_id ) {
4254
4256
hash_map:: Entry :: Occupied ( mut chan) => {
4255
4257
( try_chan_entry ! ( self , chan. get_mut( ) . funding_created( msg, best_block, & self . signer_provider, & self . logger) , chan) , chan. remove ( ) )
4256
4258
} ,
4257
4259
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. temporary_channel_id ) )
4258
- }
4259
- } ;
4260
- // Because we have exclusive ownership of the channel here we can release the peer_state
4261
- // lock before watch_channel
4262
- match self . chain_monitor . watch_channel ( monitor. get_funding_txo ( ) . 0 , monitor) {
4263
- ChannelMonitorUpdateStatus :: Completed => { } ,
4264
- ChannelMonitorUpdateStatus :: PermanentFailure => {
4265
- // Note that we reply with the new channel_id in error messages if we gave up on the
4266
- // channel, not the temporary_channel_id. This is compatible with ourselves, but the
4267
- // spec is somewhat ambiguous here. Not a huge deal since we'll send error messages for
4268
- // any messages referencing a previously-closed channel anyway.
4269
- // We do not propagate the monitor update to the user as it would be for a monitor
4270
- // that we didn't manage to store (and that we don't care about - we don't respond
4271
- // with the funding_signed so the channel can never go on chain).
4272
- let ( _monitor_update, failed_htlcs) = chan. force_shutdown ( false ) ;
4273
- assert ! ( failed_htlcs. is_empty( ) ) ;
4274
- return Err ( MsgHandleErrInternal :: send_err_msg_no_close ( "ChannelMonitor storage failure" . to_owned ( ) , funding_msg. channel_id ) ) ;
4275
- } ,
4276
- ChannelMonitorUpdateStatus :: InProgress => {
4277
- // There's no problem signing a counterparty's funding transaction if our monitor
4278
- // hasn't persisted to disk yet - we can't lose money on a transaction that we haven't
4279
- // accepted payment from yet. We do, however, need to wait to send our channel_ready
4280
- // until we have persisted our monitor.
4281
- chan. monitor_updating_paused ( false , false , channel_ready. is_some ( ) , Vec :: new ( ) , Vec :: new ( ) , Vec :: new ( ) ) ;
4282
- channel_ready = None ; // Don't send the channel_ready now
4283
- } ,
4284
- }
4285
- // It's safe to unwrap as we've held the `per_peer_state` read lock since checking that the
4286
- // peer exists, despite the inner PeerState potentially having no channels after removing
4287
- // the channel above.
4288
- let mut peer_state_lock = peer_state_mutex_opt. unwrap ( ) . lock ( ) . unwrap ( ) ;
4289
- let peer_state = & mut * peer_state_lock;
4260
+ } ;
4261
+
4290
4262
match peer_state. channel_by_id . entry ( funding_msg. channel_id ) {
4291
4263
hash_map:: Entry :: Occupied ( _) => {
4292
- return Err ( MsgHandleErrInternal :: send_err_msg_no_close ( "Already had channel with the new channel_id" . to_owned ( ) , funding_msg. channel_id ) )
4264
+ Err ( MsgHandleErrInternal :: send_err_msg_no_close ( "Already had channel with the new channel_id" . to_owned ( ) , funding_msg. channel_id ) )
4293
4265
} ,
4294
4266
hash_map:: Entry :: Vacant ( e) => {
4295
4267
let mut id_to_peer = self . id_to_peer . lock ( ) . unwrap ( ) ;
@@ -4303,17 +4275,34 @@ where
4303
4275
i_e. insert ( chan. get_counterparty_node_id ( ) ) ;
4304
4276
}
4305
4277
}
4278
+
4279
+ // There's no problem signing a counterparty's funding transaction if our monitor
4280
+ // hasn't persisted to disk yet - we can't lose money on a transaction that we haven't
4281
+ // accepted payment from yet. We do, however, need to wait to send our channel_ready
4282
+ // until we have persisted our monitor.
4306
4283
peer_state. pending_msg_events . push ( events:: MessageSendEvent :: SendFundingSigned {
4307
4284
node_id : counterparty_node_id. clone ( ) ,
4308
4285
msg : funding_msg,
4309
4286
} ) ;
4310
- if let Some ( msg) = channel_ready {
4311
- send_channel_ready ! ( self , peer_state. pending_msg_events, chan, msg) ;
4287
+
4288
+ let monitor_res = self . chain_monitor . watch_channel ( monitor. get_funding_txo ( ) . 0 , monitor) ;
4289
+
4290
+ let chan = e. insert ( chan) ;
4291
+ let mut res = handle_new_monitor_update ! ( self , monitor_res, 0 , peer_state_lock, peer_state, chan, MANUALLY_REMOVING , 42 ) ;
4292
+
4293
+ // Note that we reply with the new channel_id in error messages if we gave up on the
4294
+ // channel, not the temporary_channel_id. This is compatible with ourselves, but the
4295
+ // spec is somewhat ambiguous here. Not a huge deal since we'll send error messages for
4296
+ // any messages referencing a previously-closed channel anyway.
4297
+ // We do not propagate the monitor update to the user as it would be for a monitor
4298
+ // that we didn't manage to store (and that we don't care about - we don't respond
4299
+ // with the funding_signed so the channel can never go on chain).
4300
+ if let Err ( MsgHandleErrInternal { shutdown_finish : Some ( ( res, _) ) , .. } ) = & mut res {
4301
+ res. 0 = None ;
4312
4302
}
4313
- e . insert ( chan ) ;
4303
+ res
4314
4304
}
4315
4305
}
4316
- Ok ( ( ) )
4317
4306
}
4318
4307
4319
4308
fn internal_funding_signed ( & self , counterparty_node_id : & PublicKey , msg : & msgs:: FundingSigned ) -> Result < ( ) , MsgHandleErrInternal > {
0 commit comments