From 7bd44b01dfceea84f82d05e20ee09e7c8c1b3d4d Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Thu, 26 Oct 2023 11:04:11 -0700 Subject: [PATCH] lint and fixes that rls missed cuz of the version change --- web3_proxy/src/app/mod.rs | 9 ++++---- web3_proxy/src/compute_units.rs | 39 +++++++++++++++++++++------------ 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/web3_proxy/src/app/mod.rs b/web3_proxy/src/app/mod.rs index 768a55a2..c92899c5 100644 --- a/web3_proxy/src/app/mod.rs +++ b/web3_proxy/src/app/mod.rs @@ -1093,7 +1093,7 @@ impl App { .params() .as_array() .ok_or_else(|| Web3ProxyError::BadRequest("Unable to get array from params".into()))? - .get(0) + .first() .ok_or_else(|| Web3ProxyError::BadRequest("Unable to get item 0 from params".into()))? .as_str() .ok_or_else(|| { @@ -1177,8 +1177,9 @@ impl App { // no idea how we got an array here, but lets force this to just the txid // TODO: think about this more if value.get().starts_with('[') { - let backend_rpcs = web3_request - .backend_rpcs_used() + let backend_rpcs = web3_request.backend_rpcs_used(); + + let backend_rpcs = backend_rpcs .iter() .map(|x| x.name.as_str()) .collect::>(); @@ -1584,7 +1585,7 @@ impl App { serde_json::Value::Array(params) => { // TODO: make a struct and use serde conversion to clean this up if params.len() != 1 - || !params.get(0).map(|x| x.is_string()).unwrap_or(false) + || !params.first().map(|x| x.is_string()).unwrap_or(false) { // TODO: what error code? // TODO: use Web3ProxyError::BadRequest diff --git a/web3_proxy/src/compute_units.rs b/web3_proxy/src/compute_units.rs index fa35f727..e5a949eb 100644 --- a/web3_proxy/src/compute_units.rs +++ b/web3_proxy/src/compute_units.rs @@ -7,7 +7,7 @@ //! TODO: script that queries influx and calculates observed relative costs use migration::sea_orm::prelude::Decimal; -use std::{ops::Add, str::FromStr}; +use std::{ops::Add, ops::Mul, str::FromStr}; use tracing::{trace, warn}; /// TODO: i don't like how we use this inside the config and also have it available publicly. we should only getting this value from the config @@ -44,6 +44,17 @@ where } } +impl Mul for ComputeUnit +where + T: Into, +{ + type Output = Self; + + fn mul(self, rhs: T) -> Self::Output { + Self(self.0 * rhs.into()) + } +} + impl ComputeUnit { /// costs can vary widely depending on method and chain pub fn new(method: &str, chain_id: u64, response_bytes: u64) -> Self { @@ -155,31 +166,31 @@ impl ComputeUnit { (_, "web3_bundlerVersion") => 15, (_, "web3_sha3") => 15, (_, "ots_getInternalOperations") => { - return Self::variable_price(chain_id, method, response_bytes) + 100 + return Self::variable_price(chain_id, method, response_bytes) + 100; } (_, "ots_hasCode") => { - return Self::variable_price(chain_id, method, response_bytes) + 100 + return Self::variable_price(chain_id, method, response_bytes) + 100; } (_, "ots_getTransactionError") => { - return Self::variable_price(chain_id, method, response_bytes) + 100 + return Self::variable_price(chain_id, method, response_bytes) + 100; } (_, "ots_traceTransaction") => { - return Self::variable_price(chain_id, method, response_bytes) + 100 + return Self::variable_price(chain_id, method, response_bytes) + 100; } (_, "ots_getBlockDetails") => { - return Self::variable_price(chain_id, method, response_bytes) + 100 + return Self::variable_price(chain_id, method, response_bytes) + 100; } (_, "ots_getBlockDetailsByHash") => { - return Self::variable_price(chain_id, method, response_bytes) + 100 + return Self::variable_price(chain_id, method, response_bytes) + 100; } (_, "ots_getBlockTransactions") => { - return Self::variable_price(chain_id, method, response_bytes) + 100 + return Self::variable_price(chain_id, method, response_bytes) + 100; } (_, "ots_searchTransactionsBefore") => { - return Self::variable_price(chain_id, method, response_bytes) + 100 + return Self::variable_price(chain_id, method, response_bytes) + 100; } (_, "ots_searchTransactionsAfter") => { - return Self::variable_price(chain_id, method, response_bytes) + 100 + return Self::variable_price(chain_id, method, response_bytes) + 100; } (_, "ots_getTransactionBySenderAndNonce") => 1000, (_, "ots_getContractCreator") => 1000, @@ -204,11 +215,11 @@ impl ComputeUnit { { // maybe charge extra since they are doing things they aren't supposed to return Self::unimplemented(); - - warn!(%response_bytes, "unknown method {}", method); - return Self::unimplemented() - + Self::variable_price(chain_id, method, response_bytes).0; } + + warn!(%response_bytes, "unknown method {}", method); + return Self::unimplemented() + + Self::variable_price(chain_id, method, response_bytes).0; } };