@@ -892,7 +892,7 @@ pub(super) struct PeerState<SP: Deref> where SP::Target: SignerProvider {
892
892
/// The peer is currently connected (i.e. we've seen a
893
893
/// [`ChannelMessageHandler::peer_connected`] and no corresponding
894
894
/// [`ChannelMessageHandler::peer_disconnected`].
895
- is_connected: bool,
895
+ pub is_connected: bool,
896
896
}
897
897
898
898
impl <SP: Deref> PeerState<SP> where SP::Target: SignerProvider {
@@ -1392,8 +1392,7 @@ where
1392
1392
1393
1393
pending_offers_messages: Mutex<Vec<PendingOnionMessage<OffersMessage>>>,
1394
1394
1395
- /// Tracks the channel_update message that were not broadcasted because
1396
- /// we were not connected to any peers.
1395
+ /// Tracks the message events that are to be broadcasted when we are connected to some peer.
1397
1396
pending_broadcast_messages: Mutex<Vec<MessageSendEvent>>,
1398
1397
1399
1398
entropy_source: ES,
@@ -1980,7 +1979,8 @@ macro_rules! handle_error {
1980
1979
match $internal {
1981
1980
Ok(msg) => Ok(msg),
1982
1981
Err(MsgHandleErrInternal { err, shutdown_finish, .. }) => {
1983
- let mut msg_events = Vec::with_capacity(2);
1982
+ let mut msg_event = None;
1983
+ let mut broadcast_event = None;
1984
1984
1985
1985
if let Some((shutdown_res, update_option)) = shutdown_finish {
1986
1986
let counterparty_node_id = shutdown_res.counterparty_node_id;
@@ -1992,7 +1992,7 @@ macro_rules! handle_error {
1992
1992
1993
1993
$self.finish_close_channel(shutdown_res);
1994
1994
if let Some(update) = update_option {
1995
- msg_events.push (events::MessageSendEvent::BroadcastChannelUpdate {
1995
+ broadcast_event = Some (events::MessageSendEvent::BroadcastChannelUpdate {
1996
1996
msg: update
1997
1997
});
1998
1998
}
@@ -2002,17 +2002,22 @@ macro_rules! handle_error {
2002
2002
2003
2003
if let msgs::ErrorAction::IgnoreError = err.action {
2004
2004
} else {
2005
- msg_events.push (events::MessageSendEvent::HandleError {
2005
+ msg_event = Some (events::MessageSendEvent::HandleError {
2006
2006
node_id: $counterparty_node_id,
2007
2007
action: err.action.clone()
2008
2008
});
2009
2009
}
2010
2010
2011
- if !msg_events.is_empty() {
2011
+ if let Some(broadcast_event) = broadcast_event {
2012
+ let mut pending_broadcast_messages = $self.pending_broadcast_messages.lock().unwrap();
2013
+ pending_broadcast_messages.push(broadcast_event);
2014
+ }
2015
+
2016
+ if let Some(msg_event) = msg_event {
2012
2017
let per_peer_state = $self.per_peer_state.read().unwrap();
2013
2018
if let Some(peer_state_mutex) = per_peer_state.get(&$counterparty_node_id) {
2014
2019
let mut peer_state = peer_state_mutex.lock().unwrap();
2015
- peer_state.pending_msg_events.append(&mut msg_events );
2020
+ peer_state.pending_msg_events.push(msg_event );
2016
2021
}
2017
2022
}
2018
2023
@@ -2963,7 +2968,7 @@ where
2963
2968
};
2964
2969
if let Some(update) = update_opt {
2965
2970
// If we have some Channel Update to broadcast, we cache it and broadcast it later.
2966
- let mut pending_broadcast_messages = self.pending_broadcast_messages.lock().unwrap();
2971
+ let pending_broadcast_messages = &mut self.pending_broadcast_messages.lock().unwrap();
2967
2972
pending_broadcast_messages.push(events::MessageSendEvent::BroadcastChannelUpdate {
2968
2973
msg: update
2969
2974
});
@@ -4042,6 +4047,7 @@ where
4042
4047
.ok_or_else(|| APIError::ChannelUnavailable { err: format!("Can't find a peer matching the passed counterparty node_id {}", counterparty_node_id) })?;
4043
4048
let mut peer_state_lock = peer_state_mutex.lock().unwrap();
4044
4049
let peer_state = &mut *peer_state_lock;
4050
+
4045
4051
for channel_id in channel_ids {
4046
4052
if !peer_state.has_channel(channel_id) {
4047
4053
return Err(APIError::ChannelUnavailable {
@@ -4058,7 +4064,8 @@ where
4058
4064
}
4059
4065
if let ChannelPhase::Funded(channel) = channel_phase {
4060
4066
if let Ok(msg) = self.get_channel_update_for_broadcast(channel) {
4061
- peer_state.pending_msg_events.push(events::MessageSendEvent::BroadcastChannelUpdate { msg });
4067
+ let pending_broadcast_messages = &mut self.pending_broadcast_messages.lock().unwrap();
4068
+ pending_broadcast_messages.push(events::MessageSendEvent::BroadcastChannelUpdate { msg });
4062
4069
} else if let Ok(msg) = self.get_channel_update_for_unicast(channel) {
4063
4070
peer_state.pending_msg_events.push(events::MessageSendEvent::SendChannelUpdate {
4064
4071
node_id: channel.context.get_counterparty_node_id(),
@@ -4968,7 +4975,8 @@ where
4968
4975
if n >= DISABLE_GOSSIP_TICKS {
4969
4976
chan.set_channel_update_status(ChannelUpdateStatus::Disabled);
4970
4977
if let Ok(update) = self.get_channel_update_for_broadcast(&chan) {
4971
- pending_msg_events.push(events::MessageSendEvent::BroadcastChannelUpdate {
4978
+ let pending_broadcast_messages = &mut self.pending_broadcast_messages.lock().unwrap();
4979
+ pending_broadcast_messages.push(events::MessageSendEvent::BroadcastChannelUpdate {
4972
4980
msg: update
4973
4981
});
4974
4982
}
@@ -4982,7 +4990,8 @@ where
4982
4990
if n >= ENABLE_GOSSIP_TICKS {
4983
4991
chan.set_channel_update_status(ChannelUpdateStatus::Enabled);
4984
4992
if let Ok(update) = self.get_channel_update_for_broadcast(&chan) {
4985
- pending_msg_events.push(events::MessageSendEvent::BroadcastChannelUpdate {
4993
+ let pending_broadcast_messages = &mut self.pending_broadcast_messages.lock().unwrap();
4994
+ pending_broadcast_messages.push(events::MessageSendEvent::BroadcastChannelUpdate {
4986
4995
msg: update
4987
4996
});
4988
4997
}
@@ -6641,9 +6650,8 @@ where
6641
6650
}
6642
6651
if let Some(ChannelPhase::Funded(chan)) = chan_option {
6643
6652
if let Ok(update) = self.get_channel_update_for_broadcast(&chan) {
6644
- let mut peer_state_lock = peer_state_mutex.lock().unwrap();
6645
- let peer_state = &mut *peer_state_lock;
6646
- peer_state.pending_msg_events.push(events::MessageSendEvent::BroadcastChannelUpdate {
6653
+ let pending_broadcast_messages = &mut self.pending_broadcast_messages.lock().unwrap();
6654
+ pending_broadcast_messages.push(events::MessageSendEvent::BroadcastChannelUpdate {
6647
6655
msg: update
6648
6656
});
6649
6657
}
@@ -7303,7 +7311,8 @@ where
7303
7311
if let ChannelPhase::Funded(mut chan) = remove_channel_phase!(self, chan_phase_entry) {
7304
7312
failed_channels.push(chan.context.force_shutdown(false, ClosureReason::HolderForceClosed));
7305
7313
if let Ok(update) = self.get_channel_update_for_broadcast(&chan) {
7306
- pending_msg_events.push(events::MessageSendEvent::BroadcastChannelUpdate {
7314
+ let pending_broadcast_messages = &mut self.pending_broadcast_messages.lock().unwrap();
7315
+ pending_broadcast_messages.push(events::MessageSendEvent::BroadcastChannelUpdate {
7307
7316
msg: update
7308
7317
});
7309
7318
}
@@ -7488,7 +7497,8 @@ where
7488
7497
// We're done with this channel. We got a closing_signed and sent back
7489
7498
// a closing_signed with a closing transaction to broadcast.
7490
7499
if let Ok(update) = self.get_channel_update_for_broadcast(&chan) {
7491
- pending_msg_events.push(events::MessageSendEvent::BroadcastChannelUpdate {
7500
+ let pending_broadcast_messages = &mut self.pending_broadcast_messages.lock().unwrap();
7501
+ pending_broadcast_messages.push(events::MessageSendEvent::BroadcastChannelUpdate {
7492
7502
msg: update
7493
7503
});
7494
7504
}
@@ -8450,6 +8460,7 @@ where
8450
8460
let mut peer_state_lock = peer_state_mutex.lock().unwrap();
8451
8461
let peer_state = &mut *peer_state_lock;
8452
8462
let pending_msg_events = &mut peer_state.pending_msg_events;
8463
+
8453
8464
peer_state.channel_by_id.retain(|_, phase| {
8454
8465
match phase {
8455
8466
// Retain unfunded channels.
@@ -8522,7 +8533,8 @@ where
8522
8533
let reason_message = format!("{}", reason);
8523
8534
failed_channels.push(channel.context.force_shutdown(true, reason));
8524
8535
if let Ok(update) = self.get_channel_update_for_broadcast(&channel) {
8525
- pending_msg_events.push(events::MessageSendEvent::BroadcastChannelUpdate {
8536
+ let pending_broadcast_messages = &mut self.pending_broadcast_messages.lock().unwrap();
8537
+ pending_broadcast_messages.push(events::MessageSendEvent::BroadcastChannelUpdate {
8526
8538
msg: update
8527
8539
});
8528
8540
}
@@ -8969,7 +8981,9 @@ where
8969
8981
// Gossip
8970
8982
&events::MessageSendEvent::SendChannelAnnouncement { .. } => false,
8971
8983
&events::MessageSendEvent::BroadcastChannelAnnouncement { .. } => true,
8972
- &events::MessageSendEvent::BroadcastChannelUpdate { .. } => true,
8984
+ // [`ChannelManager::pending_broadcast_events`] holds the [`BroadcastChannelUpdate`]
8985
+ // This check here is to ensure exhaustivity.
8986
+ &events::MessageSendEvent::BroadcastChannelUpdate { .. } => false,
8973
8987
&events::MessageSendEvent::BroadcastNodeAnnouncement { .. } => true,
8974
8988
&events::MessageSendEvent::SendChannelUpdate { .. } => false,
8975
8989
&events::MessageSendEvent::SendChannelRangeQuery { .. } => false,
@@ -11880,7 +11894,6 @@ mod tests {
11880
11894
assert_eq!(nodes_0_lock.len(), 1);
11881
11895
assert!(nodes_0_lock.contains_key(&funding_output));
11882
11896
}
11883
-
11884
11897
{
11885
11898
// At this stage, `nodes[1]` has proposed a fee for the closing transaction in the
11886
11899
// `handle_closing_signed` call above. As `nodes[1]` has not yet received the signature
0 commit comments