Skip to content

Commit 0b0b56b

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 252a75a commit 0b0b56b

File tree

1 file changed

+20
-33
lines changed

1 file changed

+20
-33
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3711,6 +3711,24 @@ where
37113711
})
37123712
}
37133713

3714+
fn convert_unfunded_channel_err_internal<SP: Deref, CM: AChannelManager>(
3715+
cm: &CM, err: ChannelError, chan: &mut Channel<SP>,
3716+
) -> (bool, MsgHandleErrInternal)
3717+
where
3718+
SP::Target: SignerProvider,
3719+
{
3720+
let chan_id = chan.context().channel_id();
3721+
convert_channel_err_internal(err, chan_id, |reason, msg| {
3722+
let cm = cm.get_cm();
3723+
let logger = WithChannelContext::from(&cm.logger, chan.context(), None);
3724+
3725+
let shutdown_res = chan.force_shutdown(reason);
3726+
log_error!(logger, "Closed channel due to close-required error: {}", msg);
3727+
locked_close_channel!(cm, chan.context(), UNFUNDED);
3728+
(shutdown_res, None)
3729+
})
3730+
}
3731+
37143732
/// When a channel is removed, two things need to happen:
37153733
/// (a) This must be called in the same `per_peer_state` lock as the channel-closing action,
37163734
/// (b) [`handle_error`] needs to be called without holding any locks (except
@@ -3725,34 +3743,6 @@ where
37253743
/// true).
37263744
#[rustfmt::skip]
37273745
macro_rules! convert_channel_err {
3728-
($self: ident, $peer_state: expr, $err: expr, $chan: expr, $close: expr, $locked_close: expr, $channel_id: expr, _internal) => { {
3729-
match $err {
3730-
ChannelError::Warn(msg) => {
3731-
(false, MsgHandleErrInternal::from_chan_no_close(ChannelError::Warn(msg), $channel_id))
3732-
},
3733-
ChannelError::WarnAndDisconnect(msg) => {
3734-
(false, MsgHandleErrInternal::from_chan_no_close(ChannelError::WarnAndDisconnect(msg), $channel_id))
3735-
},
3736-
ChannelError::Ignore(msg) => {
3737-
(false, MsgHandleErrInternal::from_chan_no_close(ChannelError::Ignore(msg), $channel_id))
3738-
},
3739-
ChannelError::Abort(reason) => {
3740-
(false, MsgHandleErrInternal::from_chan_no_close(ChannelError::Abort(reason), $channel_id))
3741-
},
3742-
ChannelError::Close((msg, reason)) => {
3743-
let (mut shutdown_res, chan_update) = $close(reason);
3744-
let logger = WithChannelContext::from(&$self.logger, &$chan.context(), None);
3745-
log_error!(logger, "Closed channel due to close-required error: {}", msg);
3746-
$locked_close(&mut shutdown_res, $chan);
3747-
let err =
3748-
MsgHandleErrInternal::from_finish_shutdown(msg, $channel_id, shutdown_res, chan_update);
3749-
(true, err)
3750-
},
3751-
ChannelError::SendError(msg) => {
3752-
(false, MsgHandleErrInternal::from_chan_no_close(ChannelError::SendError(msg), $channel_id))
3753-
},
3754-
}
3755-
} };
37563746
($self: ident, $peer_state: expr, $shutdown_result: expr, $funded_channel: expr, COOP_CLOSED) => { {
37573747
let reason = ChannelError::Close(("Coop Closed".to_owned(), $shutdown_result.closure_reason.clone()));
37583748
let closed_update_ids = &mut $peer_state.closed_channel_monitor_update_ids;
@@ -3769,10 +3759,7 @@ macro_rules! convert_channel_err {
37693759
convert_funded_channel_err_internal($self, closed_update_ids, in_flight_updates, None, $err, $funded_channel)
37703760
} };
37713761
($self: ident, $peer_state: expr, $err: expr, $channel: expr, UNFUNDED_CHANNEL) => { {
3772-
let chan_id = $channel.context().channel_id();
3773-
let mut do_close = |reason| { ($channel.force_shutdown(reason), None) };
3774-
let locked_close = |_, chan: &mut Channel<_>| { locked_close_channel!($self, chan.context(), UNFUNDED); };
3775-
convert_channel_err!($self, $peer_state, $err, $channel, do_close, locked_close, chan_id, _internal)
3762+
convert_unfunded_channel_err_internal($self, $err, $channel)
37763763
} };
37773764
($self: ident, $peer_state: expr, $err: expr, $channel: expr) => {
37783765
match $channel.as_funded_mut() {
@@ -3782,7 +3769,7 @@ macro_rules! convert_channel_err {
37823769
convert_funded_channel_err_internal($self, closed_update_ids, in_flight_updates, None, $err, funded_channel)
37833770
},
37843771
None => {
3785-
convert_channel_err!($self, $peer_state, $err, $channel, UNFUNDED_CHANNEL)
3772+
convert_unfunded_channel_err_internal($self, $err, $channel)
37863773
},
37873774
}
37883775
};

0 commit comments

Comments
 (0)