Skip to content

Commit bbe4d7c

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 569f172 commit bbe4d7c

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
@@ -1312,7 +1312,7 @@ macro_rules! convert_chan_err {
13121312
}
13131313

13141314
macro_rules! break_chan_entry {
1315-
($self: ident, $res: expr, $channel_state: expr, $entry: expr) => {
1315+
($self: ident, $res: expr, $entry: expr) => {
13161316
match $res {
13171317
Ok(res) => res,
13181318
Err(e) => {
@@ -1327,7 +1327,7 @@ macro_rules! break_chan_entry {
13271327
}
13281328

13291329
macro_rules! try_chan_entry {
1330-
($self: ident, $res: expr, $channel_state: expr, $entry: expr) => {
1330+
($self: ident, $res: expr, $entry: expr) => {
13311331
match $res {
13321332
Ok(res) => res,
13331333
Err(e) => {
@@ -1342,7 +1342,7 @@ macro_rules! try_chan_entry {
13421342
}
13431343

13441344
macro_rules! remove_channel {
1345-
($self: expr, $channel_state: expr, $entry: expr) => {
1345+
($self: expr, $entry: expr) => {
13461346
{
13471347
let channel = $entry.remove_entry().1;
13481348
update_maps_on_chan_removal!($self, channel);
@@ -1421,17 +1421,17 @@ macro_rules! handle_monitor_err {
14211421
}
14221422

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

14321432
// Does not break in case of TemporaryFailure!
14331433
macro_rules! maybe_break_monitor_err {
1434-
($self: ident, $err: expr, $channel_state: expr, $entry: expr, $action_type: path, $resend_raa: expr, $resend_commitment: expr) => {
1434+
($self: ident, $err: expr, $entry: expr, $action_type: path, $resend_raa: expr, $resend_commitment: expr) => {
14351435
match (handle_monitor_err!($self, $err, $entry, $action_type, $resend_raa, $resend_commitment), $err) {
14361436
(e, ChannelMonitorUpdateErr::PermanentFailure) => {
14371437
break e;
@@ -1880,7 +1880,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
18801880
let (result, is_permanent) =
18811881
handle_monitor_err!(self, e, chan_entry.get_mut(), RAACommitmentOrder::CommitmentFirst, chan_entry.key(), NO_UPDATE);
18821882
if is_permanent {
1883-
remove_channel!(self, channel_state, chan_entry);
1883+
remove_channel!(self, chan_entry);
18841884
break result;
18851885
}
18861886
}
@@ -1892,7 +1892,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
18921892
});
18931893

18941894
if chan_entry.get().is_shutdown() {
1895-
let channel = remove_channel!(self, channel_state, chan_entry);
1895+
let channel = remove_channel!(self, chan_entry);
18961896
if let Ok(channel_update) = self.get_channel_update_for_broadcast(&channel) {
18971897
channel_state.pending_msg_events.push(events::MessageSendEvent::BroadcastChannelUpdate {
18981898
msg: channel_update
@@ -1993,7 +1993,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
19931993
} else {
19941994
self.issue_channel_close_events(chan.get(),ClosureReason::HolderForceClosed);
19951995
}
1996-
remove_channel!(self, channel_state, chan)
1996+
remove_channel!(self, chan)
19971997
} else {
19981998
return Err(APIError::ChannelUnavailable{err: "No such channel".to_owned()});
19991999
}
@@ -2495,11 +2495,11 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
24952495
payment_secret: payment_secret.clone(),
24962496
payment_params: payment_params.clone(),
24972497
}, onion_packet, &self.logger),
2498-
channel_state, chan)
2498+
chan)
24992499
} {
25002500
Some((update_add, commitment_signed, monitor_update)) => {
25012501
if let Err(e) = self.chain_monitor.update_channel(chan.get().get_funding_txo().unwrap(), monitor_update) {
2502-
maybe_break_monitor_err!(self, e, channel_state, chan, RAACommitmentOrder::CommitmentFirst, false, true);
2502+
maybe_break_monitor_err!(self, e, chan, RAACommitmentOrder::CommitmentFirst, false, true);
25032503
// Note that MonitorUpdateFailed here indicates (per function docs)
25042504
// that we will resend the commitment update once monitor updating
25052505
// is restored. Therefore, we must return an error indicating that
@@ -3301,7 +3301,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
33013301
}
33023302
ChannelError::Close(msg) => {
33033303
log_trace!(self.logger, "Closing channel {} due to Close-required error: {}", log_bytes!(chan.key()[..]), msg);
3304-
let mut channel = remove_channel!(self, channel_state, chan);
3304+
let mut channel = remove_channel!(self, chan);
33053305
// ChannelClosed event is generated by handle_error for us.
33063306
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()))
33073307
},
@@ -4518,7 +4518,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
45184518
}
45194519
};
45204520
channel_state.pending_msg_events.push(send_msg_err_event);
4521-
let _ = remove_channel!(self, channel_state, channel);
4521+
let _ = remove_channel!(self, channel);
45224522
return Err(APIError::APIMisuseError { err: "Please use accept_inbound_channel_from_trusted_peer_0conf to accept channels with zero confirmations.".to_owned() });
45234523
}
45244524

@@ -4598,7 +4598,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
45984598
if chan.get().get_counterparty_node_id() != *counterparty_node_id {
45994599
return Err(MsgHandleErrInternal::send_err_msg_no_close("Got a message for a channel from the wrong node!".to_owned(), msg.temporary_channel_id));
46004600
}
4601-
try_chan_entry!(self, chan.get_mut().accept_channel(&msg, &self.default_configuration.channel_handshake_limits, &their_features), channel_state, chan);
4601+
try_chan_entry!(self, chan.get_mut().accept_channel(&msg, &self.default_configuration.channel_handshake_limits, &their_features), chan);
46024602
(chan.get().get_value_satoshis(), chan.get().get_funding_redeemscript().to_v0_p2wsh(), chan.get().get_user_id())
46034603
},
46044604
hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel".to_owned(), msg.temporary_channel_id))
@@ -4625,7 +4625,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
46254625
if chan.get().get_counterparty_node_id() != *counterparty_node_id {
46264626
return Err(MsgHandleErrInternal::send_err_msg_no_close("Got a message for a channel from the wrong node!".to_owned(), msg.temporary_channel_id));
46274627
}
4628-
(try_chan_entry!(self, chan.get_mut().funding_created(msg, best_block, &self.logger), channel_state, chan), chan.remove())
4628+
(try_chan_entry!(self, chan.get_mut().funding_created(msg, best_block, &self.logger), chan), chan.remove())
46294629
},
46304630
hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel".to_owned(), msg.temporary_channel_id))
46314631
}
@@ -4699,7 +4699,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
46994699
}
47004700
let (monitor, funding_tx, channel_ready) = match chan.get_mut().funding_signed(&msg, best_block, &self.logger) {
47014701
Ok(update) => update,
4702-
Err(e) => try_chan_entry!(self, Err(e), channel_state, chan),
4702+
Err(e) => try_chan_entry!(self, Err(e), chan),
47034703
};
47044704
if let Err(e) = self.chain_monitor.watch_channel(chan.get().get_funding_txo().unwrap(), monitor) {
47054705
let mut res = handle_monitor_err!(self, e, chan, RAACommitmentOrder::RevokeAndACKFirst, channel_ready.is_some(), OPTIONALLY_RESEND_FUNDING_LOCKED);
@@ -4735,7 +4735,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
47354735
return Err(MsgHandleErrInternal::send_err_msg_no_close("Got a message for a channel from the wrong node!".to_owned(), msg.channel_id));
47364736
}
47374737
let announcement_sigs_opt = try_chan_entry!(self, chan.get_mut().channel_ready(&msg, self.get_our_node_id(),
4738-
self.genesis_hash.clone(), &self.best_block.read().unwrap(), &self.logger), channel_state, chan);
4738+
self.genesis_hash.clone(), &self.best_block.read().unwrap(), &self.logger), chan);
47394739
if let Some(announcement_sigs) = announcement_sigs_opt {
47404740
log_trace!(self.logger, "Sending announcement_signatures for channel {}", log_bytes!(chan.get().channel_id()));
47414741
channel_state.pending_msg_events.push(events::MessageSendEvent::SendAnnouncementSignatures {
@@ -4780,7 +4780,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
47804780
if chan_entry.get().sent_shutdown() { " after we initiated shutdown" } else { "" });
47814781
}
47824782

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

47864786
// Update the monitor with the shutdown script if necessary.
@@ -4789,7 +4789,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
47894789
let (result, is_permanent) =
47904790
handle_monitor_err!(self, e, chan_entry.get_mut(), RAACommitmentOrder::CommitmentFirst, chan_entry.key(), NO_UPDATE);
47914791
if is_permanent {
4792-
remove_channel!(self, channel_state, chan_entry);
4792+
remove_channel!(self, chan_entry);
47934793
break result;
47944794
}
47954795
}
@@ -4825,7 +4825,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
48254825
if chan_entry.get().get_counterparty_node_id() != *counterparty_node_id {
48264826
return Err(MsgHandleErrInternal::send_err_msg_no_close("Got a message for a channel from the wrong node!".to_owned(), msg.channel_id));
48274827
}
4828-
let (closing_signed, tx) = try_chan_entry!(self, chan_entry.get_mut().closing_signed(&self.fee_estimator, &msg), channel_state, chan_entry);
4828+
let (closing_signed, tx) = try_chan_entry!(self, chan_entry.get_mut().closing_signed(&self.fee_estimator, &msg), chan_entry);
48294829
if let Some(msg) = closing_signed {
48304830
channel_state.pending_msg_events.push(events::MessageSendEvent::SendClosingSigned {
48314831
node_id: counterparty_node_id.clone(),
@@ -4838,7 +4838,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
48384838
// also implies there are no pending HTLCs left on the channel, so we can
48394839
// fully delete it from tracking (the channel monitor is still around to
48404840
// watch for old state broadcasts)!
4841-
(tx, Some(remove_channel!(self, channel_state, chan_entry)))
4841+
(tx, Some(remove_channel!(self, chan_entry)))
48424842
} else { (tx, None) }
48434843
},
48444844
hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel".to_owned(), msg.channel_id))
@@ -4902,7 +4902,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
49024902
_ => pending_forward_info
49034903
}
49044904
};
4905-
try_chan_entry!(self, chan.get_mut().update_add_htlc(&msg, pending_forward_info, create_pending_htlc_status, &self.logger), channel_state, chan);
4905+
try_chan_entry!(self, chan.get_mut().update_add_htlc(&msg, pending_forward_info, create_pending_htlc_status, &self.logger), chan);
49064906
},
49074907
hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel".to_owned(), msg.channel_id))
49084908
}
@@ -4918,7 +4918,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
49184918
if chan.get().get_counterparty_node_id() != *counterparty_node_id {
49194919
return Err(MsgHandleErrInternal::send_err_msg_no_close("Got a message for a channel from the wrong node!".to_owned(), msg.channel_id));
49204920
}
4921-
try_chan_entry!(self, chan.get_mut().update_fulfill_htlc(&msg), channel_state, chan)
4921+
try_chan_entry!(self, chan.get_mut().update_fulfill_htlc(&msg), chan)
49224922
},
49234923
hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel".to_owned(), msg.channel_id))
49244924
}
@@ -4935,7 +4935,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
49354935
if chan.get().get_counterparty_node_id() != *counterparty_node_id {
49364936
return Err(MsgHandleErrInternal::send_err_msg_no_close("Got a message for a channel from the wrong node!".to_owned(), msg.channel_id));
49374937
}
4938-
try_chan_entry!(self, chan.get_mut().update_fail_htlc(&msg, HTLCFailReason::LightningError { err: msg.reason.clone() }), channel_state, chan);
4938+
try_chan_entry!(self, chan.get_mut().update_fail_htlc(&msg, HTLCFailReason::LightningError { err: msg.reason.clone() }), chan);
49394939
},
49404940
hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel".to_owned(), msg.channel_id))
49414941
}
@@ -4952,9 +4952,9 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
49524952
}
49534953
if (msg.failure_code & 0x8000) == 0 {
49544954
let chan_err: ChannelError = ChannelError::Close("Got update_fail_malformed_htlc with BADONION not set".to_owned());
4955-
try_chan_entry!(self, Err(chan_err), channel_state, chan);
4955+
try_chan_entry!(self, Err(chan_err), chan);
49564956
}
4957-
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);
4957+
try_chan_entry!(self, chan.get_mut().update_fail_malformed_htlc(&msg, HTLCFailReason::Reason { failure_code: msg.failure_code, data: Vec::new() }), chan);
49584958
Ok(())
49594959
},
49604960
hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel".to_owned(), msg.channel_id))
@@ -4971,17 +4971,17 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
49714971
}
49724972
let (revoke_and_ack, commitment_signed, monitor_update) =
49734973
match chan.get_mut().commitment_signed(&msg, &self.logger) {
4974-
Err((None, e)) => try_chan_entry!(self, Err(e), channel_state, chan),
4974+
Err((None, e)) => try_chan_entry!(self, Err(e), chan),
49754975
Err((Some(update), e)) => {
49764976
assert!(chan.get().is_awaiting_monitor_update());
49774977
let _ = self.chain_monitor.update_channel(chan.get().get_funding_txo().unwrap(), update);
4978-
try_chan_entry!(self, Err(e), channel_state, chan);
4978+
try_chan_entry!(self, Err(e), chan);
49794979
unreachable!();
49804980
},
49814981
Ok(res) => res
49824982
};
49834983
if let Err(e) = self.chain_monitor.update_channel(chan.get().get_funding_txo().unwrap(), monitor_update) {
4984-
return_monitor_err!(self, e, channel_state, chan, RAACommitmentOrder::RevokeAndACKFirst, true, commitment_signed.is_some());
4984+
return_monitor_err!(self, e, chan, RAACommitmentOrder::RevokeAndACKFirst, true, commitment_signed.is_some());
49854985
}
49864986
channel_state.pending_msg_events.push(events::MessageSendEvent::SendRevokeAndACK {
49874987
node_id: counterparty_node_id.clone(),
@@ -5056,7 +5056,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
50565056
}
50575057
let was_frozen_for_monitor = chan.get().is_awaiting_monitor_update();
50585058
let raa_updates = break_chan_entry!(self,
5059-
chan.get_mut().revoke_and_ack(&msg, &self.logger), channel_state, chan);
5059+
chan.get_mut().revoke_and_ack(&msg, &self.logger), chan);
50605060
htlcs_to_fail = raa_updates.holding_cell_failed_htlcs;
50615061
if let Err(e) = self.chain_monitor.update_channel(chan.get().get_funding_txo().unwrap(), raa_updates.monitor_update) {
50625062
if was_frozen_for_monitor {
@@ -5115,7 +5115,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
51155115
if chan.get().get_counterparty_node_id() != *counterparty_node_id {
51165116
return Err(MsgHandleErrInternal::send_err_msg_no_close("Got a message for a channel from the wrong node!".to_owned(), msg.channel_id));
51175117
}
5118-
try_chan_entry!(self, chan.get_mut().update_fee(&self.fee_estimator, &msg), channel_state, chan);
5118+
try_chan_entry!(self, chan.get_mut().update_fee(&self.fee_estimator, &msg), chan);
51195119
},
51205120
hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel".to_owned(), msg.channel_id))
51215121
}
@@ -5137,7 +5137,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
51375137

