Skip to content

Commit

Permalink
Merge pull request fedimint#4858 from maan2003/ma/jj-zztmkurpwuol
Browse files Browse the repository at this point in the history
feat: gateway filter for update_gateway_cache_continuously
  • Loading branch information
maan2003 authored Apr 8, 2024
2 parents 2643cbc + 41daa1c commit 9a2afb3
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions modules/fedimint-ln-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ use fedimint_ln_common::{
LightningGatewayAnnouncement, LightningGatewayRegistration, LightningInput,
LightningModuleTypes, LightningOutput, LightningOutputV0,
};
use futures::{FutureExt, StreamExt};
use futures::{Future, FutureExt, StreamExt};
use incoming::IncomingSmError;
use lightning_invoice::{
Bolt11Invoice, Currency, InvoiceBuilder, PaymentSecret, RouteHint, RouteHintHop, RoutingFees,
Expand Down Expand Up @@ -937,16 +937,23 @@ impl LightningClientModule {

/// Continuously update the gateway cache whenever a gateway expires.
///
/// The gateways returned by `gateway_filters` are checked for expiry.
/// Client integrators are expected to call this function in a spawned task.
pub async fn update_gateway_cache_continuously(&self) -> ! {
pub async fn update_gateway_cache_continuously<Fut>(
&self,
gateways_filter: impl Fn(Vec<LightningGatewayAnnouncement>) -> Fut,
) -> !
where
Fut: Future<Output = Vec<LightningGatewayAnnouncement>>,
{
let mut first_time = true;

const ABOUT_TO_EXPIRE: Duration = Duration::from_secs(30);
const EMPTY_GATEWAY_SLEEP: Duration = Duration::from_secs(10 * 60);
loop {
let gateways = self.list_gateways().await;
// TODO: filter gateways by vetted
let sleep_time = gateways
let sleep_time = gateways_filter(gateways)
.await
.into_iter()
.map(|x| x.ttl.saturating_sub(ABOUT_TO_EXPIRE))
.min()
Expand Down

0 comments on commit 9a2afb3

Please sign in to comment.