use lightning::routing::gossip::NetworkGraph;
use lightning::util::logger::Logger;
use lightning::util::ser::Writeable;
+use tokio::runtime::Runtime;
use tokio::sync::{mpsc, Mutex, Semaphore};
use crate::config;
pub(crate) struct GossipPersister<L: Deref> where L::Target: Logger {
gossip_persistence_receiver: mpsc::Receiver<GossipMessage>,
network_graph: Arc<NetworkGraph<L>>,
+ tokio_runtime: Runtime,
logger: L
}
pub fn new(network_graph: Arc<NetworkGraph<L>>, logger: L) -> (Self, mpsc::Sender<GossipMessage>) {
let (gossip_persistence_sender, gossip_persistence_receiver) =
mpsc::channel::<GossipMessage>(100);
+ let runtime = Runtime::new().unwrap();
(GossipPersister {
gossip_persistence_receiver,
network_graph,
+ tokio_runtime: runtime,
logger
}, gossip_persistence_sender)
}
let mut announcement_signed = Vec::new();
announcement.write(&mut announcement_signed).unwrap();
- let _task = tokio::spawn(async move {
+ let _task = self.tokio_runtime.spawn(async move {
let client;
{
let mut connections_set = connections_cache_ref.lock().await;
// this may not be used outside test cfg
let _seen_timestamp = seen_override.unwrap_or(timestamp as u32) as f64;
- let _task = tokio::spawn(async move {
+ let _task = self.tokio_runtime.spawn(async move {
let client;
{
let mut connections_set = connections_cache_ref.lock().await;
});
}
+#[tokio::test]
+async fn test_persistence_runtime() {
+ let _sanitizer = SchemaSanitizer::new();
+ let logger = Arc::new(TestLogger::new());
+ let network_graph = NetworkGraph::new(Network::Bitcoin, logger.clone());
+ let network_graph_arc = Arc::new(network_graph);
+ let (_persister, _receiver) = GossipPersister::new(network_graph_arc.clone(), logger.clone());
+
+ tokio::task::spawn_blocking(move || {
+ drop(_persister);
+ }).await.unwrap();
+
+ clean_test_db().await;
+}
+
+
#[tokio::test]
async fn test_trivial_setup() {
let _sanitizer = SchemaSanitizer::new();
println!("last update b: {}", last_update_seen_b);
assert_eq!(last_update_seen_a, update_result - CLIENT_BACKDATE_INTERVAL);
assert_eq!(last_update_seen_b, update_result - CLIENT_BACKDATE_INTERVAL);
+
+ tokio::task::spawn_blocking(move || {
+ drop(persister);
+ }).await.unwrap();
}
/// If a channel has only seen updates in one direction, it should not be announced
let client_channel_count = channels.len();
assert_eq!(client_channel_count, 1);
+ tokio::task::spawn_blocking(move || {
+ drop(persister);
+ }).await.unwrap();
+
clean_test_db().await;
}
assert_eq!(serialization.update_count_full, 0);
assert_eq!(serialization.update_count_incremental, 1);
+ tokio::task::spawn_blocking(move || {
+ drop(persister);
+ }).await.unwrap();
+
clean_test_db().await;
}
drop(receiver);
persister.persist_gossip().await;
+
+ tokio::task::spawn_blocking(move || {
+ drop(persister);
+ }).await.unwrap();
}
let client_graph = NetworkGraph::new(Network::Bitcoin, logger.clone());
drop(receiver);
persister.persist_gossip().await;
+
+ tokio::task::spawn_blocking(move || {
+ drop(persister);
+ }).await.unwrap();
}
let client_graph = NetworkGraph::new(Network::Bitcoin, logger.clone());
drop(receiver);
persister.persist_gossip().await;
+
+ tokio::task::spawn_blocking(move || {
+ drop(persister);
+ }).await.unwrap();
}
let client_graph = NetworkGraph::new(Network::Bitcoin, logger.clone());
drop(receiver);
persister.persist_gossip().await;
+
+ tokio::task::spawn_blocking(move || {
+ drop(persister);
+ }).await.unwrap();
}
let client_graph = NetworkGraph::new(Network::Bitcoin, logger.clone());
drop(receiver);
persister.persist_gossip().await;
+
+ tokio::task::spawn_blocking(move || {
+ drop(persister);
+ }).await.unwrap();
}
let client_graph = NetworkGraph::new(Network::Bitcoin, logger.clone());
drop(receiver);
persister.persist_gossip().await;
+
+ tokio::task::spawn_blocking(move || {
+ drop(persister);
+ }).await.unwrap();
}
let cache_path = cache_sanitizer.cache_path();
drop(receiver);
persister.persist_gossip().await;
+
+ tokio::task::spawn_blocking(move || {
+ drop(persister);
+ }).await.unwrap();
}
// regenerate snapshots