Create method for obtaining UTC-prepared Postgres client.
[rapid-gossip-sync-server] / src / lib.rs
index b6281bcb6836b58f7ecff75664ba6075bde8df13..550ed79ddcdac4d56f65e93e5ac94f7fa030bfa7 100644 (file)
@@ -20,6 +20,7 @@ use lightning::routing::gossip::{NetworkGraph, NodeId};
 use lightning::util::logger::Logger;
 use lightning::util::ser::{ReadableArgs, Writeable};
 use tokio::sync::mpsc;
+use tokio_postgres::{Client, NoTls};
 use crate::lookup::DeltaSet;
 
 use crate::persistence::GossipPersister;
@@ -110,6 +111,20 @@ impl<L: Deref + Clone + Send + Sync + 'static> RapidSyncProcessor<L> where L::Ta
        }
 }
 
+pub(crate) async fn connect_to_db() -> Client {
+       let connection_config = config::db_connection_config();
+       let (client, connection) = connection_config.connect(NoTls).await.unwrap();
+
+       tokio::spawn(async move {
+               if let Err(e) = connection.await {
+                       panic!("connection error: {}", e);
+               }
+       });
+
+       client.execute("set time zone UTC", &[]).await.unwrap();
+       client
+}
+
 /// This method generates a no-op blob that can be used as a delta where none exists.
 ///
 /// The primary purpose of this method is the scenario of a client retrieving and processing a
@@ -142,16 +157,10 @@ fn serialize_empty_blob(current_timestamp: u64) -> Vec<u8> {
 }
 
 async fn serialize_delta<L: Deref + Clone>(network_graph: Arc<NetworkGraph<L>>, last_sync_timestamp: u32, logger: L) -> SerializedResponse where L::Target: Logger {
-       let (client, connection) = lookup::connect_to_db().await;
+       let client = connect_to_db().await;
 
        network_graph.remove_stale_channels_and_tracking();
 
-       tokio::spawn(async move {
-               if let Err(e) = connection.await {
-                       panic!("connection error: {}", e);
-               }
-       });
-
        let mut output: Vec<u8> = vec![];
 
        // set a flag if the chain hash is prepended