Skip to content

Commit a274261

Browse files
committed
Clean up the handle_monitor_err!() macro argument forms somewhat
`handle_monitor_err!()` has a number of different forms depending on which messages and actions were outstanding when the monitor updating first failed. Instead of matching by argument count, its much more readable to put an explicit string in the arguments to make it easy to scan for the called form.
1 parent 09f8aba commit a274261

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,9 +1458,6 @@ macro_rules! remove_channel {
14581458
}
14591459

14601460
macro_rules! handle_monitor_err {
1461-
($self: ident, $err: expr, $channel_state: expr, $entry: expr, $action_type: path, $resend_raa: expr, $resend_commitment: expr) => {
1462-
handle_monitor_err!($self, $err, $channel_state, $entry, $action_type, $resend_raa, $resend_commitment, Vec::new(), Vec::new())
1463-
};
14641461
($self: ident, $err: expr, $short_to_id: expr, $chan: expr, $action_type: path, $resend_raa: expr, $resend_commitment: expr, $failed_forwards: expr, $failed_fails: expr, $failed_finalized_fulfills: expr, $chan_id: expr) => {
14651462
match $err {
14661463
ChannelMonitorUpdateErr::PermanentFailure => {
@@ -1513,9 +1510,19 @@ macro_rules! handle_monitor_err {
15131510
}
15141511
res
15151512
} };
1513+
($self: ident, $err: expr, $channel_state: expr, $entry: expr, $action_type: path, $chan_id: expr, COMMITMENT_UPDATE_ONLY) => { {
1514+
debug_assert!($action_type == RAACommitmentOrder::CommitmentFirst);
1515+
handle_monitor_err!($self, $err, $channel_state, $entry, $action_type, false, true, Vec::new(), Vec::new(), Vec::new(), $chan_id)
1516+
} };
1517+
($self: ident, $err: expr, $channel_state: expr, $entry: expr, $action_type: path, $chan_id: expr, NO_UPDATE) => {
1518+
handle_monitor_err!($self, $err, $channel_state, $entry, $action_type, false, false, Vec::new(), Vec::new(), Vec::new(), $chan_id)
1519+
};
1520+
($self: ident, $err: expr, $channel_state: expr, $entry: expr, $action_type: path, $resend_raa: expr, $resend_commitment: expr) => {
1521+
handle_monitor_err!($self, $err, $channel_state, $entry, $action_type, $resend_raa, $resend_commitment, Vec::new(), Vec::new(), Vec::new())
1522+
};
15161523
($self: ident, $err: expr, $channel_state: expr, $entry: expr, $action_type: path, $resend_raa: expr, $resend_commitment: expr, $failed_forwards: expr, $failed_fails: expr) => {
15171524
handle_monitor_err!($self, $err, $channel_state, $entry, $action_type, $resend_raa, $resend_commitment, $failed_forwards, $failed_fails, Vec::new())
1518-
}
1525+
};
15191526
}
15201527

15211528
macro_rules! return_monitor_err {
@@ -1911,7 +1918,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
19111918
if let Some(monitor_update) = monitor_update {
19121919
if let Err(e) = self.chain_monitor.update_channel(chan_entry.get().get_funding_txo().unwrap(), monitor_update) {
19131920
let (result, is_permanent) =
1914-
handle_monitor_err!(self, e, channel_state.short_to_id, chan_entry.get_mut(), RAACommitmentOrder::CommitmentFirst, false, false, Vec::new(), Vec::new(), Vec::new(), chan_entry.key());
1921+
handle_monitor_err!(self, e, channel_state.short_to_id, chan_entry.get_mut(), RAACommitmentOrder::CommitmentFirst, chan_entry.key(), NO_UPDATE);
19151922
if is_permanent {
19161923
remove_channel!(channel_state, chan_entry);
19171924
break result;
@@ -3455,7 +3462,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
34553462
let ret_err = match res {
34563463
Ok(Some((update_fee, commitment_signed, monitor_update))) => {
34573464
if let Err(e) = self.chain_monitor.update_channel(chan.get_funding_txo().unwrap(), monitor_update) {
3458-
let (res, drop) = handle_monitor_err!(self, e, short_to_id, chan, RAACommitmentOrder::CommitmentFirst, false, true, Vec::new(), Vec::new(), Vec::new(), chan_id);
3465+
let (res, drop) = handle_monitor_err!(self, e, short_to_id, chan, RAACommitmentOrder::CommitmentFirst, chan_id, COMMITMENT_UPDATE_ONLY);
34593466
if drop { retain_channel = false; }
34603467
res
34613468
} else {
@@ -4399,7 +4406,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
43994406
if let Some(monitor_update) = monitor_update {
44004407
if let Err(e) = self.chain_monitor.update_channel(chan_entry.get().get_funding_txo().unwrap(), monitor_update) {
44014408
let (result, is_permanent) =
4402-
handle_monitor_err!(self, e, channel_state.short_to_id, chan_entry.get_mut(), RAACommitmentOrder::CommitmentFirst, false, false, Vec::new(), Vec::new(), Vec::new(), chan_entry.key());
4409+
handle_monitor_err!(self, e, channel_state.short_to_id, chan_entry.get_mut(), RAACommitmentOrder::CommitmentFirst, chan_entry.key(), NO_UPDATE);
44034410
if is_permanent {
44044411
remove_channel!(channel_state, chan_entry);
44054412
break result;
@@ -4965,7 +4972,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
49654972
if let Some((commitment_update, monitor_update)) = commitment_opt {
49664973
if let Err(e) = self.chain_monitor.update_channel(chan.get_funding_txo().unwrap(), monitor_update) {
49674974
has_monitor_update = true;
4968-
let (res, close_channel) = handle_monitor_err!(self, e, short_to_id, chan, RAACommitmentOrder::CommitmentFirst, false, true, Vec::new(), Vec::new(), Vec::new(), channel_id);
4975+
let (res, close_channel) = handle_monitor_err!(self, e, short_to_id, chan, RAACommitmentOrder::CommitmentFirst, channel_id, COMMITMENT_UPDATE_ONLY);
49694976
handle_errors.push((chan.get_counterparty_node_id(), res));
49704977
if close_channel { return false; }
49714978
} else {

0 commit comments

Comments
 (0)