Skip to content

Commit abf1e72

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 743e6e1 commit abf1e72

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
@@ -1310,7 +1310,7 @@ macro_rules! convert_chan_err {
13101310
}
13111311

13121312
macro_rules! break_chan_entry {
1313-
($self: ident, $res: expr, $channel_state: expr, $entry: expr) => {
1313+
($self: ident, $res: expr, $entry: expr) => {
13141314
match $res {
13151315
Ok(res) => res,
13161316
Err(e) => {
@@ -1325,7 +1325,7 @@ macro_rules! break_chan_entry {
13251325
}
13261326

13271327
macro_rules! try_chan_entry {
1328-
($self: ident, $res: expr, $channel_state: expr, $entry: expr) => {
1328+
($self: ident, $res: expr, $entry: expr) => {
13291329
match $res {
13301330
Ok(res) => res,
13311331
Err(e) => {
@@ -1340,7 +1340,7 @@ macro_rules! try_chan_entry {
13401340
}
13411341

13421342
macro_rules! remove_channel {
1343-
($self: expr, $channel_state: expr, $entry: expr) => {
1343+
($self: expr, $entry: expr) => {
13441344
{
13451345
let channel = $entry.remove_entry().1;
13461346
update_maps_on_chan_removal!($self, channel);
@@ -1419,17 +1419,17 @@ macro_rules! handle_monitor_err {
14191419
}
14201420

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

14301430
// Does not break in case of TemporaryFailure!
14311431
macro_rules! maybe_break_monitor_err {
1432-
($self: ident, $err: expr, $channel_state: expr, $entry: expr, $action_type: path, $resend_raa: expr, $resend_commitment: expr) => {
1432+
($self: ident, $err: expr, $entry: expr, $action_type: path, $resend_raa: expr, $resend_commitment: expr) => {
14331433
match (handle_monitor_err!($self, $err, $entry, $action_type, $resend_raa, $resend_commitment), $err) {
14341434
(e, ChannelMonitorUpdateErr::PermanentFailure) => {
14351435
break e;
@@ -1878,7 +1878,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
18781878
let (result, is_permanent) =
18791879
handle_monitor_err!(self, e, chan_entry.get_mut(), RAACommitmentOrder::CommitmentFirst, chan_entry.key(), NO_UPDATE);
18801880
if is_permanent {
1881-
remove_channel!(self, channel_state, chan_entry);
1881+
remove_channel!(self, chan_entry);
18821882
break result;
18831883
}
18841884
}
@@ -1890,7 +1890,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
18901890
});
18911891

18921892
if chan_entry.get().is_shutdown() {
1893-
let channel = remove_channel!(self, channel_state, chan_entry);
1893+
let channel = remove_channel!(self, chan_entry);
18941894
if let Ok(channel_update) = self.get_channel_update_for_broadcast(&channel) {
18951895
channel_state.pending_msg_events.push(events::MessageSendEvent::BroadcastChannelUpdate {
18961896
msg: channel_update
@@ -1991,7 +1991,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
19911991
} else {
19921992
self.issue_channel_close_events(chan.get(),ClosureReason::HolderForceClosed);
19931993
}
1994-
remove_channel!(self, channel_state, chan)
1994+
remove_channel!(self, chan)
19951995
} else {
19961996
return Err(APIError::ChannelUnavailable{err: "No such channel".to_owned()});
19971997
}
@@ -2493,11 +2493,11 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
24932493
payment_secret: payment_secret.clone(),
24942494
payment_params: payment_params.clone(),
24952495
}, onion_packet, &self.logger),
2496-
channel_state, chan)
2496+
chan)
24972497
} {
24982498
Some((update_add, commitment_signed, monitor_update)) => {
24992499
if let Err(e) = self.chain_monitor.update_channel(chan.get().get_funding_txo().unwrap(), monitor_update) {
2500-
maybe_break_monitor_err!(self, e, channel_state, chan, RAACommitmentOrder::CommitmentFirst, false, true);
2500+
maybe_break_monitor_err!(self, e, chan, RAACommitmentOrder::CommitmentFirst, false, true);
25012501
// Note that MonitorUpdateFailed here indicates (per function docs)
25022502
// that we will resend the commitment update once monitor updating
25032503
// is restored. Therefore, we must return an error indicating that
@@ -3299,7 +3299,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
32993299
}
33003300
ChannelError::Close(msg) => {
33013301
log_trace!(self.logger, "Closing channel {} due to Close-required error: {}", log_bytes!(chan.key()[..]), msg);
3302-
let mut channel = remove_channel!(self, channel_state, chan);
3302+
let mut channel = remove_channel!(self, chan);
33033303
// ChannelClosed event is generated by handle_error for us.
33043304
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()))
33053305
},
@@ -4516,7 +4516,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
45164516
}
45174517
};
45184518
channel_state.pending_msg_events.push(send_msg_err_event);
4519-
let _ = remove_channel!(self, channel_state, channel);
4519+
let _ = remove_channel!(self, channel);
45204520
return Err(APIError::APIMisuseError { err: "Please use accept_inbound_channel_from_trusted_peer_0conf to accept channels with zero confirmations.".to_owned() });
45214521
}
45224522

@@ -4596,7 +4596,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
45964596
if chan.get().get_counterparty_node_id() != *counterparty_node_id {
45974597
return Err(MsgHandleErrInternal::send_err_msg_no_close("Got a message for a channel from the wrong node!".to_owned(), msg.temporary_channel_id));
45984598
}
4599-
try_chan_entry!(self, chan.get_mut().accept_channel(&msg, &self.default_configuration.channel_handshake_limits, &their_features), channel_state, chan);
4599+
try_chan_entry!(self, chan.get_mut().accept_channel(&msg, &self.default_configuration.channel_handshake_limits, &their_features), chan);
46004600
(chan.get().get_value_satoshis(), chan.get().get_funding_redeemscript().to_v0_p2wsh(), chan.get().get_user_id())
46014601
},
46024602
hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel".to_owned(), msg.temporary_channel_id))
@@ -4623,7 +4623,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
46234623
if chan.get().get_counterparty_node_id() != *counterparty_node_id {
46244624
return Err(MsgHandleErrInternal::send_err_msg_no_close("Got a message for a channel from the wrong node!".to_owned(), msg.temporary_channel_id));
46254625
}
4626-
(try_chan_entry!(self, chan.get_mut().funding_created(msg, best_block, &self.logger), channel_state, chan), chan.remove())
4626+
(try_chan_entry!(self, chan.get_mut().funding_created(msg, best_block, &self.logger), chan), chan.remove())
46274627
},
46284628
hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel".to_owned(), msg.temporary_channel_id))
46294629
}
@@ -4697,7 +4697,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
46974697
}
46984698
let (monitor, funding_tx, channel_ready) = match chan.get_mut().funding_signed(&msg, best_block, &self.logger) {
46994699
Ok(update) => update,
4700-
Err(e) => try_chan_entry!(self, Err(e), channel_state, chan),
4700+
Err(e) => try_chan_entry!(self, Err(e), chan),
47014701
};
47024702
if let Err(e) = self.chain_monitor.watch_channel(chan.get().get_funding_txo().unwrap(), monitor) {
47034703
let mut res = handle_monitor_err!(self, e, chan, RAACommitmentOrder::RevokeAndACKFirst, channel_ready.is_some(), OPTIONALLY_RESEND_FUNDING_LOCKED);
@@ -4733,7 +4733,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
47334733
return Err(MsgHandleErrInternal::send_err_msg_no_close("Got a message for a channel from the wrong node!".to_owned(), msg.channel_id));
47344734
}
47354735
let announcement_sigs_opt = try_chan_entry!(self, chan.get_mut().channel_ready(&msg, self.get_our_node_id(),
4736-
self.genesis_hash.clone(), &self.best_block.read().unwrap(), &self.logger), channel_state, chan);
4736+
self.genesis_hash.clone(), &self.best_block.read().unwrap(), &self.logger), chan);
47374737
if let Some(announcement_sigs) = announcement_sigs_opt {
47384738
log_trace!(self.logger, "Sending announcement_signatures for channel {}", log_bytes!(chan.get().channel_id()));
47394739
channel_state.pending_msg_events.push(events::MessageSendEvent::SendAnnouncementSignatures {
@@ -4778,7 +4778,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
47784778
if chan_entry.get().sent_shutdown() { " after we initiated shutdown" } else { "" });
47794779
}
47804780

4781-
let (shutdown, monitor_update, htlcs) = try_chan_entry!(self, chan_entry.get_mut().shutdown(&self.keys_manager, &their_features, &msg), channel_state, chan_entry);
4781+
let (shutdown, monitor_update, htlcs) = try_chan_entry!(self, chan_entry.get_mut().shutdown(&self.keys_manager, &their_features, &msg), chan_entry);
47824782
dropped_htlcs = htlcs;
47834783

47844784
// Update the monitor with the shutdown script if necessary.
@@ -4787,7 +4787,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
47874787
let (result, is_permanent) =
47884788
handle_monitor_err!(self, e, chan_entry.get_mut(), RAACommitmentOrder::CommitmentFirst, chan_entry.key(), NO_UPDATE);
47894789
if is_permanent {
4790-
remove_channel!(self, channel_state, chan_entry);
4790+
remove_channel!(self, chan_entry);
47914791
break result;
47924792
}
47934793
}
@@ -4823,7 +4823,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
48234823
if chan_entry.get().get_counterparty_node_id() != *counterparty_node_id {
48244824
return Err(MsgHandleErrInternal::send_err_msg_no_close("Got a message for a channel from the wrong node!".to_owned(), msg.channel_id));
48254825
}
4826-
let (closing_signed, tx) = try_chan_entry!(self, chan_entry.get_mut().closing_signed(&self.fee_estimator, &msg), channel_state, chan_entry);
4826+
let (closing_signed, tx) = try_chan_entry!(self, chan_entry.get_mut().closing_signed(&self.fee_estimator, &msg), chan_entry);
48274827
if let Some(msg) = closing_signed {
48284828
channel_state.pending_msg_events.push(events::MessageSendEvent::SendClosingSigned {
48294829
node_id: counterparty_node_id.clone(),
@@ -4836,7 +4836,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
48364836
// also implies there are no pending HTLCs left on the channel, so we can
48374837
// fully delete it from tracking (the channel monitor is still around to
48384838
// watch for old state broadcasts)!
4839-
(tx, Some(remove_channel!(self, channel_state, chan_entry)))
4839+
(tx, Some(remove_channel!(self, chan_entry)))
48404840
} else { (tx, None) }
48414841
},
48424842
hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel".to_owned(), msg.channel_id))
@@ -4900,7 +4900,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
49004900
_ => pending_forward_info
49014901
}
49024902
};
4903-
try_chan_entry!(self, chan.get_mut().update_add_htlc(&msg, pending_forward_info, create_pending_htlc_status, &self.logger), channel_state, chan);
4903+
try_chan_entry!(self, chan.get_mut().update_add_htlc(&msg, pending_forward_info, create_pending_htlc_status, &self.logger), chan);
49044904
},
49054905
hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel".to_owned(), msg.channel_id))
49064906
}
@@ -4916,7 +4916,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
49164916
if chan.get().get_counterparty_node_id() != *counterparty_node_id {
49174917
return Err(MsgHandleErrInternal::send_err_msg_no_close("Got a message for a channel from the wrong node!".to_owned(), msg.channel_id));
49184918
}
4919-
try_chan_entry!(self, chan.get_mut().update_fulfill_htlc(&msg), channel_state, chan)
4919+
try_chan_entry!(self, chan.get_mut().update_fulfill_htlc(&msg), chan)
49204920
},
49214921
hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel".to_owned(), msg.channel_id))
49224922
}
@@ -4933,7 +4933,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
49334933
if chan.get().get_counterparty_node_id() != *counterparty_node_id {
49344934
return Err(MsgHandleErrInternal::send_err_msg_no_close("Got a message for a channel from the wrong node!".to_owned(), msg.channel_id));
49354935
}
4936-
try_chan_entry!(self, chan.get_mut().update_fail_htlc(&msg, HTLCFailReason::LightningError { err: msg.reason.clone() }), channel_state, chan);
4936+
try_chan_entry!(self, chan.get_mut().update_fail_htlc(&msg, HTLCFailReason::LightningError { err: msg.reason.clone() }), chan);
49374937
},
49384938
hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel".to_owned(), msg.channel_id))
49394939
}
@@ -4950,9 +4950,9 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
49504950
}
49514951
if (msg.failure_code & 0x8000) == 0 {
49524952
let chan_err: ChannelError = ChannelError::Close("Got update_fail_malformed_htlc with BADONION not set".to_owned());
4953-
try_chan_entry!(self, Err(chan_err), channel_state, chan);
4953+
try_chan_entry!(self, Err(chan_err), chan);
49544954
}
4955-
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);
4955+
try_chan_entry!(self, chan.get_mut().update_fail_malformed_htlc(&msg, HTLCFailReason::Reason { failure_code: msg.failure_code, data: Vec::new() }), chan);
49564956
Ok(())
49574957
},
49584958
hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel".to_owned(), msg.channel_id))
@@ -4969,17 +4969,17 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
49694969
}
49704970
let (revoke_and_ack, commitment_signed, monitor_update) =
49714971
match chan.get_mut().commitment_signed(&msg, &self.logger) {
4972-
Err((None, e)) => try_chan_entry!(self, Err(e), channel_state, chan),
4972+
Err((None, e)) => try_chan_entry!(self, Err(e), chan),
49734973
Err((Some(update), e)) => {
49744974
assert!(chan.get().is_awaiting_monitor_update());
49754975
let _ = self.chain_monitor.update_channel(chan.get().get_funding_txo().unwrap(), update);
4976-
try_chan_entry!(self, Err(e), channel_state, chan);
4976+
try_chan_entry!(self, Err(e), chan);
49774977
unreachable!();
49784978
},
49794979
Ok(res) => res
49804980
};
49814981
if let Err(e) = self.chain_monitor.update_channel(chan.get().get_funding_txo().unwrap(), monitor_update) {
4982-
return_monitor_err!(self, e, channel_state, chan, RAACommitmentOrder::RevokeAndACKFirst, true, commitment_signed.is_some());
4982+
return_monitor_err!(self, e, chan, RAACommitmentOrder::RevokeAndACKFirst, true, commitment_signed.is_some());
49834983
}
49844984
channel_state.pending_msg_events.push(events::MessageSendEvent::SendRevokeAndACK {
49854985
node_id: counterparty_node_id.clone(),
@@ -5054,7 +5054,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
50545054
}
50555055
let was_frozen_for_monitor = chan.get().is_awaiting_monitor_update();
50565056
let raa_updates = break_chan_entry!(self,
5057-
chan.get_mut().revoke_and_ack(&msg, &self.logger), channel_state, chan);
5057+
chan.get_mut().revoke_and_ack(&msg, &self.logger), chan);
50585058
htlcs_to_fail = raa_updates.holding_cell_failed_htlcs;
50595059
if let Err(e) = self.chain_monitor.update_channel(chan.get().get_funding_txo().unwrap(), raa_updates.monitor_update) {
50605060
if was_frozen_for_monitor {
@@ -5113,7 +5113,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
51135113
if chan.get().get_counterparty_node_id() != *counterparty_node_id {
51145114
return Err(MsgHandleErrInternal::send_err_msg_no_close("Got a message for a channel from the wrong node!".to_owned(), msg.channel_id));
51155115
}
5116-
try_chan_entry!(self, chan.get_mut().update_fee(&self.fee_estimator, &msg), channel_state, chan);
5116+
try_chan_entry!(self, chan.get_mut().update_fee(&self.fee_estimator, &msg), chan);
51175117
},
51185118
hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel".to_owned(), msg.channel_id))
51195119
}
@@ -5135,7 +5135,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
51355135

