diff --git a/web3_proxy/src/app/mod.rs b/web3_proxy/src/app/mod.rs index 6f6549d1..589c9b9d 100644 --- a/web3_proxy/src/app/mod.rs +++ b/web3_proxy/src/app/mod.rs @@ -345,6 +345,14 @@ impl Web3ProxyApp { ); } + if !top_config.extra.is_empty() { + warn!("unknown TopConfig fields!: {:?}", top_config.app.extra.keys()); + } + + if !top_config.app.extra.is_empty() { + warn!("unknown Web3ProxyAppConfig fields!: {:?}", top_config.app.extra.keys()); + } + // setup metrics let app_metrics = Default::default(); let open_request_handle_metrics: Arc = Default::default(); diff --git a/web3_proxy/src/bin/web3_proxy.rs b/web3_proxy/src/bin/web3_proxy.rs index 69cba460..94269dfa 100644 --- a/web3_proxy/src/bin/web3_proxy.rs +++ b/web3_proxy/src/bin/web3_proxy.rs @@ -293,7 +293,7 @@ mod tests { // make a test TopConfig // TODO: load TopConfig from a file? CliConfig could have `cli_config.load_top_config`. would need to inject our endpoint ports - let app_config = TopConfig { + let top_config = TopConfig { app: AppConfig { chain_id: 31337, default_user_max_requests_per_period: Some(6_000_000), @@ -317,6 +317,7 @@ mod tests { hard_limit: None, weight: 1, subscribe_txs: Some(false), + extra: Default::default(), }, ), ( @@ -330,6 +331,7 @@ mod tests { hard_limit: None, weight: 1, subscribe_txs: Some(false), + extra: Default::default(), }, ), ]), @@ -343,7 +345,7 @@ mod tests { let handle = { let shutdown_sender = shutdown_sender.clone(); - thread::spawn(move || run(shutdown_sender, cli_config, app_config)) + thread::spawn(move || run(shutdown_sender, cli_config, top_config)) }; // TODO: do something to the node. query latest block, mine another block, query again diff --git a/web3_proxy/src/config.rs b/web3_proxy/src/config.rs index d8574289..71461fd6 100644 --- a/web3_proxy/src/config.rs +++ b/web3_proxy/src/config.rs @@ -5,6 +5,7 @@ use crate::{app::AnyhowJoinHandle, rpcs::blockchain::ArcBlock}; use argh::FromArgs; use ethers::prelude::TxHash; use hashbrown::HashMap; +use log::warn; use migration::sea_orm::DatabaseConnection; use serde::Deserialize; use std::sync::Arc; @@ -38,17 +39,19 @@ pub struct CliConfig { } #[derive(Debug, Deserialize)] -#[serde(deny_unknown_fields)] pub struct TopConfig { pub app: AppConfig, pub balanced_rpcs: HashMap, + // TODO: instead of an option, give it a default pub private_rpcs: Option>, + /// unknown config options get put here + #[serde(flatten, default="HashMap::default")] + pub extra: HashMap, } /// shared configuration between Web3Connections // TODO: no String, only &str #[derive(Debug, Default, Deserialize)] -#[serde(deny_unknown_fields)] pub struct AppConfig { /// Request limit for allowed origins for anonymous users. /// These requests get rate limited by IP. @@ -143,6 +146,10 @@ pub struct AppConfig { /// maximum size of the connection pool for the cache /// If none, the minimum * 2 is used pub volatile_redis_max_connections: Option, + + /// unknown config options get put here + #[serde(flatten, default="HashMap::default")] + pub extra: HashMap, } fn default_allowed_origin_requests_per_period() -> HashMap { @@ -177,7 +184,6 @@ fn default_response_cache_max_bytes() -> usize { /// Configuration for a backend web3 RPC server #[derive(Debug, Deserialize)] -#[serde(deny_unknown_fields)] pub struct Web3ConnectionConfig { /// simple way to disable a connection without deleting the row #[serde(default)] @@ -199,6 +205,9 @@ pub struct Web3ConnectionConfig { /// Don't do this with free rpcs #[serde(default)] pub subscribe_txs: Option, + /// unknown config options get put here + #[serde(flatten, default="HashMap::default")] + pub extra: HashMap, } fn default_weight() -> u32 { @@ -222,6 +231,10 @@ impl Web3ConnectionConfig { tx_id_sender: Option>, open_request_handle_metrics: Arc, ) -> anyhow::Result<(Arc, AnyhowJoinHandle<()>)> { + if !self.extra.is_empty() { + warn!("unknown Web3ConnectionConfig fields!: {:?}", self.extra.keys()); + } + let hard_limit = match (self.hard_limit, redis_pool) { (None, None) => None, (Some(hard_limit), Some(redis_client_pool)) => Some((hard_limit, redis_client_pool)),