@@ -3802,7 +3802,7 @@ where
3802
3802
3803
3803
let mut peer_state_lock = peer_state_mutex.lock().unwrap();
3804
3804
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) {
3806
3806
Some(ChannelPhase::UnfundedOutboundV1(chan)) => {
3807
3807
let funding_txo = find_funding_output(&chan, &funding_transaction)?;
3808
3808
@@ -3841,10 +3841,12 @@ where
3841
3841
}),
3842
3842
};
3843
3843
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
+ }
3848
3850
match peer_state.channel_by_id.entry(chan.context.channel_id()) {
3849
3851
hash_map::Entry::Occupied(_) => {
3850
3852
panic!("Generated duplicate funding txid?");
@@ -6229,7 +6231,7 @@ where
6229
6231
6230
6232
let mut peer_state_lock = peer_state_mutex.lock().unwrap();
6231
6233
let peer_state = &mut *peer_state_lock;
6232
- let (chan, funding_msg , monitor) =
6234
+ let (chan, funding_msg_opt , monitor) =
6233
6235
match peer_state.channel_by_id.remove(&msg.temporary_channel_id) {
6234
6236
Some(ChannelPhase::UnfundedInboundV1(inbound_chan)) => {
6235
6237
match inbound_chan.funding_created(msg, best_block, &self.signer_provider, &self.logger) {
@@ -6252,17 +6254,20 @@ where
6252
6254
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))
6253
6255
};
6254
6256
6255
- match peer_state.channel_by_id.entry(funding_msg. channel_id) {
6257
+ match peer_state.channel_by_id.entry(chan.context. channel_id() ) {
6256
6258
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
+ ))
6258
6263
},
6259
6264
hash_map::Entry::Vacant(e) => {
6260
6265
let mut id_to_peer_lock = self.id_to_peer.lock().unwrap();
6261
6266
match id_to_peer_lock.entry(chan.context.channel_id()) {
6262
6267
hash_map::Entry::Occupied(_) => {
6263
6268
return Err(MsgHandleErrInternal::send_err_msg_no_close(
6264
6269
"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() ))
6266
6271
},
6267
6272
hash_map::Entry::Vacant(i_e) => {
6268
6273
let monitor_res = self.chain_monitor.watch_channel(monitor.get_funding_txo().0, monitor);
@@ -6274,10 +6279,12 @@ where
6274
6279
// hasn't persisted to disk yet - we can't lose money on a transaction that we haven't
6275
6280
// accepted payment from yet. We do, however, need to wait to send our channel_ready
6276
6281
// 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
+ }
6281
6288
6282
6289
if let ChannelPhase::Funded(chan) = e.insert(ChannelPhase::Funded(chan)) {
6283
6290
handle_new_monitor_update!(self, persist_state, peer_state_lock, peer_state,
@@ -6288,9 +6295,13 @@ where
6288
6295
Ok(())
6289
6296
} else {
6290
6297
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
+ };
6291
6302
return Err(MsgHandleErrInternal::send_err_msg_no_close(
6292
6303
"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));
6294
6305
}
6295
6306
}
6296
6307
}
@@ -7216,6 +7227,66 @@ where
7216
7227
has_update
7217
7228
}
7218
7229
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
+
7219
7290
/// Check whether any channels have finished removing all pending updates after a shutdown
7220
7291
/// exchange and can now send a closing_signed.
7221
7292
/// Returns whether any closing_signed messages were generated.
0 commit comments