diff --git a/TODO.md b/TODO.md index fcf708ba..490b0933 100644 --- a/TODO.md +++ b/TODO.md @@ -232,9 +232,9 @@ These are roughly in order of completition - [x] nullable rpc_key_id on revert log - [x] attach origin to revert_log - opt-in origin logging +- [x] test that runs check_config against example.toml - [-] add configurable size limits to all the Caches - instead of configuring each cache with MB sizes, have one value for total memory footprint and then percentages for each cache -- [ ] test that runs check_config against example.toml - [ ] improve sorting servers by weight - if the utilization is > 100%, increase weight by 1? maybe just add utilization to the weight? - if utilization is > hard limit, add a lot to the weight diff --git a/config/example.toml b/config/example.toml index f7770934..12742d20 100644 --- a/config/example.toml +++ b/config/example.toml @@ -13,7 +13,7 @@ volatile_redis_max_connections = 300 volatile_redis_url = "redis://REDIS_DOMAIN:REDIS_PORT/" redirect_public_url = "https://llamanodes.com/public-rpc" -redirect_user_url = "https://llamanodes.com/dashboard/keys?key={rpc_key_id}" +redirect_rpc_key_url = "https://llamanodes.com/dashboard/keys?key={rpc_key_id}" sentry_url = "https://SENTRY_KEY_A.ingest.sentry.io/SENTRY_KEY_B" diff --git a/web3_proxy/src/bin/web3_proxy_cli/check_config.rs b/web3_proxy/src/bin/web3_proxy_cli/check_config.rs index a05e055f..4491fdf6 100644 --- a/web3_proxy/src/bin/web3_proxy_cli/check_config.rs +++ b/web3_proxy/src/bin/web3_proxy_cli/check_config.rs @@ -14,6 +14,8 @@ pub struct CheckConfigSubCommand { impl CheckConfigSubCommand { pub async fn main(self) -> anyhow::Result<()> { + let mut num_errors = 0; + info!("Loading config @ {}", self.path); let top_config: String = fs::read_to_string(self.path)?; let top_config: TopConfig = toml::from_str(&top_config)?; @@ -72,11 +74,49 @@ impl CheckConfigSubCommand { } Some(x) => { if !x.contains("{rpc_key_id}") { + num_errors += 1; error!("redirect_user_url user url must contain \"{{rpc_key_id}}\"") } } } - Ok(()) + // TODO: print num warnings and have a flag to fail even on warnings + + if num_errors == 0 { + Ok(()) + } else { + Err(anyhow::anyhow!(format!( + "there were {} errors!", + num_errors + ))) + } + } +} + +#[cfg(test)] +mod tests { + use std::env; + + use super::*; + + #[tokio::test] + async fn check_example_toml() { + let path = env::current_dir().expect("path"); + + let parent = path.parent().expect("always a parent"); + + let config_path = parent.join("config").join("example.toml"); + + let config_path_str = config_path.to_str().expect("always a valid path"); + + let check_config_command = + CheckConfigSubCommand::from_args(&["check_config"], &[config_path_str]) + .expect("the command should have run"); + + let check_config_result = check_config_command.main().await; + + println!("{:?}", check_config_result); + + check_config_result.expect("the config should pass all checks"); } }