51365136
channel_state.pending_msg_events.push(events::MessageSendEvent::BroadcastChannelAnnouncement {
51375137
msg: try_chan_entry!(self, chan.get_mut().announcement_signatures(
5138-
self.get_our_node_id(), self.genesis_hash.clone(), self.best_block.read().unwrap().height(), msg), channel_state, chan),
5138+
self.get_our_node_id(), self.genesis_hash.clone(), self.best_block.read().unwrap().height(), msg), chan),
51395139
// Note that announcement_signatures fails if the channel cannot be announced,
51405140
// so get_channel_update_for_broadcast will never fail by the time we get here.
51415141
update_msg: self.get_channel_update_for_broadcast(chan.get()).unwrap(),
@@ -5174,7 +5174,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
51745174
return Ok(NotifyOption::SkipPersist);
51755175
} else {
51765176
log_debug!(self.logger, "Received channel_update for channel {}.", log_bytes!(chan_id));
5177-
try_chan_entry!(self, chan.get_mut().channel_update(&msg), channel_state, chan);
5177+
try_chan_entry!(self, chan.get_mut().channel_update(&msg), chan);
51785178
}
51795179
},
51805180
hash_map::Entry::Vacant(_) => unreachable!()
@@ -5199,7 +5199,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
51995199
// add-HTLCs on disconnect, we may be handed HTLCs to fail backwards here.
52005200
let responses = try_chan_entry!(self, chan.get_mut().channel_reestablish(
52015201
msg, &self.logger, self.our_network_pubkey.clone(), self.genesis_hash,
5202-
&*self.best_block.read().unwrap()), channel_state, chan);
5202+
&*self.best_block.read().unwrap()), chan);
52035203
let mut channel_update = None;
52045204
if let Some(msg) = responses.shutdown_msg {
52055205
channel_state.pending_msg_events.push(events::MessageSendEvent::SendShutdown {
@@ -5263,7 +5263,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
52635263
let by_id = &mut channel_state.by_id;
52645264
let pending_msg_events = &mut channel_state.pending_msg_events;
52655265
if let hash_map::Entry::Occupied(chan_entry) = by_id.entry(funding_outpoint.to_channel_id()) {
5266-
let mut chan = remove_channel!(self, channel_state, chan_entry);
5266+
let mut chan = remove_channel!(self, chan_entry);
52675267
failed_channels.push(chan.force_shutdown(false));
52685268
if let Ok(update) = self.get_channel_update_for_broadcast(&chan) {
52695269
pending_msg_events.push(events::MessageSendEvent::BroadcastChannelUpdate {

0 commit comments

Comments
 (0)