Skip to content

Commit

Permalink
Update gateway cache every hour
Browse files Browse the repository at this point in the history
  • Loading branch information
benthecarman committed Mar 26, 2024
1 parent d367944 commit c986a91
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use fedimint_ln_client::LightningClientModule;
use fedimint_ln_common::LightningGateway;
use log::error;
use std::collections::HashMap;
use std::time::Duration;
use std::{path::PathBuf, sync::Arc};
use tokio::sync::RwLock;

Expand Down Expand Up @@ -95,7 +96,25 @@ pub(crate) async fn setup_multimint(
fm: Arc::new(RwLock::new(mm)),
};

Ok(Arc::new(mmw))
let mmw = Arc::new(mmw);

// spawn thread to update gateways periodically, check every hour
let mmw_clone = mmw.clone();
tokio::spawn(async move {
loop {
tokio::time::sleep(Duration::from_secs(60 * 60)).await;
let mm = mmw_clone.fm.read().await;
let clients = mm.clients.lock().await;
for (_, client) in clients.iter() {
let ln = client.get_first_module::<LightningClientModule>();
if let Err(e) = ln.update_gateway_cache(true).await {
error!("Failed to update gateway cache: {e}");
}
}
}
});

Ok(mmw)
}

pub(crate) async fn select_gateway(client: &ClientHandleArc) -> Option<LightningGateway> {
Expand Down

0 comments on commit c986a91

Please sign in to comment.