@@ -3802,7 +3802,7 @@ where
38023802
38033803 let mut peer_state_lock = peer_state_mutex.lock().unwrap();
38043804 let peer_state = &mut *peer_state_lock;
3805- let (chan, msg ) = match peer_state.channel_by_id.remove(temporary_channel_id) {
3805+ let (chan, msg_opt ) = match peer_state.channel_by_id.remove(temporary_channel_id) {
38063806 Some(ChannelPhase::UnfundedOutboundV1(chan)) => {
38073807 let funding_txo = find_funding_output(&chan, &funding_transaction)?;
38083808
@@ -3841,10 +3841,12 @@ where
38413841 }),
38423842 };
38433843
3844- peer_state.pending_msg_events.push(events::MessageSendEvent::SendFundingCreated {
3845- node_id: chan.context.get_counterparty_node_id(),
3846- msg,
3847- });
3844+ if let Some(msg) = msg_opt {
3845+ peer_state.pending_msg_events.push(events::MessageSendEvent::SendFundingCreated {
3846+ node_id: chan.context.get_counterparty_node_id(),
3847+ msg,
3848+ });
3849+ }
38483850 match peer_state.channel_by_id.entry(chan.context.channel_id()) {
38493851 hash_map::Entry::Occupied(_) => {
38503852 panic!("Generated duplicate funding txid?");
@@ -6229,7 +6231,7 @@ where
62296231
62306232 let mut peer_state_lock = peer_state_mutex.lock().unwrap();
62316233 let peer_state = &mut *peer_state_lock;
6232- let (chan, funding_msg , monitor) =
6234+ let (chan, funding_msg_opt , monitor) =
62336235 match peer_state.channel_by_id.remove(&msg.temporary_channel_id) {
62346236 Some(ChannelPhase::UnfundedInboundV1(inbound_chan)) => {
62356237 match inbound_chan.funding_created(msg, best_block, &self.signer_provider, &self.logger) {
@@ -6252,17 +6254,20 @@ where
62526254 None => 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))
62536255 };
62546256
6255- match peer_state.channel_by_id.entry(funding_msg. channel_id) {
6257+ match peer_state.channel_by_id.entry(chan.context. channel_id() ) {
62566258 hash_map::Entry::Occupied(_) => {
6257- Err(MsgHandleErrInternal::send_err_msg_no_close("Already had channel with the new channel_id".to_owned(), funding_msg.channel_id))
6259+ Err(MsgHandleErrInternal::send_err_msg_no_close(
6260+ "Already had channel with the new channel_id".to_owned(),
6261+ chan.context.channel_id()
6262+ ))
62586263 },
62596264 hash_map::Entry::Vacant(e) => {
62606265 let mut id_to_peer_lock = self.id_to_peer.lock().unwrap();
62616266 match id_to_peer_lock.entry(chan.context.channel_id()) {
62626267 hash_map::Entry::Occupied(_) => {
62636268 return Err(MsgHandleErrInternal::send_err_msg_no_close(
62646269 "The funding_created message had the same funding_txid as an existing channel - funding is not possible".to_owned(),
6265- funding_msg. channel_id))
6270+ chan.context. channel_id() ))
62666271 },
62676272 hash_map::Entry::Vacant(i_e) => {
62686273 let monitor_res = self.chain_monitor.watch_channel(monitor.get_funding_txo().0, monitor);
@@ -6274,10 +6279,12 @@ where
62746279 // hasn't persisted to disk yet - we can't lose money on a transaction that we haven't
62756280 // accepted payment from yet. We do, however, need to wait to send our channel_ready
62766281 // until we have persisted our monitor.
6277- peer_state.pending_msg_events.push(events::MessageSendEvent::SendFundingSigned {
6278- node_id: counterparty_node_id.clone(),
6279- msg: funding_msg,
6280- });
6282+ if let Some(msg) = funding_msg_opt {
6283+ peer_state.pending_msg_events.push(events::MessageSendEvent::SendFundingSigned {
6284+ node_id: counterparty_node_id.clone(),
6285+ msg,
6286+ });
6287+ }
62816288
62826289 if let ChannelPhase::Funded(chan) = e.insert(ChannelPhase::Funded(chan)) {
62836290 handle_new_monitor_update!(self, persist_state, peer_state_lock, peer_state,
@@ -6288,9 +6295,13 @@ where
62886295 Ok(())
62896296 } else {
62906297 log_error!(self.logger, "Persisting initial ChannelMonitor failed, implying the funding outpoint was duplicated");
6298+ let channel_id = match funding_msg_opt {
6299+ Some(msg) => msg.channel_id,
6300+ None => chan.context.channel_id(),
6301+ };
62916302 return Err(MsgHandleErrInternal::send_err_msg_no_close(
62926303 "The funding_created message had the same funding_txid as an existing channel - funding is not possible".to_owned(),
6293- funding_msg. channel_id));
6304+ channel_id));
62946305 }
62956306 }
62966307 }
@@ -7216,6 +7227,66 @@ where
72167227 has_update
72177228 }
72187229
7230+ /// When a call to a [`ChannelSigner`] method returns an error, this indicates that the signer
7231+ /// is (temporarily) unavailable, and the operation should be retried later.
7232+ ///
7233+ /// This method allows for that retry - either checking for any signer-pending messages to be
7234+ /// attempted in every channel, or in the specifically provided channel.
7235+ ///
7236+ /// [`ChannelSigner`]: crate::sign::ChannelSigner
7237+ #[cfg(test)] // This is only implemented for one signer method, and should be private until we
7238+ // actually finish implementing it fully.
7239+ pub fn signer_unblocked(&self, channel_opt: Option<(PublicKey, ChannelId)>) {
7240+ let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
7241+
7242+ let unblock_chan = |phase: &mut ChannelPhase<SP>, pending_msg_events: &mut Vec<MessageSendEvent>| {
7243+ let node_id = phase.context().get_counterparty_node_id();
7244+ if let ChannelPhase::Funded(chan) = phase {
7245+ let msgs = chan.signer_maybe_unblocked(&self.logger);
7246+ if let Some(updates) = msgs.commitment_update {
7247+ pending_msg_events.push(events::MessageSendEvent::UpdateHTLCs {
7248+ node_id,
7249+ updates,
7250+ });
7251+ }
7252+ if let Some(msg) = msgs.funding_signed {
7253+ pending_msg_events.push(events::MessageSendEvent::SendFundingSigned {
7254+ node_id,
7255+ msg,
7256+ });
7257+ }
7258+ if let Some(msg) = msgs.funding_created {
7259+ pending_msg_events.push(events::MessageSendEvent::SendFundingCreated {
7260+ node_id,
7261+ msg,
7262+ });
7263+ }
7264+ if let Some(msg) = msgs.channel_ready {
7265+ send_channel_ready!(self, pending_msg_events, chan, msg);
7266+ }
7267+ }
7268+ };
7269+
7270+ let per_peer_state = self.per_peer_state.read().unwrap();
7271+ if let Some((counterparty_node_id, channel_id)) = channel_opt {
7272+ if let Some(peer_state_mutex) = per_peer_state.get(&counterparty_node_id) {
7273+ let mut peer_state_lock = peer_state_mutex.lock().unwrap();
7274+ let peer_state = &mut *peer_state_lock;
7275+ if let Some(chan) = peer_state.channel_by_id.get_mut(&channel_id) {
7276+ unblock_chan(chan, &mut peer_state.pending_msg_events);
7277+ }
7278+ }
7279+ } else {
7280+ for (_cp_id, peer_state_mutex) in per_peer_state.iter() {
7281+ let mut peer_state_lock = peer_state_mutex.lock().unwrap();
7282+ let peer_state = &mut *peer_state_lock;
7283+ for (_, chan) in peer_state.channel_by_id.iter_mut() {
7284+ unblock_chan(chan, &mut peer_state.pending_msg_events);
7285+ }
7286+ }
7287+ }
7288+ }
7289+
72197290 /// Check whether any channels have finished removing all pending updates after a shutdown
72207291 /// exchange and can now send a closing_signed.
72217292 /// Returns whether any closing_signed messages were generated.
0 commit comments