@@ -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: {}", $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: {}", $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 };
@@ -4608,7 +4596,7 @@ where
46084596 if chan_needs_persist == NotifyOption::DoPersist { should_persist = NotifyOption::DoPersist; }
46094597
46104598 if let Err(e) = chan.timer_check_closing_negotiation_progress() {
4611- let (needs_close, err) = convert_funded_chan_err !(self, e, chan, chan_id);
4599+ let (needs_close, err) = convert_chan_phase_err !(self, e, chan, chan_id, FUNDED_CHANNEL );
46124600 handle_errors.push((Err(err), counterparty_node_id));
46134601 if needs_close { return false; }
46144602 }
@@ -6707,7 +6695,7 @@ where
67076695 },
67086696 Err(e) => {
67096697 has_update = true;
6710- let (close_channel, res) = convert_funded_chan_err !(self, e, chan, channel_id);
6698+ let (close_channel, res) = convert_chan_phase_err !(self, e, chan, channel_id, FUNDED_CHANNEL );
67116699 handle_errors.push((chan.context.get_counterparty_node_id(), Err(res)));
67126700 !close_channel
67136701 }
0 commit comments