Skip to content

Commit 75aacc2

Browse files
committed
f combine error convert macros
1 parent d27207c commit 75aacc2

File tree

1 file changed

+23
-35
lines changed

1 file changed

+23
-35
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1828,55 +1828,43 @@ macro_rules! convert_unfunded_chan_err {
18281828
}
18291829

18301830
/// Returns (boolean indicating if we should remove the Channel object from memory, a mapped error)
1831-
macro_rules! convert_funded_chan_err {
1832-
($self: ident, $err: expr, $channel: expr, $channel_id: expr) => {
1831+
macro_rules! convert_chan_phase_err {
1832+
($self: ident, $err: expr, $channel: expr, $channel_id: expr, MANUAL_CHANNEL_UPDATE, $channel_update: expr) => {
18331833
match $err {
18341834
ChannelError::Warn(msg) => {
1835-
(false, MsgHandleErrInternal::from_chan_no_close(ChannelError::Warn(msg), $channel_id.clone()))
1835+
(false, MsgHandleErrInternal::from_chan_no_close(ChannelError::Warn(msg), *$channel_id))
18361836
},
18371837
ChannelError::Ignore(msg) => {
1838-
(false, MsgHandleErrInternal::from_chan_no_close(ChannelError::Ignore(msg), $channel_id.clone()))
1838+
(false, MsgHandleErrInternal::from_chan_no_close(ChannelError::Ignore(msg), *$channel_id))
18391839
},
18401840
ChannelError::Close(msg) => {
18411841
log_error!($self.logger, "Closing channel {} due to close-required error: {}", log_bytes!($channel_id[..]), msg);
18421842
update_maps_on_chan_removal!($self, $channel.context);
18431843
let shutdown_res = $channel.context.force_shutdown(true);
1844+
let user_id = $channel.context.get_user_id();
1845+
let channel_capacity_satoshis = $channel.context.get_value_satoshis();
18441846

1845-
(true, MsgHandleErrInternal::from_finish_shutdown(msg, *$channel_id, $channel.context.get_user_id(),
1846-
shutdown_res, $self.get_channel_update_for_broadcast(&$channel).ok(), $channel.context.get_value_satoshis()))
1847+
(true, MsgHandleErrInternal::from_finish_shutdown(msg, *$channel_id, user_id,
1848+
shutdown_res, $channel_update, channel_capacity_satoshis))
18471849
},
18481850
}
18491851
};
1850-
}
1851-
1852-
/// Returns (boolean indicating if we should remove the Channel object from memory, a mapped error)
1853-
macro_rules! convert_chan_phase_err {
1852+
($self: ident, $err: expr, $channel: expr, $channel_id: expr, FUNDED_CHANNEL) => {
1853+
convert_chan_phase_err!($self, $err, $channel, $channel_id, MANUAL_CHANNEL_UPDATE, { $self.get_channel_update_for_broadcast($channel).ok() })
1854+
};
1855+
($self: ident, $err: expr, $channel: expr, $channel_id: expr, UNFUNDED_CHANNEL) => {
1856+
convert_chan_phase_err!($self, $err, $channel, $channel_id, MANUAL_CHANNEL_UPDATE, None)
1857+
};
18541858
($self: ident, $err: expr, $channel_phase: expr, $channel_id: expr) => {
1855-
match $err {
1856-
ChannelError::Warn(msg) => {
1857-
(false, MsgHandleErrInternal::from_chan_no_close(ChannelError::Warn(msg), *$channel_id))
1859+
match $channel_phase {
1860+
ChannelPhase::Funded(channel) => {
1861+
convert_chan_phase_err!($self, $err, channel, $channel_id, FUNDED_CHANNEL)
18581862
},
1859-
ChannelError::Ignore(msg) => {
1860-
(false, MsgHandleErrInternal::from_chan_no_close(ChannelError::Ignore(msg), *$channel_id))
1863+
ChannelPhase::UnfundedOutboundV1(channel) => {
1864+
convert_chan_phase_err!($self, $err, channel, $channel_id, UNFUNDED_CHANNEL)
18611865
},
1862-
ChannelError::Close(msg) => {
1863-
log_error!($self.logger, "Closing channel {} due to close-required error: {}", log_bytes!($channel_id[..]), msg);
1864-
let context = $channel_phase.context_mut();
1865-
update_maps_on_chan_removal!($self, context);
1866-
let shutdown_res = context.force_shutdown(true);
1867-
let user_id = context.get_user_id();
1868-
let channel_capacity_satoshis = context.get_value_satoshis();
1869-
1870-
match $channel_phase {
1871-
ChannelPhase::Funded(chan) => {
1872-
(true, MsgHandleErrInternal::from_finish_shutdown(msg, *$channel_id, user_id,
1873-
shutdown_res, $self.get_channel_update_for_broadcast(&chan).ok(), channel_capacity_satoshis))
1874-
},
1875-
_ => {
1876-
(true, MsgHandleErrInternal::from_finish_shutdown(msg, *$channel_id, user_id,
1877-
shutdown_res, None, channel_capacity_satoshis))
1878-
}
1879-
}
1866+
ChannelPhase::UnfundedInboundV1(channel) => {
1867+
convert_chan_phase_err!($self, $err, channel, $channel_id, UNFUNDED_CHANNEL)
18801868
},
18811869
}
18821870
};
@@ -4609,7 +4597,7 @@ where
46094597
if chan_needs_persist == NotifyOption::DoPersist { should_persist = NotifyOption::DoPersist; }
46104598

46114599
if let Err(e) = chan.timer_check_closing_negotiation_progress() {
4612-
let (needs_close, err) = convert_funded_chan_err!(self, e, chan, chan_id);
4600+
let (needs_close, err) = convert_chan_phase_err!(self, e, chan, chan_id, FUNDED_CHANNEL);
46134601
handle_errors.push((Err(err), counterparty_node_id));
46144602
if needs_close { return false; }
46154603
}
@@ -6708,7 +6696,7 @@ where
67086696
},
67096697
Err(e) => {
67106698
has_update = true;
6711-
let (close_channel, res) = convert_funded_chan_err!(self, e, chan, channel_id);
6699+
let (close_channel, res) = convert_chan_phase_err!(self, e, chan, channel_id, FUNDED_CHANNEL);
67126700
handle_errors.push((chan.context.get_counterparty_node_id(), Err(res)));
67136701
!close_channel
67146702
}

0 commit comments

Comments
 (0)