Skip to content

Commit d9eb4c1

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 fcbe0a5 commit d9eb4c1

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
@@ -1303,7 +1303,7 @@ macro_rules! convert_chan_err {
13031303
}
13041304

13051305
macro_rules! break_chan_entry {
1306-
($self: ident, $res: expr, $channel_state: expr, $entry: expr) => {
1306+
($self: ident, $res: expr, $entry: expr) => {
13071307
match $res {
13081308
Ok(res) => res,
13091309
Err(e) => {
@@ -1318,7 +1318,7 @@ macro_rules! break_chan_entry {
13181318
}
13191319

13201320
macro_rules! try_chan_entry {
1321-
($self: ident, $res: expr, $channel_state: expr, $entry: expr) => {
1321+
($self: ident, $res: expr, $entry: expr) => {
13221322
match $res {
13231323
Ok(res) => res,
13241324
Err(e) => {
@@ -1333,7 +1333,7 @@ macro_rules! try_chan_entry {
13331333
}
13341334

13351335
macro_rules! remove_channel {
1336-
($self: expr, $channel_state: expr, $entry: expr) => {
1336+
($self: expr, $entry: expr) => {
13371337
{
13381338
let channel = $entry.remove_entry().1;
13391339
update_maps_on_chan_removal!($self, channel);
@@ -1412,17 +1412,17 @@ macro_rules! handle_monitor_err {
14121412
}
14131413

14141414
macro_rules! return_monitor_err {
1415-
($self: ident, $err: expr, $channel_state: expr, $entry: expr, $action_type: path, $resend_raa: expr, $resend_commitment: expr) => {
1415+
($self: ident, $err: expr, $entry: expr, $action_type: path, $resend_raa: expr, $resend_commitment: expr) => {
14161416
return handle_monitor_err!($self, $err, $entry, $action_type, $resend_raa, $resend_commitment);
14171417
};
1418-
($self: ident, $err: expr, $channel_state: expr, $entry: expr, $action_type: path, $resend_raa: expr, $resend_commitment: expr, $failed_forwards: expr, $failed_fails: expr) => {
1418+
($self: ident, $err: expr, $entry: expr, $action_type: path, $resend_raa: expr, $resend_commitment: expr, $failed_forwards: expr, $failed_fails: expr) => {
14191419
return handle_monitor_err!($self, $err, $entry, $action_type, $resend_raa, $resend_commitment, $failed_forwards, $failed_fails);
14201420
}
14211421
}
14221422

14231423
// Does not break in case of TemporaryFailure!
14241424
macro_rules! maybe_break_monitor_err {
1425-
($self: ident, $err: expr, $channel_state: expr, $entry: expr, $action_type: path, $resend_raa: expr, $resend_commitment: expr) => {
1425+
($self: ident, $err: expr, $entry: expr, $action_type: path, $resend_raa: expr, $resend_commitment: expr) => {
14261426
match (handle_monitor_err!($self, $err, $entry, $action_type, $resend_raa, $resend_commitment), $err) {
14271427
(e, ChannelMonitorUpdateErr::PermanentFailure) => {
14281428
break e;
@@ -1871,7 +1871,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
18711871
let (result, is_permanent) =
18721872
handle_monitor_err!(self, e, chan_entry.get_mut(), RAACommitmentOrder::CommitmentFirst, chan_entry.key(), NO_UPDATE);
18731873
if is_permanent {
1874-
remove_channel!(self, channel_state, chan_entry);
1874+
remove_channel!(self, chan_entry);
18751875
break result;
18761876
}
18771877
}
@@ -1883,7 +1883,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
18831883
});
18841884

18851885
if chan_entry.get().is_shutdown() {
1886-
let channel = remove_channel!(self, channel_state, chan_entry);
1886+
let channel = remove_channel!(self, chan_entry);
18871887
if let Ok(channel_update) = self.get_channel_update_for_broadcast(&channel) {
18881888
channel_state.pending_msg_events.push(events::MessageSendEvent::BroadcastChannelUpdate {
18891889
msg: channel_update
@@ -1984,7 +1984,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
19841984
} else {
19851985
self.issue_channel_close_events(chan.get(),ClosureReason::HolderForceClosed);
19861986
}
1987-
remove_channel!(self, channel_state, chan)
1987+
remove_channel!(self, chan)
19881988
} else {
19891989
return Err(APIError::ChannelUnavailable{err: "No such channel".to_owned()});
19901990
}
@@ -2486,11 +2486,11 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
24862486
payment_secret: payment_secret.clone(),
24872487
payment_params: payment_params.clone(),
24882488
}, onion_packet, &self.logger),
2489-
channel_state, chan)
2489+
chan)
24902490
} {
24912491
Some((update_add, commitment_signed, monitor_update)) => {
24922492
if let Err(e) = self.chain_monitor.update_channel(chan.get().get_funding_txo().unwrap(), monitor_update) {
2493-
maybe_break_monitor_err!(self, e, channel_state, chan, RAACommitmentOrder::CommitmentFirst, false, true);
2493+
maybe_break_monitor_err!(self, e, chan, RAACommitmentOrder::CommitmentFirst, false, true);
24942494
// Note that MonitorUpdateFailed here indicates (per function docs)
24952495
// that we will resend the commitment update once monitor updating
24962496
// is restored. Therefore, we must return an error indicating that
@@ -3292,7 +3292,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
32923292
}
32933293
ChannelError::Close(msg) => {
32943294
log_trace!(self.logger, "Closing channel {} due to Close-required error: {}", log_bytes!(chan.key()[..]), msg);
3295-
let mut channel = remove_channel!(self, channel_state, chan);
3295+
let mut channel = remove_channel!(self, chan);
32963296
// ChannelClosed event is generated by handle_error for us.
32973297
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()))
32983298
},
@@ -4499,7 +4499,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
44994499
}
45004500
};
45014501
channel_state.pending_msg_events.push(send_msg_err_event);
4502-
let _ = remove_channel!(self, channel_state, channel);
4502+
let _ = remove_channel!(self, channel);
45034503
return Err(APIError::APIMisuseError { err: "Please use accept_inbound_channel_from_trusted_peer_0conf to accept channels with zero confirmations.".to_owned() });
45044504
}
45054505

@@ -4579,7 +4579,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
45794579
if chan.get().get_counterparty_node_id() != *counterparty_node_id {
45804580
return Err(MsgHandleErrInternal::send_err_msg_no_close("Got a message for a channel from the wrong node!".to_owned(), msg.temporary_channel_id));
45814581
}
4582-
try_chan_entry!(self, chan.get_mut().accept_channel(&msg, &self.default_configuration.channel_handshake_limits, &their_features), channel_state, chan);
4582+
try_chan_entry!(self, chan.get_mut().accept_channel(&msg, &self.default_configuration.channel_handshake_limits, &their_features), chan);
45834583
(chan.get().get_value_satoshis(), chan.get().get_funding_redeemscript().to_v0_p2wsh(), chan.get().get_user_id())
45844584
},
45854585
hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel".to_owned(), msg.temporary_channel_id))
@@ -4606,7 +4606,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
46064606
if chan.get().get_counterparty_node_id() != *counterparty_node_id {
46074607
return Err(MsgHandleErrInternal::send_err_msg_no_close("Got a message for a channel from the wrong node!".to_owned(), msg.temporary_channel_id));
46084608
}
4609-
(try_chan_entry!(self, chan.get_mut().funding_created(msg, best_block, &self.logger), channel_state, chan), chan.remove())
4609+
(try_chan_entry!(self, chan.get_mut().funding_created(msg, best_block, &self.logger), chan), chan.remove())
46104610
},
46114611
hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel".to_owned(), msg.temporary_channel_id))
46124612
}
@@ -4680,7 +4680,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
46804680
}
46814681
let (monitor, funding_tx, channel_ready) = match chan.get_mut().funding_signed(&msg, best_block, &self.logger) {
46824682
Ok(update) => update,
4683-
Err(e) => try_chan_entry!(self, Err(e), channel_state, chan),
4683+
Err(e) => try_chan_entry!(self, Err(e), chan),
46844684
};
46854685
if let Err(e) = self.chain_monitor.watch_channel(chan.get().get_funding_txo().unwrap(), monitor) {
46864686
let mut res = handle_monitor_err!(self, e, chan, RAACommitmentOrder::RevokeAndACKFirst, channel_ready.is_some(), OPTIONALLY_RESEND_FUNDING_LOCKED);
@@ -4716,7 +4716,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
47164716
return Err(MsgHandleErrInternal::send_err_msg_no_close("Got a message for a channel from the wrong node!".to_owned(), msg.channel_id));
47174717
}
47184718
let announcement_sigs_opt = try_chan_entry!(self, chan.get_mut().channel_ready(&msg, self.get_our_node_id(),
4719-
self.genesis_hash.clone(), &self.best_block.read().unwrap(), &self.logger), channel_state, chan);
4719+
self.genesis_hash.clone(), &self.best_block.read().unwrap(), &self.logger), chan);
47204720
if let Some(announcement_sigs) = announcement_sigs_opt {
47214721
log_trace!(self.logger, "Sending announcement_signatures for channel {}", log_bytes!(chan.get().channel_id()));
47224722
channel_state.pending_msg_events.push(events::MessageSendEvent::SendAnnouncementSignatures {
@@ -4761,7 +4761,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
47614761
if chan_entry.get().sent_shutdown() { " after we initiated shutdown" } else { "" });
47624762
}
47634763

4764-
let (shutdown, monitor_update, htlcs) = try_chan_entry!(self, chan_entry.get_mut().shutdown(&self.keys_manager, &their_features, &msg), channel_state, chan_entry);
4764+
let (shutdown, monitor_update, htlcs) = try_chan_entry!(self, chan_entry.get_mut().shutdown(&self.keys_manager, &their_features, &msg), chan_entry);
47654765
dropped_htlcs = htlcs;
47664766

47674767
// Update the monitor with the shutdown script if necessary.
@@ -4770,7 +4770,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
47704770
let (result, is_permanent) =
47714771
handle_monitor_err!(self, e, chan_entry.get_mut(), RAACommitmentOrder::CommitmentFirst, chan_entry.key(), NO_UPDATE);
47724772
if is_permanent {
4773-
remove_channel!(self, channel_state, chan_entry);
4773+
remove_channel!(self, chan_entry);
47744774
break result;
47754775
}
47764776
}
@@ -4806,7 +4806,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
48064806
if chan_entry.get().get_counterparty_node_id() != *counterparty_node_id {
48074807
return Err(MsgHandleErrInternal::send_err_msg_no_close("Got a message for a channel from the wrong node!".to_owned(), msg.channel_id));
48084808
}
4809-
let (closing_signed, tx) = try_chan_entry!(self, chan_entry.get_mut().closing_signed(&self.fee_estimator, &msg), channel_state, chan_entry);
4809+
let (closing_signed, tx) = try_chan_entry!(self, chan_entry.get_mut().closing_signed(&self.fee_estimator, &msg), chan_entry);
48104810
if let Some(msg) = closing_signed {
48114811
channel_state.pending_msg_events.push(events::MessageSendEvent::SendClosingSigned {
48124812
node_id: counterparty_node_id.clone(),
@@ -4819,7 +4819,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
48194819
// also implies there are no pending HTLCs left on the channel, so we can
48204820
// fully delete it from tracking (the channel monitor is still around to
48214821
// watch for old state broadcasts)!
4822-
(tx, Some(remove_channel!(self, channel_state, chan_entry)))
4822+
(tx, Some(remove_channel!(self, chan_entry)))
48234823
} else { (tx, None) }
48244824
},
48254825
hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel".to_owned(), msg.channel_id))
@@ -4883,7 +4883,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
48834883
_ => pending_forward_info
48844884
}
48854885
};
4886-
try_chan_entry!(self, chan.get_mut().update_add_htlc(&msg, pending_forward_info, create_pending_htlc_status, &self.logger), channel_state, chan);
4886+
try_chan_entry!(self, chan.get_mut().update_add_htlc(&msg, pending_forward_info, create_pending_htlc_status, &self.logger), chan);
48874887
},
48884888
hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel".to_owned(), msg.channel_id))
48894889
}
@@ -4899,7 +4899,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
48994899
if chan.get().get_counterparty_node_id() != *counterparty_node_id {
49004900
return Err(MsgHandleErrInternal::send_err_msg_no_close("Got a message for a channel from the wrong node!".to_owned(), msg.channel_id));
49014901
}
4902-
try_chan_entry!(self, chan.get_mut().update_fulfill_htlc(&msg), channel_state, chan)
4902+
try_chan_entry!(self, chan.get_mut().update_fulfill_htlc(&msg), chan)
49034903
},
49044904
hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel".to_owned(), msg.channel_id))
49054905
}
@@ -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_fail_htlc(&msg, HTLCFailReason::LightningError { err: msg.reason.clone() }), channel_state, chan);
4919+
try_chan_entry!(self, chan.get_mut().update_fail_htlc(&msg, HTLCFailReason::LightningError { err: msg.reason.clone() }), 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,9 +4933,9 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
49334933
}
49344934
if (msg.failure_code & 0x8000) == 0 {
49354935
let chan_err: ChannelError = ChannelError::Close("Got update_fail_malformed_htlc with BADONION not set".to_owned());
4936-
try_chan_entry!(self, Err(chan_err), channel_state, chan);
4936+
try_chan_entry!(self, Err(chan_err), chan);
49374937
}
4938-
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);
4938+
try_chan_entry!(self, chan.get_mut().update_fail_malformed_htlc(&msg, HTLCFailReason::Reason { failure_code: msg.failure_code, data: Vec::new() }), chan);
49394939
Ok(())
49404940
},
49414941
hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel".to_owned(), msg.channel_id))
@@ -4952,17 +4952,17 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
49524952
}
49534953
let (revoke_and_ack, commitment_signed, monitor_update) =
49544954
match chan.get_mut().commitment_signed(&msg, &self.logger) {
4955-
Err((None, e)) => try_chan_entry!(self, Err(e), channel_state, chan),
4955+
Err((None, e)) => try_chan_entry!(self, Err(e), chan),
49564956
Err((Some(update), e)) => {
49574957
assert!(chan.get().is_awaiting_monitor_update());
49584958
let _ = self.chain_monitor.update_channel(chan.get().get_funding_txo().unwrap(), update);
4959-
try_chan_entry!(self, Err(e), channel_state, chan);
4959+
try_chan_entry!(self, Err(e), chan);
49604960
unreachable!();
49614961
},
49624962
Ok(res) => res
49634963
};
49644964
if let Err(e) = self.chain_monitor.update_channel(chan.get().get_funding_txo().unwrap(), monitor_update) {
4965-
return_monitor_err!(self, e, channel_state, chan, RAACommitmentOrder::RevokeAndACKFirst, true, commitment_signed.is_some());
4965+
return_monitor_err!(self, e, chan, RAACommitmentOrder::RevokeAndACKFirst, true, commitment_signed.is_some());
49664966
}
49674967
channel_state.pending_msg_events.push(events::MessageSendEvent::SendRevokeAndACK {
49684968
node_id: counterparty_node_id.clone(),
@@ -5037,7 +5037,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
50375037
}
50385038
let was_frozen_for_monitor = chan.get().is_awaiting_monitor_update();
50395039
let raa_updates = break_chan_entry!(self,
5040-
chan.get_mut().revoke_and_ack(&msg, &self.logger), channel_state, chan);
5040+
chan.get_mut().revoke_and_ack(&msg, &self.logger), chan);
50415041
htlcs_to_fail = raa_updates.holding_cell_failed_htlcs;
50425042
if let Err(e) = self.chain_monitor.update_channel(chan.get().get_funding_txo().unwrap(), raa_updates.monitor_update) {
50435043
if was_frozen_for_monitor {
@@ -5096,7 +5096,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
50965096
if chan.get().get_counterparty_node_id() != *counterparty_node_id {
50975097
return Err(MsgHandleErrInternal::send_err_msg_no_close("Got a message for a channel from the wrong node!".to_owned(), msg.channel_id));
50985098
}
5099-
try_chan_entry!(self, chan.get_mut().update_fee(&self.fee_estimator, &msg), channel_state, chan);
5099+
try_chan_entry!(self, chan.get_mut().update_fee(&self.fee_estimator, &msg), chan);
51005100
},
51015101
hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel".to_owned(), msg.channel_id))
51025102
}
@@ -5118,7 +5118,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
51185118

