Skip to content

Commit 270ce0c

Browse files
Remove excess channel_state passing to macros
As the `short_to_chan_info` has been moved out of the `channel_state` to a standalone lock, several macros no longer need the `channel_state` passed into the macro.
1 parent eb876df commit 270ce0c

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,7 +1307,7 @@ macro_rules! convert_chan_err {
13071307
}
13081308

13091309
macro_rules! break_chan_entry {
1310-
($self: ident, $res: expr, $channel_state: expr, $entry: expr) => {
1310+
($self: ident, $res: expr, $entry: expr) => {
13111311
match $res {
13121312
Ok(res) => res,
13131313
Err(e) => {
@@ -1322,7 +1322,7 @@ macro_rules! break_chan_entry {
13221322
}
13231323

13241324
macro_rules! try_chan_entry {
1325-
($self: ident, $res: expr, $channel_state: expr, $entry: expr) => {
1325+
($self: ident, $res: expr, $entry: expr) => {
13261326
match $res {
13271327
Ok(res) => res,
13281328
Err(e) => {
@@ -1337,7 +1337,7 @@ macro_rules! try_chan_entry {
13371337
}
13381338

13391339
macro_rules! remove_channel {
1340-
($self: expr, $channel_state: expr, $entry: expr) => {
1340+
($self: expr, $entry: expr) => {
13411341
{
13421342
let channel = $entry.remove_entry().1;
13431343
update_maps_on_chan_removal!($self, channel);
@@ -1416,17 +1416,17 @@ macro_rules! handle_monitor_err {
14161416
}
14171417

14181418
macro_rules! return_monitor_err {
1419-
($self: ident, $err: expr, $channel_state: expr, $entry: expr, $action_type: path, $resend_raa: expr, $resend_commitment: expr) => {
1419+
($self: ident, $err: expr, $entry: expr, $action_type: path, $resend_raa: expr, $resend_commitment: expr) => {
14201420
return handle_monitor_err!($self, $err, $entry, $action_type, $resend_raa, $resend_commitment);
14211421
};
1422-
($self: ident, $err: expr, $channel_state: expr, $entry: expr, $action_type: path, $resend_raa: expr, $resend_commitment: expr, $failed_forwards: expr, $failed_fails: expr) => {
1422+
($self: ident, $err: expr, $entry: expr, $action_type: path, $resend_raa: expr, $resend_commitment: expr, $failed_forwards: expr, $failed_fails: expr) => {
14231423
return handle_monitor_err!($self, $err, $entry, $action_type, $resend_raa, $resend_commitment, $failed_forwards, $failed_fails);
14241424
}
14251425
}
14261426

14271427
// Does not break in case of TemporaryFailure!
14281428
macro_rules! maybe_break_monitor_err {
1429-
($self: ident, $err: expr, $channel_state: expr, $entry: expr, $action_type: path, $resend_raa: expr, $resend_commitment: expr) => {
1429+
($self: ident, $err: expr, $entry: expr, $action_type: path, $resend_raa: expr, $resend_commitment: expr) => {
14301430
match (handle_monitor_err!($self, $err, $entry, $action_type, $resend_raa, $resend_commitment), $err) {
14311431
(e, ChannelMonitorUpdateErr::PermanentFailure) => {
14321432
break e;
@@ -1875,7 +1875,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
18751875
let (result, is_permanent) =
18761876
handle_monitor_err!(self, e, chan_entry.get_mut(), RAACommitmentOrder::CommitmentFirst, chan_entry.key(), NO_UPDATE);
18771877
if is_permanent {
1878-
remove_channel!(self, channel_state, chan_entry);
1878+
remove_channel!(self, chan_entry);
18791879
break result;
18801880
}
18811881
}
@@ -1887,7 +1887,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
18871887
});
18881888

18891889
if chan_entry.get().is_shutdown() {
1890-
let channel = remove_channel!(self, channel_state, chan_entry);
1890+
let channel = remove_channel!(self, chan_entry);
18911891
if let Ok(channel_update) = self.get_channel_update_for_broadcast(&channel) {
18921892
channel_state.pending_msg_events.push(events::MessageSendEvent::BroadcastChannelUpdate {
18931893
msg: channel_update
@@ -1988,7 +1988,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
19881988
} else {
19891989
self.issue_channel_close_events(chan.get(),ClosureReason::HolderForceClosed);
19901990
}
1991-
remove_channel!(self, channel_state, chan)
1991+
remove_channel!(self, chan)
19921992
} else {
19931993
return Err(APIError::ChannelUnavailable{err: "No such channel".to_owned()});
19941994
}
@@ -2490,11 +2490,11 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
24902490
payment_secret: payment_secret.clone(),
24912491
payment_params: payment_params.clone(),
24922492
}, onion_packet, &self.logger),
2493-
channel_state, chan)
2493+
chan)
24942494
} {
24952495
Some((update_add, commitment_signed, monitor_update)) => {
24962496
if let Err(e) = self.chain_monitor.update_channel(chan.get().get_funding_txo().unwrap(), monitor_update) {
2497-
maybe_break_monitor_err!(self, e, channel_state, chan, RAACommitmentOrder::CommitmentFirst, false, true);
2497+
maybe_break_monitor_err!(self, e, chan, RAACommitmentOrder::CommitmentFirst, false, true);
24982498
// Note that MonitorUpdateFailed here indicates (per function docs)
24992499
// that we will resend the commitment update once monitor updating
25002500
// is restored. Therefore, we must return an error indicating that
@@ -3296,7 +3296,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
32963296
}
32973297
ChannelError::Close(msg) => {
32983298
log_trace!(self.logger, "Closing channel {} due to Close-required error: {}", log_bytes!(chan.key()[..]), msg);
3299-
let mut channel = remove_channel!(self, channel_state, chan);
3299+
let mut channel = remove_channel!(self, chan);
33003300
// ChannelClosed event is generated by handle_error for us.
33013301
Err(MsgHandleErrInternal::from_finish_shutdown(msg, channel.channel_id(), channel.get_user_id(), channel.force_shutdown(true), self.get_channel_update_for_broadcast(&channel).ok()))
33023302
},
@@ -4513,7 +4513,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
45134513
}
45144514
};
45154515
channel_state.pending_msg_events.push(send_msg_err_event);
4516-
let _ = remove_channel!(self, channel_state, channel);
4516+
let _ = remove_channel!(self, channel);
45174517
return Err(APIError::APIMisuseError { err: "Please use accept_inbound_channel_from_trusted_peer_0conf to accept channels with zero confirmations.".to_owned() });
45184518
}
45194519

@@ -4593,7 +4593,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
45934593
if chan.get().get_counterparty_node_id() != *counterparty_node_id {
45944594
return Err(MsgHandleErrInternal::send_err_msg_no_close("Got a message for a channel from the wrong node!".to_owned(), msg.temporary_channel_id));
45954595
}
4596-
try_chan_entry!(self, chan.get_mut().accept_channel(&msg, &self.default_configuration.channel_handshake_limits, &their_features), channel_state, chan);
4596+
try_chan_entry!(self, chan.get_mut().accept_channel(&msg, &self.default_configuration.channel_handshake_limits, &their_features), chan);
45974597
(chan.get().get_value_satoshis(), chan.get().get_funding_redeemscript().to_v0_p2wsh(), chan.get().get_user_id())
45984598
},
45994599
hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel".to_owned(), msg.temporary_channel_id))
@@ -4620,7 +4620,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
46204620
if chan.get().get_counterparty_node_id() != *counterparty_node_id {
46214621
return Err(MsgHandleErrInternal::send_err_msg_no_close("Got a message for a channel from the wrong node!".to_owned(), msg.temporary_channel_id));
46224622
}
4623-
(try_chan_entry!(self, chan.get_mut().funding_created(msg, best_block, &self.logger), channel_state, chan), chan.remove())
4623+
(try_chan_entry!(self, chan.get_mut().funding_created(msg, best_block, &self.logger), chan), chan.remove())
46244624
},
46254625
hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel".to_owned(), msg.temporary_channel_id))
46264626
}
@@ -4694,7 +4694,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
46944694
}
46954695
let (monitor, funding_tx, channel_ready) = match chan.get_mut().funding_signed(&msg, best_block, &self.logger) {
46964696
Ok(update) => update,
4697-
Err(e) => try_chan_entry!(self, Err(e), channel_state, chan),
4697+
Err(e) => try_chan_entry!(self, Err(e), chan),
46984698
};
46994699
if let Err(e) = self.chain_monitor.watch_channel(chan.get().get_funding_txo().unwrap(), monitor) {
47004700
let mut res = handle_monitor_err!(self, e, chan, RAACommitmentOrder::RevokeAndACKFirst, channel_ready.is_some(), OPTIONALLY_RESEND_FUNDING_LOCKED);
@@ -4730,7 +4730,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
47304730
return Err(MsgHandleErrInternal::send_err_msg_no_close("Got a message for a channel from the wrong node!".to_owned(), msg.channel_id));
47314731
}
47324732
let announcement_sigs_opt = try_chan_entry!(self, chan.get_mut().channel_ready(&msg, self.get_our_node_id(),
4733-
self.genesis_hash.clone(), &self.best_block.read().unwrap(), &self.logger), channel_state, chan);
4733+
self.genesis_hash.clone(), &self.best_block.read().unwrap(), &self.logger), chan);
47344734
if let Some(announcement_sigs) = announcement_sigs_opt {
47354735
log_trace!(self.logger, "Sending announcement_signatures for channel {}", log_bytes!(chan.get().channel_id()));
47364736
channel_state.pending_msg_events.push(events::MessageSendEvent::SendAnnouncementSignatures {
@@ -4775,7 +4775,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
47754775
if chan_entry.get().sent_shutdown() { " after we initiated shutdown" } else { "" });
47764776
}
47774777

4778-
let (shutdown, monitor_update, htlcs) = try_chan_entry!(self, chan_entry.get_mut().shutdown(&self.keys_manager, &their_features, &msg), channel_state, chan_entry);
4778+
let (shutdown, monitor_update, htlcs) = try_chan_entry!(self, chan_entry.get_mut().shutdown(&self.keys_manager, &their_features, &msg), chan_entry);
47794779
dropped_htlcs = htlcs;
47804780

47814781
// Update the monitor with the shutdown script if necessary.
@@ -4784,7 +4784,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
47844784
let (result, is_permanent) =
47854785
handle_monitor_err!(self, e, chan_entry.get_mut(), RAACommitmentOrder::CommitmentFirst, chan_entry.key(), NO_UPDATE);
47864786
if is_permanent {
4787-
remove_channel!(self, channel_state, chan_entry);
4787+
remove_channel!(self, chan_entry);
47884788
break result;
47894789
}
47904790
}
@@ -4820,7 +4820,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
48204820
if chan_entry.get().get_counterparty_node_id() != *counterparty_node_id {
48214821
return Err(MsgHandleErrInternal::send_err_msg_no_close("Got a message for a channel from the wrong node!".to_owned(), msg.channel_id));
48224822
}
4823-
let (closing_signed, tx) = try_chan_entry!(self, chan_entry.get_mut().closing_signed(&self.fee_estimator, &msg), channel_state, chan_entry);
4823+
let (closing_signed, tx) = try_chan_entry!(self, chan_entry.get_mut().closing_signed(&self.fee_estimator, &msg), chan_entry);
48244824
if let Some(msg) = closing_signed {
48254825
channel_state.pending_msg_events.push(events::MessageSendEvent::SendClosingSigned {
48264826
node_id: counterparty_node_id.clone(),
@@ -4833,7 +4833,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
48334833
// also implies there are no pending HTLCs left on the channel, so we can
48344834
// fully delete it from tracking (the channel monitor is still around to
48354835
// watch for old state broadcasts)!
4836-
(tx, Some(remove_channel!(self, channel_state, chan_entry)))
4836+
(tx, Some(remove_channel!(self, chan_entry)))
48374837
} else { (tx, None) }
48384838
},
48394839
hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel".to_owned(), msg.channel_id))
@@ -4897,7 +4897,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
48974897
_ => pending_forward_info
48984898
}
48994899
};
4900-
try_chan_entry!(self, chan.get_mut().update_add_htlc(&msg, pending_forward_info, create_pending_htlc_status, &self.logger), channel_state, chan);
4900+
try_chan_entry!(self, chan.get_mut().update_add_htlc(&msg, pending_forward_info, create_pending_htlc_status, &self.logger), chan);
49014901
},
49024902
hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel".to_owned(), msg.channel_id))
49034903
}
@@ -4913,7 +4913,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
49134913
if chan.get().get_counterparty_node_id() != *counterparty_node_id {
49144914
return Err(MsgHandleErrInternal::send_err_msg_no_close("Got a message for a channel from the wrong node!".to_owned(), msg.channel_id));
49154915
}
4916-
try_chan_entry!(self, chan.get_mut().update_fulfill_htlc(&msg), channel_state, chan)
4916+
try_chan_entry!(self, chan.get_mut().update_fulfill_htlc(&msg), chan)
49174917
},
49184918
hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel".to_owned(), msg.channel_id))
49194919
}
@@ -4930,7 +4930,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
49304930
if chan.get().get_counterparty_node_id() != *counterparty_node_id {
49314931
return Err(MsgHandleErrInternal::send_err_msg_no_close("Got a message for a channel from the wrong node!".to_owned(), msg.channel_id));
49324932
}
4933-
try_chan_entry!(self, chan.get_mut().update_fail_htlc(&msg, HTLCFailReason::LightningError { err: msg.reason.clone() }), channel_state, chan);
4933+
try_chan_entry!(self, chan.get_mut().update_fail_htlc(&msg, HTLCFailReason::LightningError { err: msg.reason.clone() }), chan);
49344934
},
49354935
hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel".to_owned(), msg.channel_id))
49364936
}
@@ -4947,9 +4947,9 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
49474947
}
49484948
if (msg.failure_code & 0x8000) == 0 {
49494949
let chan_err: ChannelError = ChannelError::Close("Got update_fail_malformed_htlc with BADONION not set".to_owned());
4950-
try_chan_entry!(self, Err(chan_err), channel_state, chan);
4950+
try_chan_entry!(self, Err(chan_err), chan);
49514951
}
4952-
try_chan_entry!(self, chan.get_mut().update_fail_malformed_htlc(&msg, HTLCFailReason::Reason { failure_code: msg.failure_code, data: Vec::new() }), channel_state, chan);
4952+
try_chan_entry!(self, chan.get_mut().update_fail_malformed_htlc(&msg, HTLCFailReason::Reason { failure_code: msg.failure_code, data: Vec::new() }), chan);
49534953
Ok(())
49544954
},
49554955
hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel".to_owned(), msg.channel_id))
@@ -4966,17 +4966,17 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
49664966
}
49674967
let (revoke_and_ack, commitment_signed, monitor_update) =
49684968
match chan.get_mut().commitment_signed(&msg, &self.logger) {
4969-
Err((None, e)) => try_chan_entry!(self, Err(e), channel_state, chan),
4969+
Err((None, e)) => try_chan_entry!(self, Err(e), chan),
49704970
Err((Some(update), e)) => {
49714971
assert!(chan.get().is_awaiting_monitor_update());
49724972
let _ = self.chain_monitor.update_channel(chan.get().get_funding_txo().unwrap(), update);
4973-
try_chan_entry!(self, Err(e), channel_state, chan);
4973+
try_chan_entry!(self, Err(e), chan);
49744974
unreachable!();
49754975
},
49764976
Ok(res) => res
49774977
};
49784978
if let Err(e) = self.chain_monitor.update_channel(chan.get().get_funding_txo().unwrap(), monitor_update) {
4979-
return_monitor_err!(self, e, channel_state, chan, RAACommitmentOrder::RevokeAndACKFirst, true, commitment_signed.is_some());
4979+
return_monitor_err!(self, e, chan, RAACommitmentOrder::RevokeAndACKFirst, true, commitment_signed.is_some());
49804980
}
49814981
channel_state.pending_msg_events.push(events::MessageSendEvent::SendRevokeAndACK {
49824982
node_id: counterparty_node_id.clone(),
@@ -5051,7 +5051,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
50515051
}
50525052
let was_frozen_for_monitor = chan.get().is_awaiting_monitor_update();
50535053
let raa_updates = break_chan_entry!(self,
5054-
chan.get_mut().revoke_and_ack(&msg, &self.logger), channel_state, chan);
5054+
chan.get_mut().revoke_and_ack(&msg, &self.logger), chan);
50555055
htlcs_to_fail = raa_updates.holding_cell_failed_htlcs;
50565056
if let Err(e) = self.chain_monitor.update_channel(chan.get().get_funding_txo().unwrap(), raa_updates.monitor_update) {
50575057
if was_frozen_for_monitor {
@@ -5110,7 +5110,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
51105110
if chan.get().get_counterparty_node_id() != *counterparty_node_id {
51115111
return Err(MsgHandleErrInternal::send_err_msg_no_close("Got a message for a channel from the wrong node!".to_owned(), msg.channel_id));
51125112
}
5113-
try_chan_entry!(self, chan.get_mut().update_fee(&self.fee_estimator, &msg), channel_state, chan);
5113+
try_chan_entry!(self, chan.get_mut().update_fee(&self.fee_estimator, &msg), chan);
51145114
},
51155115
hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel".to_owned(), msg.channel_id))
51165116
}
@@ -5132,7 +5132,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
51325132

