Skip to content

Commit 00e9496

Browse files
committed
Added persistence for the pending_broadcast_messages
1 parent 648a214 commit 00e9496

File tree

1 file changed

+31
-22
lines changed

1 file changed

+31
-22
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2844,33 +2844,40 @@ where
28442844
}
28452845
};
28462846
if let Some(update) = update_opt {
2847-
// Try to send the `BroadcastChannelUpdate` to the peer we just force-closed on, but if
2848-
// not try to broadcast it via whatever peer we have.
2849-
let brodcast_message_evt = events::MessageSendEvent::BroadcastChannelUpdate {
2850-
msg: update
2851-
};
2847+
PersistenceNotifierGuard::optionally_notify(self, || {
2848+
let mut should_persist = NotifyOption::SkipPersistNoEvents;
28522849

2853-
let per_peer_state = self.per_peer_state.read().unwrap();
2850+
// Try to send the `BroadcastChannelUpdate` to the peer we just force-closed on, but if
2851+
// not try to broadcast it via whatever peer we have.
2852+
let brodcast_message_evt = events::MessageSendEvent::BroadcastChannelUpdate {
2853+
msg: update.clone()
2854+
};
28542855

2855-
// Attempt to get the a_peer_state_mutex for the peer we disconnected on.
2856-
let a_peer_state_mutex_opt = per_peer_state.get(peer_node_id).map(|v| v);
2856+
let per_peer_state = self.per_peer_state.read().unwrap();
28572857

2858-
// If the particular peer is not present. Select any random peer from the ones we are connected on.
2859-
let a_peer_state_mutex_opt = a_peer_state_mutex_opt.or_else(|| per_peer_state.iter().next().map(|(_, v)| v));
2858+
// Attempt to get the a_peer_state_mutex for the peer we disconnected on.
2859+
let a_peer_state_mutex_opt = per_peer_state.get(peer_node_id).map(|v| v);
28602860

2861-
match a_peer_state_mutex_opt {
2862-
Some(a_peer_state_mutex) => {
2863-
let mut a_peer_state = a_peer_state_mutex.lock().unwrap();
2864-
a_peer_state.pending_msg_events.push(brodcast_message_evt);
2865-
}
2866-
// If we are connected to no peer.
2867-
None => {
2868-
let mut pending_broadcast_messages = self.pending_broadcast_messages.lock().unwrap();
2869-
pending_broadcast_messages.push(brodcast_message_evt);
2870-
log_info!(self.logger, "Not able to broadcast channel_update of force-closed channel right now.
2871-
Will try rebroadcasting later.");
2861+
// If the particular peer is not present. Select any random peer from the ones we are connected on.
2862+
let a_peer_state_mutex_opt = a_peer_state_mutex_opt.or_else(|| per_peer_state.iter().next().map(|(_, v)| v));
2863+
2864+
match a_peer_state_mutex_opt {
2865+
Some(a_peer_state_mutex) => {
2866+
let mut a_peer_state = a_peer_state_mutex.lock().unwrap();
2867+
a_peer_state.pending_msg_events.push(brodcast_message_evt);
2868+
}
2869+
// If we are connected to no peer.
2870+
None => {
2871+
let mut pending_broadcast_messages = self.pending_broadcast_messages.lock().unwrap();
2872+
pending_broadcast_messages.push(brodcast_message_evt);
2873+
log_info!(self.logger, "Not able to broadcast channel_update of force-closed channel right now.
2874+
Will try rebroadcasting later.");
2875+
should_persist = NotifyOption::DoPersist;
2876+
}
28722877
}
2873-
}
2878+
should_persist
2879+
});
2880+
28742881
}
28752882

28762883
Ok(counterparty_node_id)
@@ -4949,6 +4956,8 @@ where
49494956
a_peer_state.pending_msg_events.extend(broadcast_evts.iter().cloned());
49504957

49514958
self.pending_broadcast_messages.lock().unwrap().clear();
4959+
4960+
should_persist = NotifyOption::DoPersist;
49524961
}
49534962
}
49544963

0 commit comments

Comments
 (0)