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;
}
}
+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
}
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
use lightning::ln::msgs::{ChannelAnnouncement, ChannelUpdate, UnsignedChannelAnnouncement, UnsignedChannelUpdate};
use lightning::routing::gossip::NetworkGraph;
use lightning::util::ser::Readable;
-use tokio_postgres::{Client, Connection, NoTls, Socket};
-use tokio_postgres::tls::NoTlsStream;
+use tokio_postgres::Client;
use futures::StreamExt;
use lightning::log_info;
}
}
-pub(super) async fn connect_to_db() -> (Client, Connection<Socket, NoTlsStream>) {
- let connection_config = config::db_connection_config();
- connection_config.connect(NoTls).await.unwrap()
-}
-
/// Fetch all the channel announcements that are presently in the network graph, regardless of
/// whether they had been seen before.
/// Also include all announcements for which the first update was announced
use lightning::util::logger::Logger;
use lightning::util::ser::Writeable;
use tokio::sync::mpsc;
-use tokio_postgres::NoTls;
use crate::config;
use crate::types::GossipMessage;
}
pub(crate) async fn persist_gossip(&mut self) {
- let connection_config = config::db_connection_config();
- let (mut client, connection) =
- connection_config.connect(NoTls).await.unwrap();
-
- tokio::spawn(async move {
- if let Err(e) = connection.await {
- panic!("connection error: {}", e);
- }
- });
+ let mut client = crate::connect_to_db().await;
{
// initialize the database
config::upgrade_db(cur_schema[0].get(0), &mut client).await;
}
+ let preparation = client.execute("set time zone UTC", &[]).await;
+ if let Err(preparation_error) = preparation {
+ panic!("db preparation error: {}", preparation_error);
+ }
+
let initialization = client
.execute(
// TODO: figure out a way to fix the id value without Postgres complaining about