Create test-aware db env vars.
[rapid-gossip-sync-server] / src / config.rs
index b1c7ba283e9f73fe7ac732cd76680891fb20a14d..0655aa7d48f9013f2d6171d06e4c83eeb1d99bfa 100644 (file)
@@ -16,12 +16,17 @@ use lightning_block_sync::http::HttpEndpoint;
 use tokio_postgres::Config;
 
 pub(crate) const SCHEMA_VERSION: i32 = 12;
-pub(crate) const SYMLINK_GRANULARITY_INTERVAL: u32 = 3600 * 3;
+pub(crate) const SYMLINK_GRANULARITY_INTERVAL: u32 = 3600 * 3; // three hours
+pub(crate) const MAX_SNAPSHOT_SCOPE: u32 = 3600 * 24 * 21; // three weeks
 // generate symlinks based on a 3-hour-granularity
 /// If the last update in either direction was more than six days ago, we send a reminder
 /// That reminder may be either in the form of a channel announcement, or in the form of empty
 /// updates in both directions.
 pub(crate) const CHANNEL_REMINDER_AGE: Duration = Duration::from_secs(6 * 24 * 60 * 60);
+/// The number of successful peer connections to await prior to continuing to gossip storage.
+/// The application will still work if the number of specified peers is lower, as long as there is
+/// at least one successful peer connection, but it may result in long startup times.
+pub(crate) const CONNECTED_PEER_ASSERTION_LIMIT: usize = 5;
 pub(crate) const DOWNLOAD_NEW_GOSSIP: bool = true;
 
 pub(crate) fn snapshot_generation_interval() -> u32 {
@@ -69,13 +74,19 @@ pub(crate) fn cache_path() -> String {
 
 pub(crate) fn db_connection_config() -> Config {
        let mut config = Config::new();
-       let host = env::var("RAPID_GOSSIP_SYNC_SERVER_DB_HOST").unwrap_or("localhost".to_string());
-       let user = env::var("RAPID_GOSSIP_SYNC_SERVER_DB_USER").unwrap_or("alice".to_string());
-       let db = env::var("RAPID_GOSSIP_SYNC_SERVER_DB_NAME").unwrap_or("ln_graph_sync".to_string());
+       let env_name_prefix = if cfg!(test) {
+               "RAPID_GOSSIP_TEST_DB"
+       } else {
+               "RAPID_GOSSIP_SYNC_SERVER_DB"
+       };
+
+       let host = env::var(format!("{}{}", env_name_prefix, "_HOST")).unwrap_or("localhost".to_string());
+       let user = env::var(format!("{}{}", env_name_prefix, "_USER")).unwrap_or("alice".to_string());
+       let db = env::var(format!("{}{}", env_name_prefix, "_NAME")).unwrap_or("ln_graph_sync".to_string());
        config.host(&host);
        config.user(&user);
        config.dbname(&db);
-       if let Ok(password) = env::var("RAPID_GOSSIP_SYNC_SERVER_DB_PASSWORD") {
+       if let Ok(password) = env::var(format!("{}{}", env_name_prefix, "_PASSWORD")) {
                config.password(&password);
        }
        config