Skip to content

Commit

Permalink
feat(barq-common): specify rapid gossip sync link based on network
Browse files Browse the repository at this point in the history
Signed-off-by: Tarek <[email protected]>
  • Loading branch information
tareknaser committed Aug 27, 2024
1 parent 5a85f95 commit 7b1b833
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
29 changes: 26 additions & 3 deletions barq-common/src/algorithms/probabilistic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use reqwest::blocking;
use lampo_common::bitcoin::secp256k1::PublicKey;
use lampo_common::conf::Network;
use lampo_common::ldk::routing::gossip::NetworkGraph as LdkNetworkGraph;
use lampo_common::ldk::routing::router::{find_route, PaymentParameters, Route, RouteParameters};
use lampo_common::ldk::routing::router::{find_route, Route, RouteParameters};
use lampo_common::ldk::routing::scoring::FixedPenaltyScorer;
use lampo_common::ldk::util::logger::Logger;
use lampo_common::utils::logger::LampoLogger;
Expand Down Expand Up @@ -91,7 +91,17 @@ where

// Download the snapshot data
// For more information, see: https://docs.rs/lightning-rapid-gossip-sync/latest/lightning_rapid_gossip_sync/#getting-started
let response = blocking::get("https://rapidsync.lightningdevkit.org/snapshot/0")?;
let rapid_gossip_sync_url = match network {
Network::Bitcoin => "https://rapidsync.lightningdevkit.org/snapshot/0",
Network::Testnet => "https://rapidsync.lightningdevkit.org/testnet/snapshot/0",
_ => {
return Err(anyhow::anyhow!(
"Rapid gossip sync is not supported for the given network: {:?}. Please use either Bitcoin or Testnet",
network
))
}
};
let response = blocking::get(rapid_gossip_sync_url)?;
let snapshot_contents = response.bytes()?;

rapid_sync
Expand Down Expand Up @@ -166,7 +176,7 @@ mod tests {

struct DummyLogger {}
impl Logger for DummyLogger {
fn log(&self, record: Record) {
fn log(&self, _record: Record) {
return;
}
}
Expand All @@ -184,6 +194,19 @@ mod tests {
);
}

#[test]
fn test_rapid_gossip_sync_network_testnet() {
let strategy = LDKRoutingStrategy::new(Arc::new(DummyLogger {}));
let network = Network::Testnet;
let result = strategy.rapid_gossip_sync_network(network);

assert!(
result.is_ok(),
"Failed to create a network graph using rapid gossip sync: {:?}",
result.err()
);
}

#[test]
fn test_rapid_gossip_sync_network_not_empty() {
let strategy = LDKRoutingStrategy::new(Arc::new(DummyLogger {}));
Expand Down
2 changes: 0 additions & 2 deletions barq-common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![allow(unused)]

pub mod algorithms;
pub mod graph;
pub mod strategy;
Expand Down
2 changes: 0 additions & 2 deletions barq-plugin/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![allow(unused)]

use anyhow::Result;

mod methods;
Expand Down

0 comments on commit 7b1b833

Please sign in to comment.