51385138
channel_state.pending_msg_events.push(events::MessageSendEvent::BroadcastChannelAnnouncement {
51395139
msg: try_chan_entry!(self, chan.get_mut().announcement_signatures(
5140-
self.get_our_node_id(), self.genesis_hash.clone(), self.best_block.read().unwrap().height(), msg), channel_state, chan),
5140+
self.get_our_node_id(), self.genesis_hash.clone(), self.best_block.read().unwrap().height(), msg), chan),
51415141
// Note that announcement_signatures fails if the channel cannot be announced,
51425142
// so get_channel_update_for_broadcast will never fail by the time we get here.
51435143
update_msg: self.get_channel_update_for_broadcast(chan.get()).unwrap(),
@@ -5175,7 +5175,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
51755175
if were_node_one == msg_from_node_one {
51765176
return Ok(NotifyOption::SkipPersist);
51775177
} else {
5178-
try_chan_entry!(self, chan.get_mut().channel_update(&msg), channel_state, chan);
5178+
try_chan_entry!(self, chan.get_mut().channel_update(&msg), chan);
51795179
}
51805180
},
51815181
hash_map::Entry::Vacant(_) => unreachable!()
@@ -5200,7 +5200,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
52005200
// add-HTLCs on disconnect, we may be handed HTLCs to fail backwards here.
52015201
let responses = try_chan_entry!(self, chan.get_mut().channel_reestablish(
52025202
msg, &self.logger, self.our_network_pubkey.clone(), self.genesis_hash,
5203-
&*self.best_block.read().unwrap()), channel_state, chan);
5203+
&*self.best_block.read().unwrap()), chan);
52045204
let mut channel_update = None;
52055205
if let Some(msg) = responses.shutdown_msg {
52065206
channel_state.pending_msg_events.push(events::MessageSendEvent::SendShutdown {
@@ -5264,7 +5264,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
52645264
let by_id = &mut channel_state.by_id;
52655265
let pending_msg_events = &mut channel_state.pending_msg_events;
52665266
if let hash_map::Entry::Occupied(chan_entry) = by_id.entry(funding_outpoint.to_channel_id()) {
5267-
let mut chan = remove_channel!(self, channel_state, chan_entry);
5267+
let mut chan = remove_channel!(self, chan_entry);
52685268
failed_channels.push(chan.force_shutdown(false));
52695269
if let Ok(update) = self.get_channel_update_for_broadcast(&chan) {
52705270
pending_msg_events.push(events::MessageSendEvent::BroadcastChannelUpdate {

0 commit comments

Comments
 (0)