From c7c249723831e9c1075ef5313743829aeba7122e Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Tue, 12 Sep 2023 21:44:23 -0700 Subject: [PATCH] add cost for txpool_content and some unimplemented methods --- web3_proxy/src/compute_units.rs | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/web3_proxy/src/compute_units.rs b/web3_proxy/src/compute_units.rs index c9ad4de4..2f4c63c0 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::str::FromStr; +use std::{ops::Add, str::FromStr}; use tracing::{instrument, trace, warn}; pub fn default_usd_per_cu(chain_id: u64) -> Decimal { @@ -22,6 +22,17 @@ pub fn default_usd_per_cu(chain_id: u64) -> Decimal { #[derive(Debug)] pub struct ComputeUnit(Decimal); +impl Add for ComputeUnit +where + T: Into, +{ + type Output = Self; + + fn add(self, rhs: T) -> Self::Output { + Self(self.0 + rhs.into()) + } +} + impl ComputeUnit { /// costs can vary widely depending on method and chain #[instrument(level = "trace")] @@ -92,9 +103,18 @@ impl ComputeUnit { (_, "eth_getUserOperationByHash") => 17, (_, "eth_getUserOperationReceipt") => 15, (_, "eth_maxPriorityFeePerGas") => 10, - (_, "eth_newBlockFilter") => 20, - (_, "eth_newFilter") => 20, - (_, "eth_newPendingTransactionFilter") => 20, + (_, "eth_newBlockFilter") => { + // TODO: 20 + return Self::unimplemented(); + } + (_, "eth_newFilter") => { + // TODO: 20 + return Self::unimplemented(); + } + (_, "eth_newPendingTransactionFilter") => { + // TODO: 20 + return Self::unimplemented(); + } (_, "eth_pollSubscriptions") => { return Self::unimplemented(); } @@ -118,6 +138,9 @@ impl ComputeUnit { (_, "trace_replayBlockTransactions") => 2983, (_, "trace_replayTransaction") => 2983, (_, "trace_transaction") => 26, + (_, "txpool_content") => { + return Self::subscription_response(response_bytes) + 1000; + } (_, "invalid_method") => 100, (_, "web3_clientVersion") => 15, (_, "web3_bundlerVersion") => 15, @@ -152,6 +175,7 @@ impl ComputeUnit { /// notifications and subscription responses cost per-byte #[instrument(level = "trace")] pub fn subscription_response + std::fmt::Debug>(num_bytes: D) -> Self { + // TODO: get multiplier from config let cu = num_bytes.into() * Decimal::new(4, 2); Self(cu)