Skip to content

Commit d87ca83

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 d567f4a commit d87ca83

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
@@ -3691,6 +3691,27 @@ where
36913691
})
36923692
}
36933693

3694+
fn convert_unfunded_channel_err_internal<
3695+
SP: Deref,
3696+
CM: AChannelManager,
3697+
>(
3698+
cm: &CM, err: ChannelError, chan: &mut Channel<SP>,
3699+
) -> (bool, MsgHandleErrInternal)
3700+
where
3701+
SP::Target: SignerProvider,
3702+
{
3703+
let chan_id = chan.context().channel_id();
3704+
convert_channel_err_internal(err, chan_id, |reason, msg| {
3705+
let cm = cm.get_cm();
3706+
let logger = WithChannelContext::from(&cm.logger, chan.context(), None);
3707+
3708+
let shutdown_res = chan.force_shutdown(reason);
3709+
log_error!(logger, "Closed channel {} due to close-required error: {}", chan_id, msg);
3710+
locked_close_channel!(cm, chan.context(), UNFUNDED);
3711+
(shutdown_res, None)
3712+
})
3713+
}
3714+
36943715
/// When a channel is removed, two things need to happen:
36953716
/// (a) This must be called in the same `per_peer_state` lock as the channel-closing action,
36963717
/// (b) [`handle_error`] needs to be called without holding any locks (except
@@ -3705,34 +3726,6 @@ where
37053726
/// true).
37063727
#[rustfmt::skip]
37073728
macro_rules! convert_channel_err {
3708-
($self: ident, $peer_state: expr, $err: expr, $chan: expr, $close: expr, $locked_close: expr, $channel_id: expr, _internal) => { {
3709-
match $err {
3710-
ChannelError::Warn(msg) => {
3711-
(false, MsgHandleErrInternal::from_chan_no_close(ChannelError::Warn(msg), $channel_id))
3712-
},
3713-
ChannelError::WarnAndDisconnect(msg) => {
3714-
(false, MsgHandleErrInternal::from_chan_no_close(ChannelError::WarnAndDisconnect(msg), $channel_id))
3715-
},
3716-
ChannelError::Ignore(msg) => {
3717-
(false, MsgHandleErrInternal::from_chan_no_close(ChannelError::Ignore(msg), $channel_id))
3718-
},
3719-
ChannelError::Abort(reason) => {
3720-
(false, MsgHandleErrInternal::from_chan_no_close(ChannelError::Abort(reason), $channel_id))
3721-
},
3722-
ChannelError::Close((msg, reason)) => {
3723-
let (mut shutdown_res, chan_update) = $close(reason);
3724-
let logger = WithChannelContext::from(&$self.logger, &$chan.context(), None);
3725-
log_error!(logger, "Closed channel {} due to close-required error: {}", $channel_id, msg);
3726-
$locked_close(&mut shutdown_res, $chan);
3727-
let err =
3728-
MsgHandleErrInternal::from_finish_shutdown(msg, $channel_id, shutdown_res, chan_update);
3729-
(true, err)
3730-
},
3731-
ChannelError::SendError(msg) => {
3732-
(false, MsgHandleErrInternal::from_chan_no_close(ChannelError::SendError(msg), $channel_id))
3733-
},
3734-
}
3735-
} };
37363729
($self: ident, $peer_state: expr, $shutdown_result: expr, $funded_channel: expr, COOP_CLOSED) => { {
37373730
let reason = ChannelError::Close(("Coop Closed".to_owned(), $shutdown_result.closure_reason.clone()));
37383731
let closed_update_ids = &mut $peer_state.closed_channel_monitor_update_ids;
@@ -3749,10 +3742,7 @@ macro_rules! convert_channel_err {
37493742
convert_funded_channel_err_internal($self, closed_update_ids, in_flight_updates, None, $err, $funded_channel)
37503743
} };
37513744
($self: ident, $peer_state: expr, $err: expr, $channel: expr, UNFUNDED_CHANNEL) => { {
3752-
let chan_id = $channel.context().channel_id();
3753-
let mut do_close = |reason| { ($channel.force_shutdown(reason), None) };
3754-
let locked_close = |_, chan: &mut Channel<_>| { locked_close_channel!($self, chan.context(), UNFUNDED); };
3755-
convert_channel_err!($self, $peer_state, $err, $channel, do_close, locked_close, chan_id, _internal)
3745+
convert_unfunded_channel_err_internal($self, $err, $channel)
37563746
} };
37573747
($self: ident, $peer_state: expr, $err: expr, $channel: expr) => {
37583748
match $channel.as_funded_mut() {
@@ -3762,7 +3752,7 @@ macro_rules! convert_channel_err {
37623752
convert_funded_channel_err_internal($self, closed_update_ids, in_flight_updates, None, $err, funded_channel)
37633753
},
37643754
None => {
3765-
convert_channel_err!($self, $peer_state, $err, $channel, UNFUNDED_CHANNEL)
3755+
convert_unfunded_channel_err_internal($self, $err, $channel)
37663756
},
37673757
}
37683758
};

0 commit comments

Comments
 (0)