Skip to content

Commit 1e43fe5

Browse files
committed
Refactor channel map update macros for use with ChannelContext
1 parent 30bb796 commit 1e43fe5

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1614,10 +1614,10 @@ macro_rules! handle_error {
16141614
}
16151615

16161616
macro_rules! update_maps_on_chan_removal {
1617-
($self: expr, $channel: expr) => {{
1618-
$self.id_to_peer.lock().unwrap().remove(&$channel.context.channel_id());
1617+
($self: expr, $channel_context: expr) => {{
1618+
$self.id_to_peer.lock().unwrap().remove(&$channel_context.channel_id());
16191619
let mut short_to_chan_info = $self.short_to_chan_info.write().unwrap();
1620-
if let Some(short_id) = $channel.context.get_short_channel_id() {
1620+
if let Some(short_id) = $channel_context.get_short_channel_id() {
16211621
short_to_chan_info.remove(&short_id);
16221622
} else {
16231623
// If the channel was never confirmed on-chain prior to its closure, remove the
@@ -1626,10 +1626,10 @@ macro_rules! update_maps_on_chan_removal {
16261626
// also don't want a counterparty to be able to trivially cause a memory leak by simply
16271627
// opening a million channels with us which are closed before we ever reach the funding
16281628
// stage.
1629-
let alias_removed = $self.outbound_scid_aliases.lock().unwrap().remove(&$channel.context.outbound_scid_alias());
1629+
let alias_removed = $self.outbound_scid_aliases.lock().unwrap().remove(&$channel_context.outbound_scid_alias());
16301630
debug_assert!(alias_removed);
16311631
}
1632-
short_to_chan_info.remove(&$channel.context.outbound_scid_alias());
1632+
short_to_chan_info.remove(&$channel_context.outbound_scid_alias());
16331633
}}
16341634
}
16351635

@@ -1645,7 +1645,7 @@ macro_rules! convert_chan_err {
16451645
},
16461646
ChannelError::Close(msg) => {
16471647
log_error!($self.logger, "Closing channel {} due to close-required error: {}", log_bytes!($channel_id[..]), msg);
1648-
update_maps_on_chan_removal!($self, $channel);
1648+
update_maps_on_chan_removal!($self, &$channel.context);
16491649
let shutdown_res = $channel.context.force_shutdown(true);
16501650
(true, MsgHandleErrInternal::from_finish_shutdown(msg, *$channel_id, $channel.context.get_user_id(),
16511651
shutdown_res, $self.get_channel_update_for_broadcast(&$channel).ok()))
@@ -1688,7 +1688,7 @@ macro_rules! remove_channel {
16881688
($self: expr, $entry: expr) => {
16891689
{
16901690
let channel = $entry.remove_entry().1;
1691-
update_maps_on_chan_removal!($self, channel);
1691+
update_maps_on_chan_removal!($self, &channel.context);
16921692
channel
16931693
}
16941694
}
@@ -1810,7 +1810,7 @@ macro_rules! handle_new_monitor_update {
18101810
ChannelMonitorUpdateStatus::PermanentFailure => {
18111811
log_error!($self.logger, "Closing channel {} due to monitor update ChannelMonitorUpdateStatus::PermanentFailure",
18121812
log_bytes!($chan.context.channel_id()[..]));
1813-
update_maps_on_chan_removal!($self, $chan);
1813+
update_maps_on_chan_removal!($self, &$chan.context);
18141814
let res: Result<(), _> = Err(MsgHandleErrInternal::from_finish_shutdown(
18151815
"ChannelMonitor storage failure".to_owned(), $chan.context.channel_id(),
18161816
$chan.context.get_user_id(), $chan.context.force_shutdown(false),
@@ -2798,6 +2798,7 @@ where
27982798

27992799
self.get_channel_update_for_onion(short_channel_id, chan)
28002800
}
2801+
28012802
fn get_channel_update_for_onion(&self, short_channel_id: u64, chan: &Channel<<SP::Target as SignerProvider>::Signer>) -> Result<msgs::ChannelUpdate, LightningError> {
28022803
log_trace!(self.logger, "Generating channel update for channel {}", log_bytes!(chan.context.channel_id()));
28032804
let were_node_one = self.our_network_pubkey.serialize()[..] < chan.context.get_counterparty_node_id().serialize()[..];
@@ -5536,7 +5537,7 @@ where
55365537
), chan),
55375538
// Note that announcement_signatures fails if the channel cannot be announced,
55385539
// so get_channel_update_for_broadcast will never fail by the time we get here.
5539-
update_msg: Some(self.get_channel_update_for_broadcast(chan.get()).unwrap()),
5540+
update_msg: Some(self.get_channel_update_for_broadcast(&chan.get()).unwrap()),
55405541
});
55415542
},
55425543
hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close(format!("Got a message for a channel from the wrong node! No such channel for the passed counterparty_node_id {}", counterparty_node_id), msg.channel_id))
@@ -5826,7 +5827,7 @@ where
58265827

58275828
log_info!(self.logger, "Broadcasting {}", log_tx!(tx));
58285829
self.tx_broadcaster.broadcast_transactions(&[&tx]);
5829-
update_maps_on_chan_removal!(self, chan);
5830+
update_maps_on_chan_removal!(self, &chan.context);
58305831
false
58315832
} else { true }
58325833
},
@@ -6530,7 +6531,7 @@ where
65306531
}
65316532
}
65326533
} else if let Err(reason) = res {
6533-
update_maps_on_chan_removal!(self, channel);
6534+
update_maps_on_chan_removal!(self, &channel.context);
65346535
// It looks like our counterparty went on-chain or funding transaction was
65356536
// reorged out of the main chain. Close the channel.
65366537
failed_channels.push(channel.context.force_shutdown(true));
@@ -6790,7 +6791,7 @@ where
67906791
peer_state.channel_by_id.retain(|_, chan| {
67916792
chan.remove_uncommitted_htlcs_and_mark_paused(&self.logger);
67926793
if chan.is_shutdown() {
6793-
update_maps_on_chan_removal!(self, chan);
6794+
update_maps_on_chan_removal!(self, &chan.context);
67946795
self.issue_channel_close_events(&chan.context, ClosureReason::DisconnectedPeer);
67956796
return false;
67966797
}

0 commit comments

Comments
 (0)