Functionize the UNFUNDED case in `convert_channel_err`
What changed, and why it matters
This commit is a pure code cleanup: it extracts the handling of unfunded channels from a large macro into a small internal function. There is no change to user-visible behavior, no bug fix, and no security relevance.
No security action needed; treat as routine refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors convert_channel_err! in lightning/src/ln/channelmanager.rs by moving the UNFUNDED_CHANNEL arm into a new convert_unfunded_channel_err_internal function. The new function calls the same convert_channel_err_internal, force_shutdown, logging, and locked_close_channel! logic that the macro arm previously invoked. The commit message explicitly states the goal is reducing generated code size and build times. No logic, error handling paths, or state transitions are altered.
Changed components
lightning/src/ln/channelmanager.rsInspect captured patch +20 / −33
diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs
index 000e081..ec22d1c 100644
--- a/lightning/src/ln/channelmanager.rs
+++ b/lightning/src/ln/channelmanager.rs
@@ -3711,6 +3711,24 @@ where
})
}
+fn convert_unfunded_channel_err_internal<SP: Deref, CM: AChannelManager>(
+ cm: &CM, err: ChannelError, chan: &mut Channel<SP>,
+) -> (bool, MsgHandleErrInternal)
+where
+ SP::Target: SignerProvider,
+{
+ let chan_id = chan.context().channel_id();
+ convert_channel_err_internal(err, chan_id, |reason, msg| {
+ let cm = cm.get_cm();
+ let logger = WithChannelContext::from(&cm.logger, chan.context(), None);
+
+ let shutdown_res = chan.force_shutdown(reason);
+ log_error!(logger, "Closed channel due to close-required error: {}", msg);
+ locked_close_channel!(cm, chan.context(), UNFUNDED);
+ (shutdown_res, None)
+ })
+}
+
/// When a channel is removed, two things need to happen:
/// (a) This must be called in the same `per_peer_state` lock as the channel-closing action,
/// (b) [`handle_error`] needs to be called without holding any locks (except
@@ -3725,34 +3743,6 @@ where
/// true).
#[rustfmt::skip]
macro_rules! convert_channel_err {
- ($self: ident, $peer_state: expr, $err: expr, $chan: expr, $close: expr, $locked_close: expr, $channel_id: expr, _internal) => { {
- match $err {
- ChannelError::Warn(msg) => {
- (false, MsgHandleErrInternal::from_chan_no_close(ChannelError::Warn(msg), $channel_id))
- },
- ChannelError::WarnAndDisconnect(msg) => {
- (false, MsgHandleErrInternal::from_chan_no_close(ChannelError::WarnAndDisconnect(msg), $channel_id))
- },
- ChannelError::Ignore(msg) => {
- (false, MsgHandleErrInternal::from_chan_no_close(ChannelError::Ignore(msg), $channel_id))
- },
- ChannelError::Abort(reason) => {
- (false, MsgHandleErrInternal::from_chan_no_close(ChannelError::Abort(reason), $channel_id))
- },
- ChannelError::Close((msg, reason)) => {
- let (mut shutdown_res, chan_update) = $close(reason);
- let logger = WithChannelContext::from(&$self.logger, &$chan.context(), None);
- log_error!(logger, "Closed channel due to close-required error: {}", msg);
- $locked_close(&mut shutdown_res, $chan);
- let err =
- MsgHandleErrInternal::from_finish_shutdown(msg, $channel_id, shutdown_res, chan_update);
- (true, err)
- },
- ChannelError::SendError(msg) => {
- (false, MsgHandleErrInternal::from_chan_no_close(ChannelError::SendError(msg), $channel_id))
- },
- }
- } };
($self: ident, $peer_state: expr, $shutdown_result: expr, $funded_channel: expr, COOP_CLOSED) => { {
let reason = ChannelError::Close(("Coop Closed".to_owned(), $shutdown_result.closure_reason.clone()));
let closed_update_ids = &mut $peer_state.closed_channel_monitor_update_ids;
@@ -3769,10 +3759,7 @@ macro_rules! convert_channel_err {
convert_funded_channel_err_internal($self, closed_update_ids, in_flight_updates, None, $err, $funded_channel)
} };
($self: ident, $peer_state: expr, $err: expr, $channel: expr, UNFUNDED_CHANNEL) => { {
- let chan_id = $channel.context().channel_id();
- let mut do_close = |reason| { ($channel.force_shutdown(reason), None) };
- let locked_close = |_, chan: &mut Channel<_>| { locked_close_channel!($self, chan.context(), UNFUNDED); };
- convert_channel_err!($self, $peer_state, $err, $channel, do_close, locked_close, chan_id, _internal)
+ convert_unfunded_channel_err_internal($self, $err, $channel)
} };
($self: ident, $peer_state: expr, $err: expr, $channel: expr) => {
match $channel.as_funded_mut() {
@@ -3782,7 +3769,7 @@ macro_rules! convert_channel_err {
convert_funded_channel_err_internal($self, closed_update_ids, in_flight_updates, None, $err, funded_channel)
},
None => {
- convert_channel_err!($self, $peer_state, $err, $channel, UNFUNDED_CHANNEL)
+ convert_unfunded_channel_err_internal($self, $err, $channel)
},
}
};
Why this scored 14/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.