Skip to content

Commit 8a3d3ea

Browse files
committed
Functionize the UNFUNDED case in convert_channel_err
`convert_channel_err` is used extensively in `channelmanager.rs` (often indirectly via `try_channel_entry`) and generates nontrivial code (especially once you include `locked_close_channel`). Here we take the `UNFUNDED` case of it and move them to an internal function reducing the generated code size. On the same machine as described three commits ago, this further reduces build times from the previous commit by about another second.
1 parent dc419ee commit 8a3d3ea

File tree

1 file changed

+23
-33
lines changed

1 file changed

+23
-33
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3710,6 +3710,27 @@ where
37103710
})
37113711
}
37123712

3713+
fn convert_unfunded_channel_err_internal<
3714+
SP: Deref,
3715+
CM: AChannelManager,
3716+
>(
3717+
cm: &CM, err: ChannelError, chan: &mut Channel<SP>,
3718+
) -> (bool, MsgHandleErrInternal)
3719+
where
3720+
SP::Target: SignerProvider,
3721+
{
3722+
let chan_id = chan.context().channel_id();
3723+
convert_channel_err_internal(err, chan_id, |reason, msg| {
3724+
let cm = cm.get_cm();
3725+
let logger = WithChannelContext::from(&cm.logger, chan.context(), None);
3726+
3727+
let shutdown_res = chan.force_shutdown(reason);
3728+
log_error!(logger, "Closed channel {} due to close-required error: {}", chan_id, msg);
3729+
locked_close_channel!(cm, chan.context(), UNFUNDED);
3730+
(shutdown_res, None)
3731+
})
3732+
}
3733+
37133734
/// When a channel is removed, two things need to happen:
37143735
/// (a) This must be called in the same `per_peer_state` lock as the channel-closing action,
37153736
/// (b) [`handle_error`] needs to be called without holding any locks (except
@@ -3724,34 +3745,6 @@ where
37243745
/// true).
37253746
#[rustfmt::skip]
37263747
macro_rules! convert_channel_err {
3727-
($self: ident, $peer_state: expr, $err: expr, $chan: expr, $close: expr, $locked_close: expr, $channel_id: expr, _internal) => { {
3728-
match $err {
3729-
ChannelError::Warn(msg) => {
3730-
(false, MsgHandleErrInternal::from_chan_no_close(ChannelError::Warn(msg), $channel_id))
3731-
},
3732-
ChannelError::WarnAndDisconnect(msg) => {
3733-
(false, MsgHandleErrInternal::from_chan_no_close(ChannelError::WarnAndDisconnect(msg), $channel_id))
3734-
},
3735-
ChannelError::Ignore(msg) => {
3736-
(false, MsgHandleErrInternal::from_chan_no_close(ChannelError::Ignore(msg), $channel_id))
3737-
},
3738-
ChannelError::Abort(reason) => {
3739-
(false, MsgHandleErrInternal::from_chan_no_close(ChannelError::Abort(reason), $channel_id))
3740-
},
3741-
ChannelError::Close((msg, reason)) => {
3742-
let (mut shutdown_res, chan_update) = $close(reason);
3743-
let logger = WithChannelContext::from(&$self.logger, &$chan.context(), None);
3744-
log_error!(logger, "Closed channel {} due to close-required error: {}", $channel_id, msg);
3745-
$locked_close(&mut shutdown_res, $chan);
3746-
let err =
3747-
MsgHandleErrInternal::from_finish_shutdown(msg, $channel_id, shutdown_res, chan_update);
3748-
(true, err)
3749-
},
3750-
ChannelError::SendError(msg) => {
3751-
(false, MsgHandleErrInternal::from_chan_no_close(ChannelError::SendError(msg), $channel_id))
3752-
},
3753-
}
3754-
} };
37553748
($self: ident, $peer_state: expr, $shutdown_result: expr, $funded_channel: expr, COOP_CLOSED) => { {
37563749
let reason = ChannelError::Close(("Coop Closed".to_owned(), $shutdown_result.closure_reason.clone()));
37573750
let closed_update_ids = &mut $peer_state.closed_channel_monitor_update_ids;
@@ -3768,10 +3761,7 @@ macro_rules! convert_channel_err {
37683761
convert_funded_channel_err_internal($self, closed_update_ids, in_flight_updates, None, $err, $funded_channel)
37693762
} };
37703763
($self: ident, $peer_state: expr, $err: expr, $channel: expr, UNFUNDED_CHANNEL) => { {
3771-
let chan_id = $channel.context().channel_id();
3772-
let mut do_close = |reason| { ($channel.force_shutdown(reason), None) };
3773-
let locked_close = |_, chan: &mut Channel<_>| { locked_close_channel!($self, chan.context(), UNFUNDED); };
3774-
convert_channel_err!($self, $peer_state, $err, $channel, do_close, locked_close, chan_id, _internal)
3764+
convert_unfunded_channel_err_internal($self, $err, $channel)
37753765
} };
37763766
($self: ident, $peer_state: expr, $err: expr, $channel: expr) => {
37773767
match $channel.as_funded_mut() {
@@ -3781,7 +3771,7 @@ macro_rules! convert_channel_err {
37813771
convert_funded_channel_err_internal($self, closed_update_ids, in_flight_updates, None, $err, funded_channel)
37823772
},
37833773
None => {
3784-
convert_channel_err!($self, $peer_state, $err, $channel, UNFUNDED_CHANNEL)
3774+
convert_unfunded_channel_err_internal($self, $err, $channel)
37853775
},
37863776
}
37873777
};

0 commit comments

Comments
 (0)