Skip to content

Commit 1da7a95

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 4a83796 commit 1da7a95

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
@@ -1315,7 +1315,7 @@ macro_rules! convert_chan_err {
13151315
}
13161316

13171317
macro_rules! break_chan_entry {
1318-
($self: ident, $res: expr, $channel_state: expr, $entry: expr) => {
1318+
($self: ident, $res: expr, $entry: expr) => {
13191319
match $res {
13201320
Ok(res) => res,
13211321
Err(e) => {
@@ -1330,7 +1330,7 @@ macro_rules! break_chan_entry {
13301330
}
13311331

13321332
macro_rules! try_chan_entry {
1333-
($self: ident, $res: expr, $channel_state: expr, $entry: expr) => {
1333+
($self: ident, $res: expr, $entry: expr) => {
13341334
match $res {
13351335
Ok(res) => res,
13361336
Err(e) => {
@@ -1345,7 +1345,7 @@ macro_rules! try_chan_entry {
13451345
}
13461346

13471347
macro_rules! remove_channel {
1348-
($self: expr, $channel_state: expr, $entry: expr) => {
1348+
($self: expr, $entry: expr) => {
13491349
{
13501350
update_maps_on_chan_removal!($self, $entry.get());
13511351
let removed_channel = $entry.remove_entry().1;
@@ -1424,17 +1424,17 @@ macro_rules! handle_monitor_err {
14241424
}
14251425

14261426
macro_rules! return_monitor_err {
1427-
($self: ident, $err: expr, $channel_state: expr, $entry: expr, $action_type: path, $resend_raa: expr, $resend_commitment: expr) => {
1427+
($self: ident, $err: expr, $entry: expr, $action_type: path, $resend_raa: expr, $resend_commitment: expr) => {
14281428
return handle_monitor_err!($self, $err, $entry, $action_type, $resend_raa, $resend_commitment);
14291429
};
1430-
($self: ident, $err: expr, $channel_state: expr, $entry: expr, $action_type: path, $resend_raa: expr, $resend_commitment: expr, $failed_forwards: expr, $failed_fails: expr) => {
1430+
($self: ident, $err: expr, $entry: expr, $action_type: path, $resend_raa: expr, $resend_commitment: expr, $failed_forwards: expr, $failed_fails: expr) => {
14311431
return handle_monitor_err!($self, $err, $entry, $action_type, $resend_raa, $resend_commitment, $failed_forwards, $failed_fails);
14321432
}
14331433
}
14341434

14351435
// Does not break in case of TemporaryFailure!
14361436
macro_rules! maybe_break_monitor_err {
1437-
($self: ident, $err: expr, $channel_state: expr, $entry: expr, $action_type: path, $resend_raa: expr, $resend_commitment: expr) => {
1437+
($self: ident, $err: expr, $entry: expr, $action_type: path, $resend_raa: expr, $resend_commitment: expr) => {
14381438
match (handle_monitor_err!($self, $err, $entry, $action_type, $resend_raa, $resend_commitment), $err) {
14391439
(e, ChannelMonitorUpdateErr::PermanentFailure) => {
14401440
break e;
@@ -1883,7 +1883,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
18831883
let (result, is_permanent) =
18841884
handle_monitor_err!(self, e, chan_entry.get_mut(), RAACommitmentOrder::CommitmentFirst, chan_entry.key(), NO_UPDATE);
18851885
if is_permanent {
1886-
remove_channel!(self, channel_state, chan_entry);
1886+
remove_channel!(self, chan_entry);
18871887
break result;
18881888
}
18891889
}
@@ -1895,7 +1895,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
18951895
});
18961896

18971897
if chan_entry.get().is_shutdown() {
1898-
let channel = remove_channel!(self, channel_state, chan_entry);
1898+
let channel = remove_channel!(self, chan_entry);
18991899
if let Ok(channel_update) = self.get_channel_update_for_broadcast(&channel) {
19001900
channel_state.pending_msg_events.push(events::MessageSendEvent::BroadcastChannelUpdate {
19011901
msg: channel_update
@@ -1996,7 +1996,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
19961996
} else {
19971997
self.issue_channel_close_events(chan.get(),ClosureReason::HolderForceClosed);
19981998
}
1999-
remove_channel!(self, channel_state, chan)
1999+
remove_channel!(self, chan)
20002000
} else {
20012001
return Err(APIError::ChannelUnavailable{err: "No such channel".to_owned()});
20022002
}
@@ -2498,11 +2498,11 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
24982498
payment_secret: payment_secret.clone(),
24992499
payment_params: payment_params.clone(),
25002500
}, onion_packet, &self.logger),
2501-
channel_state, chan)
2501+
chan)
25022502
} {
25032503
Some((update_add, commitment_signed, monitor_update)) => {
25042504
if let Err(e) = self.chain_monitor.update_channel(chan.get().get_funding_txo().unwrap(), monitor_update) {
2505-
maybe_break_monitor_err!(self, e, channel_state, chan, RAACommitmentOrder::CommitmentFirst, false, true);
2505+
maybe_break_monitor_err!(self, e, chan, RAACommitmentOrder::CommitmentFirst, false, true);
25062506
// Note that MonitorUpdateFailed here indicates (per function docs)
25072507
// that we will resend the commitment update once monitor updating
25082508
// is restored. Therefore, we must return an error indicating that
@@ -3304,7 +3304,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
33043304
}
33053305
ChannelError::Close(msg) => {
33063306
log_trace!(self.logger, "Closing channel {} due to Close-required error: {}", log_bytes!(chan.key()[..]), msg);
3307-
let mut channel = remove_channel!(self, channel_state, chan);
3307+
let mut channel = remove_channel!(self, chan);
33083308
// ChannelClosed event is generated by handle_error for us.
33093309
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()))
33103310
},
@@ -4511,7 +4511,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
45114511
}
45124512
};
45134513
channel_state.pending_msg_events.push(send_msg_err_event);
4514-
let _ = remove_channel!(self, channel_state, channel);
4514+
let _ = remove_channel!(self, channel);
45154515
return Err(APIError::APIMisuseError { err: "Please use accept_inbound_channel_from_trusted_peer_0conf to accept channels with zero confirmations.".to_owned() });
45164516
}
45174517

@@ -4591,7 +4591,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
45914591
if chan.get().get_counterparty_node_id() != *counterparty_node_id {
45924592
return Err(MsgHandleErrInternal::send_err_msg_no_close("Got a message for a channel from the wrong node!".to_owned(), msg.temporary_channel_id));
45934593
}
4594-
try_chan_entry!(self, chan.get_mut().accept_channel(&msg, &self.default_configuration.channel_handshake_limits, &their_features), channel_state, chan);
4594+
try_chan_entry!(self, chan.get_mut().accept_channel(&msg, &self.default_configuration.channel_handshake_limits, &their_features), chan);
45954595
(chan.get().get_value_satoshis(), chan.get().get_funding_redeemscript().to_v0_p2wsh(), chan.get().get_user_id())
45964596
},
45974597
hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel".to_owned(), msg.temporary_channel_id))
@@ -4618,7 +4618,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
46184618
if chan.get().get_counterparty_node_id() != *counterparty_node_id {
46194619
return Err(MsgHandleErrInternal::send_err_msg_no_close("Got a message for a channel from the wrong node!".to_owned(), msg.temporary_channel_id));
46204620
}
4621-
(try_chan_entry!(self, chan.get_mut().funding_created(msg, best_block, &self.logger), channel_state, chan), chan.remove())
4621+
(try_chan_entry!(self, chan.get_mut().funding_created(msg, best_block, &self.logger), chan), chan.remove())
46224622
},
46234623
hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel".to_owned(), msg.temporary_channel_id))
46244624
}
@@ -4698,7 +4698,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
46984698
}
46994699
let (monitor, funding_tx, channel_ready) = match chan.get_mut().funding_signed(&msg, best_block, &self.logger) {
47004700
Ok(update) => update,
4701-
Err(e) => try_chan_entry!(self, Err(e), channel_state, chan),
4701+
Err(e) => try_chan_entry!(self, Err(e), chan),
47024702
};
47034703
if let Err(e) = self.chain_monitor.watch_channel(chan.get().get_funding_txo().unwrap(), monitor) {
47044704
let mut res = handle_monitor_err!(self, e, chan, RAACommitmentOrder::RevokeAndACKFirst, channel_ready.is_some(), OPTIONALLY_RESEND_FUNDING_LOCKED);
@@ -4734,7 +4734,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
47344734
return Err(MsgHandleErrInternal::send_err_msg_no_close("Got a message for a channel from the wrong node!".to_owned(), msg.channel_id));
47354735
}
47364736
let announcement_sigs_opt = try_chan_entry!(self, chan.get_mut().channel_ready(&msg, self.get_our_node_id(),
4737-
self.genesis_hash.clone(), &self.best_block.read().unwrap(), &self.logger), channel_state, chan);
4737+
self.genesis_hash.clone(), &self.best_block.read().unwrap(), &self.logger), chan);
47384738
if let Some(announcement_sigs) = announcement_sigs_opt {
47394739
log_trace!(self.logger, "Sending announcement_signatures for channel {}", log_bytes!(chan.get().channel_id()));
47404740
channel_state.pending_msg_events.push(events::MessageSendEvent::SendAnnouncementSignatures {
@@ -4779,7 +4779,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
47794779
if chan_entry.get().sent_shutdown() { " after we initiated shutdown" } else { "" });
47804780
}
47814781

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

47854785
// Update the monitor with the shutdown script if necessary.
@@ -4788,7 +4788,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
47884788
let (result, is_permanent) =
47894789
handle_monitor_err!(self, e, chan_entry.get_mut(), RAACommitmentOrder::CommitmentFirst, chan_entry.key(), NO_UPDATE);
47904790
if is_permanent {
4791-
remove_channel!(self, channel_state, chan_entry);
4791+
remove_channel!(self, chan_entry);
47924792
break result;
47934793
}
47944794
}
@@ -4824,7 +4824,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
48244824
if chan_entry.get().get_counterparty_node_id() != *counterparty_node_id {
48254825
return Err(MsgHandleErrInternal::send_err_msg_no_close("Got a message for a channel from the wrong node!".to_owned(), msg.channel_id));
48264826
}
4827-
let (closing_signed, tx) = try_chan_entry!(self, chan_entry.get_mut().closing_signed(&self.fee_estimator, &msg), channel_state, chan_entry);
4827+
let (closing_signed, tx) = try_chan_entry!(self, chan_entry.get_mut().closing_signed(&self.fee_estimator, &msg), chan_entry);
48284828
if let Some(msg) = closing_signed {
48294829
channel_state.pending_msg_events.push(events::MessageSendEvent::SendClosingSigned {
48304830
node_id: counterparty_node_id.clone(),
@@ -4837,7 +4837,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
48374837
// also implies there are no pending HTLCs left on the channel, so we can
48384838
// fully delete it from tracking (the channel monitor is still around to
48394839
// watch for old state broadcasts)!
4840-
(tx, Some(remove_channel!(self, channel_state, chan_entry)))
4840+
(tx, Some(remove_channel!(self, chan_entry)))
48414841
} else { (tx, None) }
48424842
},
48434843
hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel".to_owned(), msg.channel_id))
@@ -4901,7 +4901,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
49014901
_ => pending_forward_info
49024902
}
49034903
};
4904-
try_chan_entry!(self, chan.get_mut().update_add_htlc(&msg, pending_forward_info, create_pending_htlc_status, &self.logger), channel_state, chan);
4904+
try_chan_entry!(self, chan.get_mut().update_add_htlc(&msg, pending_forward_info, create_pending_htlc_status, &self.logger), chan);
49054905
},
49064906
hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel".to_owned(), msg.channel_id))
49074907
}
@@ -4917,7 +4917,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
49174917
if chan.get().get_counterparty_node_id() != *counterparty_node_id {
49184918
return Err(MsgHandleErrInternal::send_err_msg_no_close("Got a message for a channel from the wrong node!".to_owned(), msg.channel_id));
49194919
}
4920-
try_chan_entry!(self, chan.get_mut().update_fulfill_htlc(&msg), channel_state, chan)
4920+
try_chan_entry!(self, chan.get_mut().update_fulfill_htlc(&msg), chan)
49214921
},
49224922
hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel".to_owned(), msg.channel_id))
49234923
}
@@ -4934,7 +4934,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
49344934
if chan.get().get_counterparty_node_id() != *counterparty_node_id {
49354935
return Err(MsgHandleErrInternal::send_err_msg_no_close("Got a message for a channel from the wrong node!".to_owned(), msg.channel_id));
49364936
}
4937-
try_chan_entry!(self, chan.get_mut().update_fail_htlc(&msg, HTLCFailReason::LightningError { err: msg.reason.clone() }), channel_state, chan);
4937+
try_chan_entry!(self, chan.get_mut().update_fail_htlc(&msg, HTLCFailReason::LightningError { err: msg.reason.clone() }), chan);
49384938
},
49394939
hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel".to_owned(), msg.channel_id))
49404940
}
@@ -4951,9 +4951,9 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
49514951
}
49524952
if (msg.failure_code & 0x8000) == 0 {
49534953
let chan_err: ChannelError = ChannelError::Close("Got update_fail_malformed_htlc with BADONION not set".to_owned());
4954-
try_chan_entry!(self, Err(chan_err), channel_state, chan);
4954+
try_chan_entry!(self, Err(chan_err), chan);
49554955
}
4956-
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);
4956+
try_chan_entry!(self, chan.get_mut().update_fail_malformed_htlc(&msg, HTLCFailReason::Reason { failure_code: msg.failure_code, data: Vec::new() }), chan);
49574957
Ok(())
49584958
},
49594959
hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel".to_owned(), msg.channel_id))
@@ -4970,17 +4970,17 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
49704970
}
49714971
let (revoke_and_ack, commitment_signed, monitor_update) =
49724972
match chan.get_mut().commitment_signed(&msg, &self.logger) {
4973-
Err((None, e)) => try_chan_entry!(self, Err(e), channel_state, chan),
4973+
Err((None, e)) => try_chan_entry!(self, Err(e), chan),
49744974
Err((Some(update), e)) => {
49754975
assert!(chan.get().is_awaiting_monitor_update());
49764976
let _ = self.chain_monitor.update_channel(chan.get().get_funding_txo().unwrap(), update);
4977-
try_chan_entry!(self, Err(e), channel_state, chan);
4977+
try_chan_entry!(self, Err(e), chan);
49784978
unreachable!();
49794979
},
49804980
Ok(res) => res
49814981
};
49824982
if let Err(e) = self.chain_monitor.update_channel(chan.get().get_funding_txo().unwrap(), monitor_update) {
4983-
return_monitor_err!(self, e, channel_state, chan, RAACommitmentOrder::RevokeAndACKFirst, true, commitment_signed.is_some());
4983+
return_monitor_err!(self, e, chan, RAACommitmentOrder::RevokeAndACKFirst, true, commitment_signed.is_some());
49844984
}
49854985
channel_state.pending_msg_events.push(events::MessageSendEvent::SendRevokeAndACK {
49864986
node_id: counterparty_node_id.clone(),
@@ -5055,7 +5055,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
50555055
}
50565056
let was_frozen_for_monitor = chan.get().is_awaiting_monitor_update();
50575057
let raa_updates = break_chan_entry!(self,
5058-
chan.get_mut().revoke_and_ack(&msg, &self.logger), channel_state, chan);
5058+
chan.get_mut().revoke_and_ack(&msg, &self.logger), chan);
50595059
htlcs_to_fail = raa_updates.holding_cell_failed_htlcs;
50605060
if let Err(e) = self.chain_monitor.update_channel(chan.get().get_funding_txo().unwrap(), raa_updates.monitor_update) {
50615061
if was_frozen_for_monitor {
@@ -5114,7 +5114,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
51145114
if chan.get().get_counterparty_node_id() != *counterparty_node_id {
51155115
return Err(MsgHandleErrInternal::send_err_msg_no_close("Got a message for a channel from the wrong node!".to_owned(), msg.channel_id));
51165116
}
5117-
try_chan_entry!(self, chan.get_mut().update_fee(&self.fee_estimator, &msg), channel_state, chan);
5117+
try_chan_entry!(self, chan.get_mut().update_fee(&self.fee_estimator, &msg), chan);
51185118
},
51195119
hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel".to_owned(), msg.channel_id))
51205120
}
@@ -5136,7 +5136,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
51365136

51375137
channel_state.pending_msg_events.push(events::MessageSendEvent::BroadcastChannelAnnouncement {
51385138
msg: try_chan_entry!(self, chan.get_mut().announcement_signatures(
5139-
self.get_our_node_id(), self.genesis_hash.clone(), self.best_block.read().unwrap().height(), msg), channel_state, chan),
5139+
self.get_our_node_id(), self.genesis_hash.clone(), self.best_block.read().unwrap().height(), msg), chan),
51405140
// Note that announcement_signatures fails if the channel cannot be announced,
51415141
// so get_channel_update_for_broadcast will never fail by the time we get here.
51425142
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
if were_node_one == msg_from_node_one {
51755175
return Ok(NotifyOption::SkipPersist);
51765176
} else {
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)