Skip to content

Commit

Permalink
Remove gateway cache
Browse files Browse the repository at this point in the history
  • Loading branch information
benthecarman committed Mar 26, 2024
1 parent e10c423 commit d367944
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/lnurlp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub async fn lnurl_callback(

let gateway = state
.mm
.get_gateway(&federation_id)
.get_gateway(federation_id)
.await
.ok_or(anyhow!("Not gateway configured for federation"))?;

Expand Down
17 changes: 4 additions & 13 deletions src/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ pub(crate) trait MultiMintWrapperTrait {
async fn check_has_federation(&self, id: FederationId) -> bool;
async fn get_federation_client(&self, id: FederationId) -> Option<ClientHandleArc>;
async fn register_new_federation(&self, invite_code: InviteCode) -> anyhow::Result<()>;
async fn get_gateway(&self, id: &FederationId) -> Option<LightningGateway>;
async fn get_gateway(&self, id: FederationId) -> Option<LightningGateway>;
}

#[derive(Clone)]
struct MultiMintWrapper {
fm: Arc<RwLock<MultiMint>>,
/// Our preferred lightning gateway for each federation
gateways: Arc<RwLock<HashMap<FederationId, LightningGateway>>>,
}

#[async_trait]
Expand Down Expand Up @@ -57,18 +55,12 @@ impl MultiMintWrapperTrait for MultiMintWrapper {
error!("Failed to update gateway cache: {e}");
}

if let Some(gateway) = select_gateway(&client).await {
self.gateways.write().await.insert(id, gateway);
} else {
error!("No suitable gateway found for federation {id}");
}

Ok(())
}

async fn get_gateway(&self, id: &FederationId) -> Option<LightningGateway> {
let lock = self.gateways.read().await;
lock.get(id).cloned()
async fn get_gateway(&self, id: FederationId) -> Option<LightningGateway> {
let client = self.get_federation_client(id).await?;
select_gateway(&client).await
}
}

Expand Down Expand Up @@ -101,7 +93,6 @@ pub(crate) async fn setup_multimint(

let mmw = MultiMintWrapper {
fm: Arc::new(RwLock::new(mm)),
gateways: Arc::new(RwLock::new(HashMap::new())),
};

Ok(Arc::new(mmw))
Expand Down

0 comments on commit d367944

Please sign in to comment.