@@ -4695,10 +4695,10 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4695
4695
}
4696
4696
4697
4697
fn internal_funding_created ( & self , counterparty_node_id : & PublicKey , msg : & msgs:: FundingCreated ) -> Result < ( ) , MsgHandleErrInternal > {
4698
- let ( ( funding_msg , monitor , mut channel_ready ) , mut chan ) = {
4699
- let best_block = * self . best_block . read ( ) . unwrap ( ) ;
4700
- let mut channel_lock = self . channel_state . lock ( ) . unwrap ( ) ;
4701
- let channel_state = & mut * channel_lock ;
4698
+ let best_block = * self . best_block . read ( ) . unwrap ( ) ;
4699
+ let mut channel_lock = self . channel_state . lock ( ) . unwrap ( ) ;
4700
+ let channel_state = & mut * channel_lock ;
4701
+ let ( ( funding_msg , monitor ) , chan ) =
4702
4702
match channel_state. by_id . entry ( msg. temporary_channel_id . clone ( ) ) {
4703
4703
hash_map:: Entry :: Occupied ( mut chan) => {
4704
4704
if chan. get ( ) . get_counterparty_node_id ( ) != * counterparty_node_id {
@@ -4707,38 +4707,11 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4707
4707
( try_chan_entry ! ( self , chan. get_mut( ) . funding_created( msg, best_block, & self . keys_manager, & self . logger) , chan) , chan. remove ( ) )
4708
4708
} ,
4709
4709
hash_map:: Entry :: Vacant ( _) => return Err ( MsgHandleErrInternal :: send_err_msg_no_close ( "Failed to find corresponding channel" . to_owned ( ) , msg. temporary_channel_id ) )
4710
- }
4711
- } ;
4712
- // Because we have exclusive ownership of the channel here we can release the channel_state
4713
- // lock before watch_channel
4714
- match self . chain_monitor . watch_channel ( monitor. get_funding_txo ( ) . 0 , monitor) {
4715
- ChannelMonitorUpdateStatus :: Completed => { } ,
4716
- ChannelMonitorUpdateStatus :: PermanentFailure => {
4717
- // Note that we reply with the new channel_id in error messages if we gave up on the
4718
- // channel, not the temporary_channel_id. This is compatible with ourselves, but the
4719
- // spec is somewhat ambiguous here. Not a huge deal since we'll send error messages for
4720
- // any messages referencing a previously-closed channel anyway.
4721
- // We do not propagate the monitor update to the user as it would be for a monitor
4722
- // that we didn't manage to store (and that we don't care about - we don't respond
4723
- // with the funding_signed so the channel can never go on chain).
4724
- let ( _monitor_update, failed_htlcs) = chan. force_shutdown ( false ) ;
4725
- assert ! ( failed_htlcs. is_empty( ) ) ;
4726
- return Err ( MsgHandleErrInternal :: send_err_msg_no_close ( "ChannelMonitor storage failure" . to_owned ( ) , funding_msg. channel_id ) ) ;
4727
- } ,
4728
- ChannelMonitorUpdateStatus :: InProgress => {
4729
- // There's no problem signing a counterparty's funding transaction if our monitor
4730
- // hasn't persisted to disk yet - we can't lose money on a transaction that we haven't
4731
- // accepted payment from yet. We do, however, need to wait to send our channel_ready
4732
- // until we have persisted our monitor.
4733
- chan. monitor_updating_paused ( false , false , channel_ready. is_some ( ) , Vec :: new ( ) , Vec :: new ( ) , Vec :: new ( ) ) ;
4734
- channel_ready = None ; // Don't send the channel_ready now
4735
- } ,
4736
- }
4737
- let mut channel_state_lock = self . channel_state . lock ( ) . unwrap ( ) ;
4738
- let channel_state = & mut * channel_state_lock;
4710
+ } ;
4711
+
4739
4712
match channel_state. by_id . entry ( funding_msg. channel_id ) {
4740
4713
hash_map:: Entry :: Occupied ( _) => {
4741
- return Err ( MsgHandleErrInternal :: send_err_msg_no_close ( "Already had channel with the new channel_id" . to_owned ( ) , funding_msg. channel_id ) )
4714
+ Err ( MsgHandleErrInternal :: send_err_msg_no_close ( "Already had channel with the new channel_id" . to_owned ( ) , funding_msg. channel_id ) )
4742
4715
} ,
4743
4716
hash_map:: Entry :: Vacant ( e) => {
4744
4717
let mut id_to_peer = self . id_to_peer . lock ( ) . unwrap ( ) ;
@@ -4752,17 +4725,34 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4752
4725
i_e. insert ( chan. get_counterparty_node_id ( ) ) ;
4753
4726
}
4754
4727
}
4728
+
4729
+ // There's no problem signing a counterparty's funding transaction if our monitor
4730
+ // hasn't persisted to disk yet - we can't lose money on a transaction that we haven't
4731
+ // accepted payment from yet. We do, however, need to wait to send our channel_ready
4732
+ // until we have persisted our monitor.
4755
4733
channel_state. pending_msg_events . push ( events:: MessageSendEvent :: SendFundingSigned {
4756
4734
node_id : counterparty_node_id. clone ( ) ,
4757
4735
msg : funding_msg,
4758
4736
} ) ;
4759
- if let Some ( msg) = channel_ready {
4760
- send_channel_ready ! ( self , channel_state. pending_msg_events, chan, msg) ;
4737
+
4738
+ let monitor_res = self . chain_monitor . watch_channel ( monitor. get_funding_txo ( ) . 0 , monitor) ;
4739
+
4740
+ let chan = e. insert ( chan) ;
4741
+ let mut res = handle_new_monitor_update ! ( self , monitor_res, 0 , channel_lock, channel_state. pending_msg_events, chan, MANUALLY_REMOVING , 42 ) ;
4742
+
4743
+ // Note that we reply with the new channel_id in error messages if we gave up on the
4744
+ // channel, not the temporary_channel_id. This is compatible with ourselves, but the
4745
+ // spec is somewhat ambiguous here. Not a huge deal since we'll send error messages for
4746
+ // any messages referencing a previously-closed channel anyway.
4747
+ // We do not propagate the monitor update to the user as it would be for a monitor
4748
+ // that we didn't manage to store (and that we don't care about - we don't respond
4749
+ // with the funding_signed so the channel can never go on chain).
4750
+ if let Err ( MsgHandleErrInternal { shutdown_finish : Some ( ( res, _) ) , .. } ) = & mut res {
4751
+ res. 0 = None ;
4761
4752
}
4762
- e . insert ( chan ) ;
4753
+ res
4763
4754
}
4764
4755
}
4765
- Ok ( ( ) )
4766
4756
}
4767
4757
4768
4758
fn internal_funding_signed ( & self , counterparty_node_id : & PublicKey , msg : & msgs:: FundingSigned ) -> Result < ( ) , MsgHandleErrInternal > {
0 commit comments