51195119
channel_state.pending_msg_events.push(events::MessageSendEvent::BroadcastChannelAnnouncement {
51205120
msg: try_chan_entry!(self, chan.get_mut().announcement_signatures(
5121-
self.get_our_node_id(), self.genesis_hash.clone(), self.best_block.read().unwrap().height(), msg), channel_state, chan),
5121+
self.get_our_node_id(), self.genesis_hash.clone(), self.best_block.read().unwrap().height(), msg), chan),
51225122
// Note that announcement_signatures fails if the channel cannot be announced,
51235123
// so get_channel_update_for_broadcast will never fail by the time we get here.
51245124
update_msg: self.get_channel_update_for_broadcast(chan.get()).unwrap(),
@@ -5156,7 +5156,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
51565156
if were_node_one == msg_from_node_one {
51575157
return Ok(NotifyOption::SkipPersist);
51585158
} else {
5159-
try_chan_entry!(self, chan.get_mut().channel_update(&msg), channel_state, chan);
5159+
try_chan_entry!(self, chan.get_mut().channel_update(&msg), chan);
51605160
}
51615161
},
51625162
hash_map::Entry::Vacant(_) => unreachable!()
@@ -5181,7 +5181,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
51815181
// add-HTLCs on disconnect, we may be handed HTLCs to fail backwards here.
51825182
let responses = try_chan_entry!(self, chan.get_mut().channel_reestablish(
51835183
msg, &self.logger, self.our_network_pubkey.clone(), self.genesis_hash,
5184-
&*self.best_block.read().unwrap()), channel_state, chan);
5184+
&*self.best_block.read().unwrap()), chan);
51855185
let mut channel_update = None;
51865186
if let Some(msg) = responses.shutdown_msg {
51875187
channel_state.pending_msg_events.push(events::MessageSendEvent::SendShutdown {
@@ -5245,7 +5245,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
52455245
let by_id = &mut channel_state.by_id;
52465246
let pending_msg_events = &mut channel_state.pending_msg_events;
52475247
if let hash_map::Entry::Occupied(chan_entry) = by_id.entry(funding_outpoint.to_channel_id()) {
5248-
let mut chan = remove_channel!(self, channel_state, chan_entry);
5248+
let mut chan = remove_channel!(self, chan_entry);
52495249
failed_channels.push(chan.force_shutdown(false));
52505250
if let Ok(update) = self.get_channel_update_for_broadcast(&chan) {
52515251
pending_msg_events.push(events::MessageSendEvent::BroadcastChannelUpdate {

0 commit comments

Comments
 (0)