From f859ed56fc31171a7a719ac66add52e52e90e670 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Tue, 1 Nov 2022 19:24:29 +0000 Subject: [PATCH] period instead of minute in variable names --- Cargo.lock | 7 ++++--- config/example.toml | 4 ++-- deferred-rate-limiter/Cargo.toml | 2 +- deferred-rate-limiter/src/lib.rs | 1 - web3_proxy/Cargo.toml | 4 ++-- web3_proxy/src/app_stats.rs | 3 ++- web3_proxy/src/rpcs/connection.rs | 2 +- 7 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1ca24beb..c98a94fc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2698,9 +2698,9 @@ dependencies = [ [[package]] name = "moka" -version = "0.9.4" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8256cf9fa396576521e5e94affadb95818ec48f5dbedca36714387688aea29" +checksum = "e013c8176e5aae43f4c0a982733c44feebddc4e7ac0871a109a9655e668487af" dependencies = [ "async-io", "async-lock", @@ -2711,6 +2711,7 @@ dependencies = [ "num_cpus", "once_cell", "parking_lot 0.12.1", + "rustc_version", "scheduled-thread-pool", "skeptic", "smallvec", @@ -5527,7 +5528,7 @@ dependencies = [ [[package]] name = "web3_proxy" -version = "0.6.0" +version = "0.8.0" dependencies = [ "anyhow", "arc-swap", diff --git a/config/example.toml b/config/example.toml index 33c01348..fa19b9ff 100644 --- a/config/example.toml +++ b/config/example.toml @@ -18,12 +18,12 @@ redirect_user_url = "https://llamanodes.com/user-rpc-stats/{{user_id}}" # 0 = block all public requests public_max_concurrent_requests = 5 # 0 = block all public requests -public_requests_per_minute = 0 +public_requests_per_period = 0 # 1GB of cache response_cache_max_bytes = 10_000_000_000 -[app.allowed_origin_requests_per_minute] +[app.allowed_origin_requests_per_period] "https://chainlist.org" = 1_000 [balanced_rpcs] diff --git a/deferred-rate-limiter/Cargo.toml b/deferred-rate-limiter/Cargo.toml index 77f8d6a7..64a87d73 100644 --- a/deferred-rate-limiter/Cargo.toml +++ b/deferred-rate-limiter/Cargo.toml @@ -9,6 +9,6 @@ redis-rate-limiter = { path = "../redis-rate-limiter" } anyhow = "1.0.66" hashbrown = "0.12.3" -moka = { version = "0.9.4", default-features = false, features = ["future"] } +moka = { version = "0.9.5", default-features = false, features = ["future"] } tokio = "1.21.2" tracing = "0.1.37" diff --git a/deferred-rate-limiter/src/lib.rs b/deferred-rate-limiter/src/lib.rs index 343adec4..943b54cf 100644 --- a/deferred-rate-limiter/src/lib.rs +++ b/deferred-rate-limiter/src/lib.rs @@ -77,7 +77,6 @@ where let redis_key = format!("{}:{}", self.prefix, key); - // TODO: DO NOT UNWRAP HERE. figure out how to handle anyhow error being wrapped in an Arc // TODO: i'm sure this could be a lot better. but race conditions make this hard to think through. brain needs sleep let local_key_count: Arc = { // clone things outside of the `async move` diff --git a/web3_proxy/Cargo.toml b/web3_proxy/Cargo.toml index 57f62876..829207cd 100644 --- a/web3_proxy/Cargo.toml +++ b/web3_proxy/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "web3_proxy" -version = "0.6.0" +version = "0.8.0" edition = "2021" default-run = "web3_proxy" @@ -39,7 +39,7 @@ hdrhistogram = "7.5.2" http = "0.2.8" ipnet = "2.5.0" metered = { version = "0.9.0", features = ["serialize"] } -moka = { version = "0.9.4", default-features = false, features = ["future"] } +moka = { version = "0.9.5", default-features = false, features = ["future"] } notify = "5.0.0" num = "0.4.0" # TODO: import num_traits from sea-orm so we always have the same version diff --git a/web3_proxy/src/app_stats.rs b/web3_proxy/src/app_stats.rs index 303dc671..e01941a2 100644 --- a/web3_proxy/src/app_stats.rs +++ b/web3_proxy/src/app_stats.rs @@ -348,9 +348,10 @@ impl StatEmitter { debug_assert_eq!(stat.period_seconds, self.period_seconds); // get the user cache for the current period + // TODO: i don't think this works right. maybe do DashMap entry api as the outer variable let user_cache = self .aggregated_proxy_responses - .get_with(stat.period_timestamp, async move { + .get_with_by_ref(&stat.period_timestamp, async move { CacheBuilder::default() .build_with_hasher(hashbrown::hash_map::DefaultHashBuilder::new()) }) diff --git a/web3_proxy/src/rpcs/connection.rs b/web3_proxy/src/rpcs/connection.rs index 5761aba0..a0433e0b 100644 --- a/web3_proxy/src/rpcs/connection.rs +++ b/web3_proxy/src/rpcs/connection.rs @@ -384,7 +384,7 @@ impl Web3Connection { // if we already have this block saved, set new_head_block to that arc. otherwise store this copy new_head_block = block_map - .get_with(new_hash, async move { new_head_block }) + .get_with_by_ref(&new_hash, async move { new_head_block }) .await; let new_num = new_head_block.number.unwrap_or_default();