@@ -3584,7 +3584,7 @@ macro_rules! break_channel_entry {
35843584 match $res {
35853585 Ok(res) => res,
35863586 Err(e) => {
3587- let (drop, res) = $self.convert_channel_err (
3587+ let (drop, res) = $self.locked_handle_force_close (
35883588 &mut $peer_state.closed_channel_monitor_update_ids,
35893589 &mut $peer_state.in_flight_monitor_updates,
35903590 e,
@@ -3604,7 +3604,7 @@ macro_rules! try_channel_entry {
36043604 match $res {
36053605 Ok(res) => res,
36063606 Err(e) => {
3607- let (drop, res) = $self.convert_channel_err (
3607+ let (drop, res) = $self.locked_handle_force_close (
36083608 &mut $peer_state.closed_channel_monitor_update_ids,
36093609 &mut $peer_state.in_flight_monitor_updates,
36103610 e,
@@ -4225,7 +4225,7 @@ where
42254225 let reason = ClosureReason::LocallyCoopClosedUnfundedChannel;
42264226 let err = ChannelError::Close((reason.to_string(), reason));
42274227 let mut chan = chan_entry.remove();
4228- let (_, mut e) = self.convert_channel_err (
4228+ let (_, mut e) = self.locked_handle_force_close (
42294229 &mut peer_state.closed_channel_monitor_update_ids,
42304230 &mut peer_state.in_flight_monitor_updates,
42314231 err,
@@ -4367,8 +4367,11 @@ where
43674367 }
43684368
43694369 /// When a channel is removed, two things need to happen:
4370- /// (a) [`ChannelManager::convert_channel_err`] must be called in the same `per_peer_state` lock as the
4371- /// channel-closing action,
4370+ /// (a) Handle the initial within-lock closure for the channel via one of the following methods:
4371+ /// [`ChannelManager::locked_handle_unfunded_close`],
4372+ /// [`ChannelManager::locked_handle_funded_coop_close`],
4373+ /// [`ChannelManager::locked_handle_funded_force_close`] or
4374+ /// [`ChannelManager::locked_handle_force_close`].
43724375 /// (b) [`ChannelManager::handle_error`] needs to be called without holding any locks (except
43734376 /// [`ChannelManager::total_consistency_lock`]), which then calls this.
43744377 fn finish_close_channel(&self, mut shutdown_res: ShutdownResult) {
@@ -4437,7 +4440,7 @@ where
44374440 if let Some(mut chan) = peer_state.channel_by_id.remove(&channel_id) {
44384441 let reason = ClosureReason::FundingBatchClosure;
44394442 let err = ChannelError::Close((reason.to_string(), reason));
4440- let (_, e) = self.convert_channel_err (
4443+ let (_, e) = self.locked_handle_force_close (
44414444 &mut peer_state.closed_channel_monitor_update_ids,
44424445 &mut peer_state.in_flight_monitor_updates,
44434446 err,
@@ -4534,7 +4537,7 @@ where
45344537 if let Some(mut chan) = peer_state.channel_by_id.remove(channel_id) {
45354538 log_error!(logger, "Force-closing channel");
45364539 let err = ChannelError::Close((message, reason));
4537- let (_, mut e) = self.convert_channel_err (
4540+ let (_, mut e) = self.locked_handle_force_close (
45384541 &mut peer_state.closed_channel_monitor_update_ids,
45394542 &mut peer_state.in_flight_monitor_updates,
45404543 err,
@@ -4683,7 +4686,12 @@ where
46834686 })
46844687 }
46854688
4686- fn convert_funded_channel_err_internal(
4689+ /// Handle the initial within-lock closure for a funded channel that is either force-closed or cooperatively
4690+ /// closed (as indicated by `coop_close_shutdown_res`).
4691+ ///
4692+ /// Returns `(boolean indicating if we should remove the Channel object from memory, a mapped
4693+ /// error)`.
4694+ fn locked_handle_funded_close_internal(
46874695 &self, closed_channel_monitor_update_ids: &mut BTreeMap<ChannelId, u64>,
46884696 in_flight_monitor_updates: &mut BTreeMap<ChannelId, (OutPoint, Vec<ChannelMonitorUpdate>)>,
46894697 coop_close_shutdown_res: Option<ShutdownResult>, err: ChannelError,
@@ -4745,7 +4753,13 @@ where
47454753 })
47464754 }
47474755
4748- fn convert_unfunded_channel_err_internal(
4756+ /// Handle the initial within-lock closure for an unfunded channel.
4757+ ///
4758+ /// Returns `(boolean indicating if we should remove the Channel object from memory, a mapped
4759+ /// error)`.
4760+ ///
4761+ /// The same closure semantics as described in [`ChannelManager::locked_handle_funded_close`] apply.
4762+ fn locked_handle_unfunded_close(
47494763 &self, err: ChannelError, chan: &mut Channel<SP>,
47504764 ) -> (bool, MsgHandleErrInternal)
47514765 where
@@ -4771,21 +4785,19 @@ where
47714785 })
47724786 }
47734787
4774- /// When a cooperatively closed channel is removed, two things need to happen:
4775- /// (a) This must be called in the same `per_peer_state` lock as the channel-closing action,
4776- /// (b) [`ChannelManager::handle_error`] needs to be called without holding any locks (except
4777- /// [`ChannelManager::total_consistency_lock`]), which then calls
4778- /// [`ChannelManager::finish_close_channel`].
4788+ /// Handle the initial within-lock closure for a channel that is cooperatively closed.
47794789 ///
47804790 /// Returns a mapped error.
4781- fn convert_channel_err_coop(
4791+ ///
4792+ /// The same closure semantics as described in [`ChannelManager::locked_handle_funded_close`] apply.
4793+ fn locked_handle_funded_coop_close(
47824794 &self, closed_update_ids: &mut BTreeMap<ChannelId, u64>,
47834795 in_flight_updates: &mut BTreeMap<ChannelId, (OutPoint, Vec<ChannelMonitorUpdate>)>,
47844796 shutdown_result: ShutdownResult, funded_channel: &mut FundedChannel<SP>,
47854797 ) -> MsgHandleErrInternal {
47864798 let reason =
47874799 ChannelError::Close(("Coop Closed".to_owned(), shutdown_result.closure_reason.clone()));
4788- let (close, mut err) = self.convert_funded_channel_err_internal (
4800+ let (close, mut err) = self.locked_handle_funded_close_internal (
47894801 closed_update_ids,
47904802 in_flight_updates,
47914803 Some(shutdown_result),
@@ -4797,20 +4809,18 @@ where
47974809 err
47984810 }
47994811
4800- /// When a funded channel is removed, two things need to happen:
4801- /// (a) This must be called in the same `per_peer_state` lock as the channel-closing action,
4802- /// (b) [`ChannelManager::handle_error`] needs to be called without holding any locks (except
4803- /// [`ChannelManager::total_consistency_lock`]), which then calls
4804- /// [`ChannelManager::finish_close_channel`].
4812+ /// Handle the initial within-lock closure for a funded channel that is force-closed.
48054813 ///
48064814 /// Returns `(boolean indicating if we should remove the Channel object from memory, a mapped
48074815 /// error)`.
4808- fn convert_channel_err_funded(
4816+ ///
4817+ /// The same closure semantics as described in [`ChannelManager::locked_handle_funded_close`] apply.
4818+ fn locked_handle_funded_force_close(
48094819 &self, closed_update_ids: &mut BTreeMap<ChannelId, u64>,
48104820 in_flight_updates: &mut BTreeMap<ChannelId, (OutPoint, Vec<ChannelMonitorUpdate>)>,
48114821 err: ChannelError, funded_channel: &mut FundedChannel<SP>,
48124822 ) -> (bool, MsgHandleErrInternal) {
4813- self.convert_funded_channel_err_internal (
4823+ self.locked_handle_funded_close_internal (
48144824 closed_update_ids,
48154825 in_flight_updates,
48164826 None,
@@ -4819,31 +4829,26 @@ where
48194829 )
48204830 }
48214831
4822- /// When a channel that can be funded or unfunded is removed, two things need to happen:
4823- /// (a) This must be called in the same `per_peer_state` lock as the channel-closing action,
4824- /// (b) [`ChannelManager::handle_error`] needs to be called without holding any locks (except
4825- /// [`ChannelManager::total_consistency_lock`]), which then calls
4826- /// [`ChannelManager::finish_close_channel`].
4827- ///
4828- /// Note that this step can be skipped if the channel was never opened (through the creation of a
4829- /// [`ChannelMonitor`]/channel funding transaction) to begin with.
4832+ /// Handle the initial within-lock closure for a channel that is force-closed.
48304833 ///
48314834 /// Returns `(boolean indicating if we should remove the Channel object from memory, a mapped
48324835 /// error)`.
4833- fn convert_channel_err(
4836+ ///
4837+ /// The same closure semantics as described in [`ChannelManager::locked_handle_funded_close`] apply.
4838+ fn locked_handle_force_close(
48344839 &self, closed_update_ids: &mut BTreeMap<ChannelId, u64>,
48354840 in_flight_updates: &mut BTreeMap<ChannelId, (OutPoint, Vec<ChannelMonitorUpdate>)>,
48364841 err: ChannelError, channel: &mut Channel<SP>,
48374842 ) -> (bool, MsgHandleErrInternal) {
48384843 match channel.as_funded_mut() {
4839- Some(funded_channel) => self.convert_funded_channel_err_internal (
4844+ Some(funded_channel) => self.locked_handle_funded_close_internal (
48404845 closed_update_ids,
48414846 in_flight_updates,
48424847 None,
48434848 err,
48444849 funded_channel,
48454850 ),
4846- None => self.convert_unfunded_channel_err_internal (err, channel),
4851+ None => self.locked_handle_unfunded_close (err, channel),
48474852 }
48484853 }
48494854
@@ -6566,7 +6571,7 @@ where
65666571 let reason = ClosureReason::ProcessingError { err: e.clone() };
65676572 let err = ChannelError::Close((e.clone(), reason));
65686573 let peer_state = &mut *peer_state_lock;
6569- let (_, e) = self.convert_channel_err (
6574+ let (_, e) = self.locked_handle_force_close (
65706575 &mut peer_state.closed_channel_monitor_update_ids,
65716576 &mut peer_state.in_flight_monitor_updates,
65726577 err,
@@ -8333,7 +8338,7 @@ where
83338338 if chan_needs_persist == NotifyOption::DoPersist { should_persist = NotifyOption::DoPersist; }
83348339
83358340 if let Err(e) = funded_chan.timer_check_closing_negotiation_progress() {
8336- let (needs_close, err) = self.convert_channel_err_funded (&mut peer_state.closed_channel_monitor_update_ids, &mut peer_state.in_flight_monitor_updates, e, funded_chan);
8341+ let (needs_close, err) = self.locked_handle_funded_force_close (&mut peer_state.closed_channel_monitor_update_ids, &mut peer_state.in_flight_monitor_updates, e, funded_chan);
83378342 handle_errors.push((Err(err), counterparty_node_id));
83388343 if needs_close { return false; }
83398344 }
@@ -8410,7 +8415,7 @@ where
84108415 let reason = ClosureReason::FundingTimedOut;
84118416 let msg = "Force-closing pending channel due to timeout awaiting establishment handshake".to_owned();
84128417 let err = ChannelError::Close((msg, reason));
8413- let (_, e) = self.convert_channel_err (
8418+ let (_, e) = self.locked_handle_force_close (
84148419 &mut peer_state.closed_channel_monitor_update_ids,
84158420 &mut peer_state.in_flight_monitor_updates,
84168421 err,
@@ -10614,7 +10619,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1061410619 // concerning this channel as it is safe to do so.
1061510620 debug_assert!(matches!(err, ChannelError::Close(_)));
1061610621 let mut chan = Channel::from(inbound_chan);
10617- return Err(self.convert_channel_err (
10622+ return Err(self.locked_handle_force_close (
1061810623 &mut peer_state.closed_channel_monitor_update_ids,
1061910624 &mut peer_state.in_flight_monitor_updates,
1062010625 err,
@@ -10626,7 +10631,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1062610631 Some(Err(mut chan)) => {
1062710632 let err_msg = format!("Got an unexpected funding_created message from peer with counterparty_node_id {}", counterparty_node_id);
1062810633 let err = ChannelError::close(err_msg);
10629- return Err(self.convert_channel_err (
10634+ return Err(self.locked_handle_force_close (
1063010635 &mut peer_state.closed_channel_monitor_update_ids,
1063110636 &mut peer_state.in_flight_monitor_updates,
1063210637 err,
@@ -10647,7 +10652,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1064710652 let err = ChannelError::close($err.to_owned());
1064810653 chan.unset_funding_info();
1064910654 let mut chan = Channel::from(chan);
10650- return Err(self.convert_unfunded_channel_err_internal (err, &mut chan).1);
10655+ return Err(self.locked_handle_unfunded_close (err, &mut chan).1);
1065110656 }};
1065210657 }
1065310658
@@ -11267,7 +11272,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1126711272 let reason = ClosureReason::CounterpartyCoopClosedUnfundedChannel;
1126811273 let err = ChannelError::Close((reason.to_string(), reason));
1126911274 let mut chan = chan_entry.remove();
11270- let (_, mut e) = self.convert_channel_err (
11275+ let (_, mut e) = self.locked_handle_force_close (
1127111276 &mut peer_state.closed_channel_monitor_update_ids,
1127211277 &mut peer_state.in_flight_monitor_updates,
1127311278 err,
@@ -11332,7 +11337,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1133211337 // also implies there are no pending HTLCs left on the channel, so we can
1133311338 // fully delete it from tracking (the channel monitor is still around to
1133411339 // watch for old state broadcasts)!
11335- let err = self.convert_channel_err_coop (&mut peer_state.closed_channel_monitor_update_ids, &mut peer_state.in_flight_monitor_updates, close_res, chan);
11340+ let err = self.locked_handle_funded_coop_close (&mut peer_state.closed_channel_monitor_update_ids, &mut peer_state.in_flight_monitor_updates, close_res, chan);
1133611341 chan_entry.remove();
1133711342 Some((tx, Err(err)))
1133811343 } else {
@@ -12421,7 +12426,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1242112426 };
1242212427 let err = ChannelError::Close((reason.to_string(), reason));
1242312428 let mut chan = chan_entry.remove();
12424- let (_, e) = self.convert_channel_err (
12429+ let (_, e) = self.locked_handle_force_close (
1242512430 &mut peer_state.closed_channel_monitor_update_ids,
1242612431 &mut peer_state.in_flight_monitor_updates,
1242712432 err,
@@ -12442,7 +12447,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1244212447 let reason = ClosureReason::CommitmentTxConfirmed;
1244312448 let err = ChannelError::Close((reason.to_string(), reason));
1244412449 let mut chan = chan_entry.remove();
12445- let (_, e) = self.convert_channel_err (
12450+ let (_, e) = self.locked_handle_force_close (
1244612451 &mut peer_state.closed_channel_monitor_update_ids,
1244712452 &mut peer_state.in_flight_monitor_updates,
1244812453 err,
@@ -12639,7 +12644,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1263912644 _ => match unblock_chan(chan, &mut peer_state.pending_msg_events) {
1264012645 Ok(shutdown_result) => shutdown_result,
1264112646 Err(err) => {
12642- let (_, err) = self.convert_channel_err (
12647+ let (_, err) = self.locked_handle_force_close (
1264312648 &mut peer_state.closed_channel_monitor_update_ids,
1264412649 &mut peer_state.in_flight_monitor_updates,
1264512650 err,
@@ -12655,7 +12660,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1265512660 let logger = WithChannelContext::from(&self.logger, context, None);
1265612661 log_trace!(logger, "Removing channel now that the signer is unblocked");
1265712662 let (remove, err) = if let Some(funded) = chan.as_funded_mut() {
12658- let err = self.convert_channel_err_coop (
12663+ let err = self.locked_handle_funded_coop_close (
1265912664 &mut peer_state.closed_channel_monitor_update_ids,
1266012665 &mut peer_state.in_flight_monitor_updates,
1266112666 shutdown,
@@ -12666,7 +12671,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1266612671 debug_assert!(false);
1266712672 let reason = shutdown.closure_reason.clone();
1266812673 let err = ChannelError::Close((reason.to_string(), reason));
12669- self.convert_unfunded_channel_err_internal (err, chan)
12674+ self.locked_handle_unfunded_close (err, chan)
1267012675 };
1267112676 debug_assert!(remove);
1267212677 shutdown_results.push((Err(err), *cp_id));
@@ -12725,7 +12730,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1272512730 if let Some((tx, shutdown_res)) = tx_shutdown_result_opt {
1272612731 // We're done with this channel. We got a closing_signed and sent back
1272712732 // a closing_signed with a closing transaction to broadcast.
12728- let err = self.convert_channel_err_coop (
12733+ let err = self.locked_handle_funded_coop_close (
1272912734 &mut peer_state.closed_channel_monitor_update_ids,
1273012735 &mut peer_state.in_flight_monitor_updates,
1273112736 shutdown_res,
@@ -12742,12 +12747,13 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1274212747 },
1274312748 Err(e) => {
1274412749 has_update = true;
12745- let (close_channel, res) = self.convert_channel_err_funded(
12746- &mut peer_state.closed_channel_monitor_update_ids,
12747- &mut peer_state.in_flight_monitor_updates,
12748- e,
12749- funded_chan,
12750- );
12750+ let (close_channel, res) = self
12751+ .locked_handle_funded_force_close(
12752+ &mut peer_state.closed_channel_monitor_update_ids,
12753+ &mut peer_state.in_flight_monitor_updates,
12754+ e,
12755+ funded_chan,
12756+ );
1275112757 handle_errors.push((
1275212758 funded_chan.context.get_counterparty_node_id(),
1275312759 Err(res),
@@ -14117,7 +14123,7 @@ where
1411714123 // Clean up for removal.
1411814124 let reason = ClosureReason::DisconnectedPeer;
1411914125 let err = ChannelError::Close((reason.to_string(), reason));
14120- let (_, e) = self.convert_channel_err (
14126+ let (_, e) = self.locked_handle_force_close (
1412114127 &mut peer_state.closed_channel_monitor_update_ids,
1412214128 &mut peer_state.in_flight_monitor_updates,
1412314129 err,
@@ -14874,7 +14880,7 @@ where
1487414880 // It looks like our counterparty went on-chain or funding transaction was
1487514881 // reorged out of the main chain. Close the channel.
1487614882 let err = ChannelError::Close((reason.to_string(), reason));
14877- let (_, e) = self.convert_channel_err_funded (
14883+ let (_, e) = self.locked_handle_funded_force_close (
1487814884 &mut peer_state.closed_channel_monitor_update_ids, &mut peer_state.in_flight_monitor_updates,
1487914885 err,
1488014886 funded_channel
0 commit comments