From: Andrei Date: Wed, 8 Feb 2023 00:00:00 +0000 (+0000) Subject: Configure network X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=694b11978177600415c2183f1eeac73471b07f62;p=rapid-gossip-sync-server Configure network --- diff --git a/src/config.rs b/src/config.rs index 444d54c..475d63a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -5,6 +5,7 @@ use std::env; use std::io::Cursor; use std::net::{SocketAddr, ToSocketAddrs}; +use bitcoin::Network; use bitcoin::hashes::hex::FromHex; use bitcoin::secp256k1::PublicKey; use futures::stream::{FuturesUnordered, StreamExt}; @@ -17,6 +18,17 @@ pub(crate) const SCHEMA_VERSION: i32 = 8; pub(crate) const SNAPSHOT_CALCULATION_INTERVAL: u32 = 3600 * 24; // every 24 hours, in seconds pub(crate) const DOWNLOAD_NEW_GOSSIP: bool = true; +pub(crate) fn network() -> Network { + let network = env::var("RAPID_GOSSIP_SYNC_SERVER_NETWORK").unwrap_or("Bitcoin".to_string()); + match network.as_str() { + "Bitcoin" => Network::Bitcoin, + "Testnet" => Network::Testnet, + "Signet" => Network::Signet, + "Regtest" => Network::Regtest, + _ => panic!("Invalid network"), + } +} + pub(crate) fn network_graph_cache_path() -> &'static str { "./res/network_graph.bin" } diff --git a/src/lib.rs b/src/lib.rs index cc5a350..25ce1a2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,7 +16,6 @@ use std::io::BufReader; use std::sync::Arc; use bitcoin::blockdata::constants::genesis_block; -use bitcoin::Network; use bitcoin::secp256k1::PublicKey; use lightning::routing::gossip::NetworkGraph; use lightning::util::ser::{ReadableArgs, Writeable}; @@ -54,6 +53,7 @@ pub struct SerializedResponse { impl RapidSyncProcessor { pub fn new() -> Self { + let network = config::network(); let logger = TestLogger::new(); let network_graph = if let Ok(file) = File::open(&config::network_graph_cache_path()) { println!("Initializing from cached network graph…"); @@ -65,10 +65,10 @@ impl RapidSyncProcessor { network_graph } else { println!("Initialization from cached network graph failed: {}", network_graph_result.err().unwrap()); - NetworkGraph::new(genesis_block(Network::Bitcoin).header.block_hash(), logger) + NetworkGraph::new(genesis_block(network).header.block_hash(), logger) } } else { - NetworkGraph::new(genesis_block(Network::Bitcoin).header.block_hash(), logger) + NetworkGraph::new(genesis_block(network).header.block_hash(), logger) }; let arc_network_graph = Arc::new(network_graph); Self {