@@ -1381,6 +1381,10 @@ where
1381
1381
1382
1382
pending_offers_messages: Mutex<Vec<PendingOnionMessage<OffersMessage>>>,
1383
1383
1384
+ /// Tracks the channel_update message that were not broadcasted because
1385
+ /// we were not connected to any peers.
1386
+ pending_broadcast_messages: Mutex<Vec<MessageSendEvent>>,
1387
+
1384
1388
entropy_source: ES,
1385
1389
node_signer: NS,
1386
1390
signer_provider: SP,
@@ -2455,6 +2459,7 @@ where
2455
2459
funding_batch_states: Mutex::new(BTreeMap::new()),
2456
2460
2457
2461
pending_offers_messages: Mutex::new(Vec::new()),
2462
+ pending_broadcast_messages: Mutex::new(Vec::new()),
2458
2463
2459
2464
entropy_source,
2460
2465
node_signer,
@@ -2946,17 +2951,12 @@ where
2946
2951
}
2947
2952
};
2948
2953
if let Some(update) = update_opt {
2949
- // Try to send the `BroadcastChannelUpdate` to the peer we just force-closed on, but if
2950
- // not try to broadcast it via whatever peer we have.
2951
- let per_peer_state = self.per_peer_state.read().unwrap();
2952
- let a_peer_state_opt = per_peer_state.get(peer_node_id)
2953
- .ok_or(per_peer_state.values().next());
2954
- if let Ok(a_peer_state_mutex) = a_peer_state_opt {
2955
- let mut a_peer_state = a_peer_state_mutex.lock().unwrap();
2956
- a_peer_state.pending_msg_events.push(events::MessageSendEvent::BroadcastChannelUpdate {
2957
- msg: update
2958
- });
2959
- }
2954
+ // If we have some Channel Update to broadcast, we cache it and broadcast it later.
2955
+ let mut pending_broadcast_messages = self.pending_broadcast_messages.lock().unwrap();
2956
+ pending_broadcast_messages.push(events::MessageSendEvent::BroadcastChannelUpdate {
2957
+ msg: update
2958
+ });
2959
+ log_info!(self.logger, "Caching the channel_updates of force-closed channel. We will them broadcast later.");
2960
2960
}
2961
2961
2962
2962
Ok(counterparty_node_id)
@@ -4915,6 +4915,7 @@ where
4915
4915
4916
4916
{
4917
4917
let per_peer_state = self.per_peer_state.read().unwrap();
4918
+
4918
4919
for (counterparty_node_id, peer_state_mutex) in per_peer_state.iter() {
4919
4920
let mut peer_state_lock = peer_state_mutex.lock().unwrap();
4920
4921
let peer_state = &mut *peer_state_lock;
@@ -8203,6 +8204,8 @@ where
8203
8204
pending_events.append(&mut peer_state.pending_msg_events);
8204
8205
}
8205
8206
}
8207
+ let mut broadcast_msgs = self.pending_broadcast_messages.lock().unwrap();
8208
+ pending_events.append(&mut broadcast_msgs);
8206
8209
8207
8210
if !pending_events.is_empty() {
8208
8211
events.replace(pending_events);
@@ -11099,6 +11102,8 @@ where
11099
11102
11100
11103
pending_offers_messages: Mutex::new(Vec::new()),
11101
11104
11105
+ pending_broadcast_messages: Mutex::new(Vec::new()),
11106
+
11102
11107
entropy_source: args.entropy_source,
11103
11108
node_signer: args.node_signer,
11104
11109
signer_provider: args.signer_provider,
0 commit comments