51335133
channel_state.pending_msg_events.push(events::MessageSendEvent::BroadcastChannelAnnouncement {
51345134
msg: try_chan_entry!(self, chan.get_mut().announcement_signatures(
5135-
self.get_our_node_id(), self.genesis_hash.clone(), self.best_block.read().unwrap().height(), msg), channel_state, chan),
5135+
self.get_our_node_id(), self.genesis_hash.clone(), self.best_block.read().unwrap().height(), msg), chan),
51365136
// Note that announcement_signatures fails if the channel cannot be announced,
51375137
// so get_channel_update_for_broadcast will never fail by the time we get here.
51385138
update_msg: self.get_channel_update_for_broadcast(chan.get()).unwrap(),
@@ -5171,7 +5171,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
51715171
return Ok(NotifyOption::SkipPersist);
51725172
} else {
51735173
log_debug!(self.logger, "Received channel_update for channel {}.", log_bytes!(chan_id));
5174-
try_chan_entry!(self, chan.get_mut().channel_update(&msg), channel_state, chan);
5174+
try_chan_entry!(self, chan.get_mut().channel_update(&msg), chan);
51755175
}
51765176
},
51775177
hash_map::Entry::Vacant(_) => unreachable!()
@@ -5196,7 +5196,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
51965196
// add-HTLCs on disconnect, we may be handed HTLCs to fail backwards here.
51975197
let responses = try_chan_entry!(self, chan.get_mut().channel_reestablish(
51985198
msg, &self.logger, self.our_network_pubkey.clone(), self.genesis_hash,
5199-
&*self.best_block.read().unwrap()), channel_state, chan);
5199+
&*self.best_block.read().unwrap()), chan);
52005200
let mut channel_update = None;
52015201
if let Some(msg) = responses.shutdown_msg {
52025202
channel_state.pending_msg_events.push(events::MessageSendEvent::SendShutdown {
@@ -5260,7 +5260,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
52605260
let by_id = &mut channel_state.by_id;
52615261
let pending_msg_events = &mut channel_state.pending_msg_events;
52625262
if let hash_map::Entry::Occupied(chan_entry) = by_id.entry(funding_outpoint.to_channel_id()) {
5263-
let mut chan = remove_channel!(self, channel_state, chan_entry);
5263+
let mut chan = remove_channel!(self, chan_entry);
52645264
failed_channels.push(chan.force_shutdown(false));
52655265
if let Ok(update) = self.get_channel_update_for_broadcast(&chan) {
52665266
pending_msg_events.push(events::MessageSendEvent::BroadcastChannelUpdate {

0 commit comments

Comments
 (0)