From 23f31c91294b86fe90b0f38664dee0bb8cc36009 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Tue, 24 Jan 2023 04:29:12 -0800 Subject: [PATCH] sanitize inputs and improve logs --- .../src/bin/web3_proxy_cli/sentryd/compare.rs | 14 ++++++++---- .../src/bin/web3_proxy_cli/sentryd/mod.rs | 22 +++++++++++++++---- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/web3_proxy/src/bin/web3_proxy_cli/sentryd/compare.rs b/web3_proxy/src/bin/web3_proxy_cli/sentryd/compare.rs index ada4681e..f4b5c27f 100644 --- a/web3_proxy/src/bin/web3_proxy_cli/sentryd/compare.rs +++ b/web3_proxy/src/bin/web3_proxy_cli/sentryd/compare.rs @@ -169,19 +169,25 @@ async fn check_rpc( // TODO: don't unwrap! don't use the try operator let response: JsonRpcResponse> = client - .post(rpc) + .post(rpc.clone()) .json(&block_by_hash_request) .send() - .await? + .await + .context(format!("awaiting response from {}", rpc))? .json() - .await?; + .await + .context(format!("reading json on {}", rpc))?; if let Some(result) = response.result { let abbreviated = AbbreviatedBlock::from(result); Ok(abbreviated) } else if let Some(result) = response.error { - Err(anyhow!("Failed parsing response as JSON: {:?}", result)) + Err(anyhow!( + "Failed parsing response from {} as JSON: {:?}", + rpc, + result + )) } else { unimplemented!("{:?}", response) } diff --git a/web3_proxy/src/bin/web3_proxy_cli/sentryd/mod.rs b/web3_proxy/src/bin/web3_proxy_cli/sentryd/mod.rs index d7f03da9..26dc43bd 100644 --- a/web3_proxy/src/bin/web3_proxy_cli/sentryd/mod.rs +++ b/web3_proxy/src/bin/web3_proxy_cli/sentryd/mod.rs @@ -53,6 +53,20 @@ impl SentrydSubCommand { pub async fn main(self, pagerduty_async: Option) -> anyhow::Result<()> { // sentry logging should already be configured + let web3_proxy = self.web3_proxy.trim_end_matches("/").to_string(); + + let other_proxy: Vec<_> = self + .other_proxy + .into_iter() + .map(|x| x.trim_end_matches("/").to_string()) + .collect(); + + let other_rpc: Vec<_> = self + .other_rpc + .into_iter() + .map(|x| x.trim_end_matches("/").to_string()) + .collect(); + let seconds = self.seconds.unwrap_or(60); let mut handles = FuturesUnordered::new(); @@ -109,7 +123,7 @@ impl SentrydSubCommand { // check the main rpc's /health endpoint { - let url = format!("{}/health", self.web3_proxy); + let url = format!("{}/health", web3_proxy); let error_sender = error_sender.clone(); let loop_f = a_loop( @@ -123,7 +137,7 @@ impl SentrydSubCommand { handles.push(tokio::spawn(loop_f)); } // check any other web3-proxy /health endpoints - for other_web3_proxy in self.other_proxy.iter() { + for other_web3_proxy in other_proxy.iter() { let url = format!("{}/health", other_web3_proxy); let error_sender = error_sender.clone(); @@ -145,9 +159,9 @@ impl SentrydSubCommand { let rpc = self.web3_proxy.clone(); let error_sender = error_sender.clone(); - let mut others = self.other_proxy.clone(); + let mut others = other_proxy.clone(); - others.extend(self.other_rpc.clone()); + others.extend(other_rpc); let loop_f = a_loop( "head block comparison",