Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/balance-overrides/src/balance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ mod tests {

let strategy = detector.detect(NATIVE_ETH, user).await.unwrap();

std::assert_matches!(strategy, Strategy::NativeEth);
std::assert_eq!(strategy, Strategy::NativeEth);
Comment thread
metalurgical marked this conversation as resolved.
Outdated

// ETH is not an ERC20 token so we can't do an `eth_call` on `balanceOf()`.
// Additionally `eth_getBalance` does not support state overrides.
Expand Down
2 changes: 1 addition & 1 deletion crates/orderbook/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ axum = { workspace = true }
bad-tokens = { workspace = true }
balance-overrides = { workspace = true }
bigdecimal = { workspace = true }
cached = { workspace = true }
chain = { workspace = true }
chrono = { workspace = true, features = ["clock"] }
clap = { workspace = true }
Expand All @@ -43,6 +42,7 @@ humantime = { workspace = true }
humantime-serde = { workspace = true }
mimalloc = { workspace = true, optional = true }
model = { workspace = true }
moka = { workspace = true }
multibase = { workspace = true }
num = { workspace = true }
number = { workspace = true }
Expand Down
27 changes: 9 additions & 18 deletions crates/orderbook/src/ipfs_app_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ use {
crate::ipfs::Ipfs,
anyhow::Result,
app_data::{AppDataHash, create_ipfs_cid},
cached::{Cached, TimedSizedCache},
std::sync::Mutex,
moka::sync::Cache,
Comment thread
metalurgical marked this conversation as resolved.
Outdated
};

pub struct IpfsAppData {
ipfs: Ipfs,
cache: Mutex<TimedSizedCache<AppDataHash, Option<String>>>,
cache: Cache<AppDataHash, Option<String>>,
metrics: &'static Metrics,
}

Expand All @@ -34,9 +33,10 @@ impl IpfsAppData {
}
Self {
ipfs,
cache: Mutex::new(TimedSizedCache::with_size_and_lifespan_and_refresh(
1000, 600, false,
)),
cache: Cache::builder()
.max_capacity(1000)
.time_to_live(std::time::Duration::from_secs(600))
.build(),
metrics,
}
}
Expand All @@ -63,7 +63,7 @@ impl IpfsAppData {
result
}
Ok(None) => {
tracing::debug!(?contract_app_data, %cid,"no full app data");
tracing::debug!(?contract_app_data, %cid, "no full app data");
return Ok(None);
}
Err(err) => {
Expand All @@ -88,13 +88,7 @@ impl IpfsAppData {
let outcome = |data: &Option<String>| if data.is_some() { "found" } else { "missing" };

let metric = &self.metrics.app_data;
if let Some(cached) = self
.cache
.lock()
.unwrap()
.cache_get(contract_app_data)
.cloned()
{
if let Some(cached) = self.cache.get(contract_app_data) {
metric.with_label_values(&[outcome(&cached), "cache"]).inc();
return Ok(cached);
}
Expand All @@ -111,10 +105,7 @@ impl IpfsAppData {
}
};

self.cache
.lock()
.unwrap()
.cache_set(*contract_app_data, result.clone());
self.cache.insert(*contract_app_data, result.clone());
metric.with_label_values(&[outcome(&result), "node"]).inc();
Ok(result)
}
Expand Down
Loading