Skip to content

Commit 9336f34

Browse files
committed
Convert macro to convert_channel_err_coop method
1 parent 004ceef commit 9336f34

File tree

1 file changed

+31
-14
lines changed

1 file changed

+31
-14
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3611,16 +3611,6 @@ fn convert_channel_err_internal<
36113611
/// true).
36123612
#[rustfmt::skip]
36133613
macro_rules! convert_channel_err {
3614-
($self: ident, $peer_state: expr, $shutdown_result: expr, $funded_channel: expr, COOP_CLOSED) => { {
3615-
let reason = ChannelError::Close(("Coop Closed".to_owned(), $shutdown_result.closure_reason.clone()));
3616-
let closed_update_ids = &mut $peer_state.closed_channel_monitor_update_ids;
3617-
let in_flight_updates = &mut $peer_state.in_flight_monitor_updates;
3618-
let (close, mut err) =
3619-
$self.convert_funded_channel_err_internal(closed_update_ids, in_flight_updates, Some($shutdown_result), reason, $funded_channel);
3620-
err.dont_send_error_message();
3621-
debug_assert!(close);
3622-
err
3623-
} };
36243614
($self: ident, $peer_state: expr, $err: expr, $funded_channel: expr, FUNDED_CHANNEL) => { {
36253615
let closed_update_ids = &mut $peer_state.closed_channel_monitor_update_ids;
36263616
let in_flight_updates = &mut $peer_state.in_flight_monitor_updates;
@@ -4032,6 +4022,32 @@ where
40324022
})
40334023
}
40344024

4025+
/// When a channel is removed, two things need to happen:
4026+
/// (a) This must be called in the same `per_peer_state` lock as the channel-closing action,
4027+
/// (b) [`ChannelManager::handle_error`] needs to be called without holding any locks (except
4028+
/// [`ChannelManager::total_consistency_lock`]), which then calls
4029+
/// [`ChannelManager::finish_close_channel`].
4030+
///
4031+
/// Returns a mapped error.
4032+
fn convert_channel_err_coop(
4033+
&self, closed_update_ids: &mut BTreeMap<ChannelId, u64>,
4034+
in_flight_updates: &mut BTreeMap<ChannelId, (OutPoint, Vec<ChannelMonitorUpdate>)>,
4035+
shutdown_result: ShutdownResult, funded_channel: &mut FundedChannel<SP>,
4036+
) -> MsgHandleErrInternal {
4037+
let reason =
4038+
ChannelError::Close(("Coop Closed".to_owned(), shutdown_result.closure_reason.clone()));
4039+
let (close, mut err) = self.convert_funded_channel_err_internal(
4040+
closed_update_ids,
4041+
in_flight_updates,
4042+
Some(shutdown_result),
4043+
reason,
4044+
funded_channel,
4045+
);
4046+
err.dont_send_error_message();
4047+
debug_assert!(close);
4048+
err
4049+
}
4050+
40354051
/// Gets the current [`UserConfig`] which controls some global behavior and includes the
40364052
/// default configuration applied to all new channels.
40374053
pub fn get_current_config(&self) -> UserConfig {
@@ -11146,7 +11162,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1114611162
// also implies there are no pending HTLCs left on the channel, so we can
1114711163
// fully delete it from tracking (the channel monitor is still around to
1114811164
// watch for old state broadcasts)!
11149-
let err = convert_channel_err!(self, peer_state, close_res, chan, COOP_CLOSED);
11165+
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);
1115011166
chan_entry.remove();
1115111167
Some((tx, Err(err)))
1115211168
} else {
@@ -12467,7 +12483,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1246712483
log_trace!(logger, "Removing channel now that the signer is unblocked");
1246812484
let (remove, err) = if let Some(funded) = chan.as_funded_mut() {
1246912485
let err =
12470-
convert_channel_err!(self, peer_state, shutdown, funded, COOP_CLOSED);
12486+
self.convert_channel_err_coop(&mut peer_state.closed_channel_monitor_update_ids, &mut peer_state.in_flight_monitor_updates, shutdown, funded);
1247112487
(true, err)
1247212488
} else {
1247312489
debug_assert!(false);
@@ -12522,7 +12538,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1252212538
if let Some((tx, shutdown_res)) = tx_shutdown_result_opt {
1252312539
// We're done with this channel. We got a closing_signed and sent back
1252412540
// a closing_signed with a closing transaction to broadcast.
12525-
let err = convert_channel_err!(self, peer_state, shutdown_res, funded_chan, COOP_CLOSED);
12541+
let err = self.convert_channel_err_coop(&mut peer_state.closed_channel_monitor_update_ids, &mut peer_state.in_flight_monitor_updates, shutdown_res, funded_chan);
1252612542
handle_errors.push((*cp_id, Err(err)));
1252712543

1252812544
log_info!(logger, "Broadcasting {}", log_tx!(tx));
@@ -12532,7 +12548,8 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1253212548
},
1253312549
Err(e) => {
1253412550
has_update = true;
12535-
let (close_channel, res) = convert_channel_err!(self, peer_state, e, funded_chan, FUNDED_CHANNEL);
12551+
let (close_channel, res) = convert_channel_err!(
12552+
self, peer_state, e, funded_chan, FUNDED_CHANNEL);
1253612553
handle_errors.push((funded_chan.context.get_counterparty_node_id(), Err(res)));
1253712554
!close_channel
1253812555
}

0 commit comments

Comments
 (0)