sanitize inputs and improve logs

This commit is contained in:
Bryan Stitt 2023-01-24 04:29:12 -08:00
parent 953bb27adc
commit 23f31c9129
2 changed files with 28 additions and 8 deletions

@ -169,19 +169,25 @@ async fn check_rpc(
// TODO: don't unwrap! don't use the try operator // TODO: don't unwrap! don't use the try operator
let response: JsonRpcResponse<Block<TxHash>> = client let response: JsonRpcResponse<Block<TxHash>> = client
.post(rpc) .post(rpc.clone())
.json(&block_by_hash_request) .json(&block_by_hash_request)
.send() .send()
.await? .await
.context(format!("awaiting response from {}", rpc))?
.json() .json()
.await?; .await
.context(format!("reading json on {}", rpc))?;
if let Some(result) = response.result { if let Some(result) = response.result {
let abbreviated = AbbreviatedBlock::from(result); let abbreviated = AbbreviatedBlock::from(result);
Ok(abbreviated) Ok(abbreviated)
} else if let Some(result) = response.error { } 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 { } else {
unimplemented!("{:?}", response) unimplemented!("{:?}", response)
} }

@ -53,6 +53,20 @@ impl SentrydSubCommand {
pub async fn main(self, pagerduty_async: Option<PagerdutyAsyncEventsV2>) -> anyhow::Result<()> { pub async fn main(self, pagerduty_async: Option<PagerdutyAsyncEventsV2>) -> anyhow::Result<()> {
// sentry logging should already be configured // 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 seconds = self.seconds.unwrap_or(60);
let mut handles = FuturesUnordered::new(); let mut handles = FuturesUnordered::new();
@ -109,7 +123,7 @@ impl SentrydSubCommand {
// check the main rpc's /health endpoint // 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 error_sender = error_sender.clone();
let loop_f = a_loop( let loop_f = a_loop(
@ -123,7 +137,7 @@ impl SentrydSubCommand {
handles.push(tokio::spawn(loop_f)); handles.push(tokio::spawn(loop_f));
} }
// check any other web3-proxy /health endpoints // 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 url = format!("{}/health", other_web3_proxy);
let error_sender = error_sender.clone(); let error_sender = error_sender.clone();
@ -145,9 +159,9 @@ impl SentrydSubCommand {
let rpc = self.web3_proxy.clone(); let rpc = self.web3_proxy.clone();
let error_sender = error_sender.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( let loop_f = a_loop(
"head block comparison", "head block comparison",