Skip to content

Commit 728e87b

Browse files
committed
Cache and Broadcast channel update later
- Cache the force-close channel update message, and broadcast them later. - Update get_and_clear_pending_msg_events to broadcast the pending_broadcast_events along with other messages.
1 parent 40574d0 commit 728e87b

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,6 +1381,10 @@ where
13811381

13821382
pending_offers_messages: Mutex<Vec<PendingOnionMessage<OffersMessage>>>,
13831383

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+
13841388
entropy_source: ES,
13851389
node_signer: NS,
13861390
signer_provider: SP,
@@ -2455,6 +2459,7 @@ where
24552459
funding_batch_states: Mutex::new(BTreeMap::new()),
24562460

24572461
pending_offers_messages: Mutex::new(Vec::new()),
2462+
pending_broadcast_messages: Mutex::new(Vec::new()),
24582463

24592464
entropy_source,
24602465
node_signer,
@@ -2946,17 +2951,12 @@ where
29462951
}
29472952
};
29482953
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_trace!(self.logger, "Caching the channel_updates of force-closed channel. We will them broadcast later.");
29602960
}
29612961

29622962
Ok(counterparty_node_id)
@@ -8203,6 +8203,8 @@ where
82038203
pending_events.append(&mut peer_state.pending_msg_events);
82048204
}
82058205
}
8206+
let mut broadcast_msgs = self.pending_broadcast_messages.lock().unwrap();
8207+
pending_events.append(&mut broadcast_msgs);
82068208

82078209
if !pending_events.is_empty() {
82088210
events.replace(pending_events);
@@ -11099,6 +11101,8 @@ where
1109911101

1110011102
pending_offers_messages: Mutex::new(Vec::new()),
1110111103

11104+
pending_broadcast_messages: Mutex::new(Vec::new()),
11105+
1110211106
entropy_source: args.entropy_source,
1110311107
node_signer: args.node_signer,
1110411108
signer_provider: args.signer_provider,

0 commit comments

Comments
 (0)