From 8ff394137cbf4cce9c63c7e88e5a182c62ecf724 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Mon, 25 Jul 2022 19:03:19 +0000 Subject: [PATCH] better error if no redis client pool --- config/example.toml | 4 ++-- web3-proxy/src/app.rs | 2 +- web3-proxy/src/config.rs | 13 +++++++++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/config/example.toml b/config/example.toml index be68a8a5..e588a073 100644 --- a/config/example.toml +++ b/config/example.toml @@ -1,7 +1,7 @@ [shared] chain_id = 1 -# in prod, do `rate_limit_redis = "redis://redis:6379/"` -#rate_limit_redis = "redis://dev-redis:6379/" +# in prod, do `redis_url = "redis://redis:6379/"` +#redis_url = "redis://dev-redis:6379/" public_rate_limit_per_minute = 60_000 # 1GB of cache response_cache_max_bytes = 10 ^ 9 diff --git a/web3-proxy/src/app.rs b/web3-proxy/src/app.rs index 03e0c08a..1f227455 100644 --- a/web3-proxy/src/app.rs +++ b/web3-proxy/src/app.rs @@ -330,7 +330,7 @@ impl Web3ProxyApp { Some(pool) } None => { - info!("No redis address"); + warn!("No redis address"); None } }; diff --git a/web3-proxy/src/config.rs b/web3-proxy/src/config.rs index 188ba9ce..95744778 100644 --- a/web3-proxy/src/config.rs +++ b/web3-proxy/src/config.rs @@ -75,14 +75,23 @@ impl Web3ConnectionConfig { block_sender: Option>, tx_id_sender: Option)>>, ) -> anyhow::Result<(Arc, AnyhowJoinHandle<()>)> { - let hard_rate_limit = self.hard_limit.map(|x| (x, redis_client_pool.unwrap())); + let hard_limit = match (self.hard_limit, redis_client_pool) { + (None, None) => None, + (Some(hard_limit), Some(redis_client_pool)) => Some((hard_limit, redis_client_pool)), + (None, Some(_)) => None, + (Some(hard_limit), None) => { + return Err(anyhow::anyhow!( + "no redis client pool! needed for hard limit" + )) + } + }; Web3Connection::spawn( chain_id, self.url, http_client, http_interval_sender, - hard_rate_limit, + hard_limit, self.soft_limit, block_sender, tx_id_sender,