Skip to content

Commit da7ac4b

Browse files
committed
Backfill existing network graph into the DB on startup
In some cases due to ill-timed shutdown its possible for a message or two to slip by and not be persisted. This leaves missing gossip which we should really just put in the DB on startup.
1 parent dba3985 commit da7ac4b

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

src/lib.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use crate::lookup::DeltaSet;
2828
use crate::persistence::GossipPersister;
2929
use crate::serialization::{MutatedNodeProperties, NodeSerializationStrategy, SerializationSet, UpdateSerialization};
3030
use crate::snapshot::Snapshotter;
31-
use crate::types::RGSSLogger;
31+
use crate::types::{RGSSLogger, GossipMessage};
3232

3333
mod downloader;
3434
mod tracking;
@@ -105,12 +105,31 @@ impl<L: Deref + Clone + Send + Sync + 'static> RapidSyncProcessor<L> where L::Ta
105105
if config::DOWNLOAD_NEW_GOSSIP {
106106
let (mut persister, persistence_sender) =
107107
GossipPersister::new(self.network_graph.clone(), self.logger.clone()).await;
108+
log_info!(self.logger, "Starting gossip db persistence listener");
109+
tokio::spawn(async move { persister.persist_gossip().await; });
110+
111+
{
112+
log_info!(self.logger, "Backfilling latest gossip from cached network graph…");
113+
let graph = self.network_graph.read_only();
114+
for (_, chan) in graph.channels().unordered_iter() {
115+
if let Some(announcement) = &chan.announcement_message {
116+
if let Some(funding) = chan.capacity_sats {
117+
let gossip_msg = GossipMessage::ChannelAnnouncement(announcement.clone(), funding, None);
118+
persistence_sender.send(gossip_msg).await.unwrap();
119+
}
120+
}
121+
if let Some(update) = chan.one_to_two.as_ref().map(|i| i.last_update_message.as_ref()).flatten() {
122+
persistence_sender.send(GossipMessage::ChannelUpdate(update.clone(), None)).await.unwrap();
123+
}
124+
if let Some(update) = chan.two_to_one.as_ref().map(|i| i.last_update_message.as_ref()).flatten() {
125+
persistence_sender.send(GossipMessage::ChannelUpdate(update.clone(), None)).await.unwrap();
126+
}
127+
}
128+
}
108129

109130
log_info!(self.logger, "Starting gossip download");
110131
tokio::spawn(tracking::download_gossip(persistence_sender, sync_completion_sender,
111132
Arc::clone(&self.network_graph), self.logger.clone()));
112-
log_info!(self.logger, "Starting gossip db persistence listener");
113-
tokio::spawn(async move { persister.persist_gossip().await; });
114133
} else {
115134
sync_completion_sender.send(()).await.unwrap();
116135
}

0 commit comments

Comments
 (0)