Skip to content

Commit ba2114e

Browse files
committed
Convert macro to convert_channel_err_funded method
1 parent 9336f34 commit ba2114e

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3611,11 +3611,6 @@ fn convert_channel_err_internal<
36113611
/// true).
36123612
#[rustfmt::skip]
36133613
macro_rules! convert_channel_err {
3614-
($self: ident, $peer_state: expr, $err: expr, $funded_channel: expr, FUNDED_CHANNEL) => { {
3615-
let closed_update_ids = &mut $peer_state.closed_channel_monitor_update_ids;
3616-
let in_flight_updates = &mut $peer_state.in_flight_monitor_updates;
3617-
$self.convert_funded_channel_err_internal(closed_update_ids, in_flight_updates, None, $err, $funded_channel)
3618-
} };
36193614
($self: ident, $peer_state: expr, $err: expr, $channel: expr, UNFUNDED_CHANNEL) => { {
36203615
$self.convert_unfunded_channel_err_internal($err, $channel)
36213616
} };
@@ -4048,6 +4043,28 @@ where
40484043
err
40494044
}
40504045

4046+
/// When a channel is removed, two things need to happen:
4047+
/// (a) This must be called in the same `per_peer_state` lock as the channel-closing action,
4048+
/// (b) [`ChannelManager::handle_error`] needs to be called without holding any locks (except
4049+
/// [`ChannelManager::total_consistency_lock`]), which then calls
4050+
/// [`ChannelManager::finish_close_channel`].
4051+
///
4052+
/// Returns `(boolean indicating if we should remove the Channel object from memory, a mapped
4053+
/// error)`.
4054+
fn convert_channel_err_funded(
4055+
&self, closed_update_ids: &mut BTreeMap<ChannelId, u64>,
4056+
in_flight_updates: &mut BTreeMap<ChannelId, (OutPoint, Vec<ChannelMonitorUpdate>)>,
4057+
err: ChannelError, funded_channel: &mut FundedChannel<SP>,
4058+
) -> (bool, MsgHandleErrInternal) {
4059+
self.convert_funded_channel_err_internal(
4060+
closed_update_ids,
4061+
in_flight_updates,
4062+
None,
4063+
err,
4064+
funded_channel,
4065+
)
4066+
}
4067+
40514068
/// Gets the current [`UserConfig`] which controls some global behavior and includes the
40524069
/// default configuration applied to all new channels.
40534070
pub fn get_current_config(&self) -> UserConfig {
@@ -8192,7 +8209,7 @@ where
81928209
if chan_needs_persist == NotifyOption::DoPersist { should_persist = NotifyOption::DoPersist; }
81938210

81948211
if let Err(e) = funded_chan.timer_check_closing_negotiation_progress() {
8195-
let (needs_close, err) = convert_channel_err!(self, peer_state, e, funded_chan, FUNDED_CHANNEL);
8212+
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);
81968213
handle_errors.push((Err(err), counterparty_node_id));
81978214
if needs_close { return false; }
81988215
}
@@ -12548,8 +12565,8 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1254812565
},
1254912566
Err(e) => {
1255012567
has_update = true;
12551-
let (close_channel, res) = convert_channel_err!(
12552-
self, peer_state, e, funded_chan, FUNDED_CHANNEL);
12568+
let (close_channel, res) = self.convert_channel_err_funded(
12569+
&mut peer_state.closed_channel_monitor_update_ids, &mut peer_state.in_flight_monitor_updates, e, funded_chan);
1255312570
handle_errors.push((funded_chan.context.get_counterparty_node_id(), Err(res)));
1255412571
!close_channel
1255512572
}
@@ -14657,12 +14674,10 @@ where
1465714674
// It looks like our counterparty went on-chain or funding transaction was
1465814675
// reorged out of the main chain. Close the channel.
1465914676
let err = ChannelError::Close((reason.to_string(), reason));
14660-
let (_, e) = convert_channel_err!(
14661-
self,
14662-
peer_state,
14677+
let (_, e) = self.convert_channel_err_funded(
14678+
&mut peer_state.closed_channel_monitor_update_ids, &mut peer_state.in_flight_monitor_updates,
1466314679
err,
14664-
funded_channel,
14665-
FUNDED_CHANNEL
14680+
funded_channel
1466614681
);
1466714682
failed_channels.push((Err(e), *counterparty_node_id));
1466814683
return false;

0 commit comments

Comments
 (0)