From 3174fa5bad16860e22e82d472050f613a781c2e0 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Mon, 18 Sep 2023 14:18:05 -0700 Subject: [PATCH] increase cost of eth_subscribe(newPendingTransactions) --- web3_proxy/src/compute_units.rs | 10 ++++++---- web3_proxy_cli/tests/test_multiple_proxy.rs | 4 +++- web3_proxy_cli/tests/test_single_proxy.rs | 4 +++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/web3_proxy/src/compute_units.rs b/web3_proxy/src/compute_units.rs index be1402c7..806cefe5 100644 --- a/web3_proxy/src/compute_units.rs +++ b/web3_proxy/src/compute_units.rs @@ -12,15 +12,17 @@ use tracing::{instrument, trace, warn}; pub fn default_usd_per_cu(chain_id: u64) -> Decimal { match chain_id { - // TODO: only include if `cfg(test)`? 999_001_999 => Decimal::from_str("0.10").unwrap(), 1 | 31337 => Decimal::from_str("0.000000400000000000000").unwrap(), _ => Decimal::from_str("0.000000533333333333333").unwrap(), } } -pub fn default_cu_per_byte(_chain_id: u64) -> Decimal { - Decimal::new(4, 2) +pub fn default_cu_per_byte(_chain_id: u64, method: &str) -> Decimal { + match method { + "eth_subscribe(newPendingTransactions)" => Decimal::new(16, 2), + _ => Decimal::new(4, 2), + } } #[derive(Debug)] @@ -183,7 +185,7 @@ impl ComputeUnit { method: &str, num_bytes: D, ) -> Self { - let cu = num_bytes.into() * default_cu_per_byte(chain_id); + let cu = num_bytes.into() * default_cu_per_byte(chain_id, method); Self(cu) } diff --git a/web3_proxy_cli/tests/test_multiple_proxy.rs b/web3_proxy_cli/tests/test_multiple_proxy.rs index 1abdc3c7..1ea7591e 100644 --- a/web3_proxy_cli/tests/test_multiple_proxy.rs +++ b/web3_proxy_cli/tests/test_multiple_proxy.rs @@ -4,7 +4,7 @@ use std::time::Duration; use tracing::{info, warn}; use web3_proxy::prelude::futures::future::try_join_all; use web3_proxy::prelude::reqwest; -use web3_proxy::prelude::rust_decimal::Decimal; +use web3_proxy::prelude::rust_decimal::{Decimal, RoundingStrategy}; use web3_proxy::prelude::tokio::time::sleep; use web3_proxy::rpcs::blockchain::ArcBlock; use web3_proxy::test_utils::TestInflux; @@ -204,6 +204,7 @@ async fn test_multiple_proxies_stats_add_up() { .replace('"', "") ) .unwrap() + .round_dp_with_strategy(10, RoundingStrategy::ToNegativeInfinity) ); assert_eq!( Decimal::from_str( @@ -218,6 +219,7 @@ async fn test_multiple_proxies_stats_add_up() { .replace('"', "") ) .unwrap() + .round_dp_with_strategy(10, RoundingStrategy::ToNegativeInfinity) ); assert_eq!( Decimal::from_str(&mysql_stats["sum_request_bytes"].to_string()).unwrap(), diff --git a/web3_proxy_cli/tests/test_single_proxy.rs b/web3_proxy_cli/tests/test_single_proxy.rs index bbd1dca6..7c5bced7 100644 --- a/web3_proxy_cli/tests/test_single_proxy.rs +++ b/web3_proxy_cli/tests/test_single_proxy.rs @@ -4,7 +4,7 @@ use std::time::Duration; use tracing::{info, warn}; use web3_proxy::prelude::futures::future::try_join_all; use web3_proxy::prelude::reqwest; -use web3_proxy::prelude::rust_decimal::Decimal; +use web3_proxy::prelude::rust_decimal::{Decimal, RoundingStrategy}; use web3_proxy::prelude::tokio::time::sleep; use web3_proxy::rpcs::blockchain::ArcBlock; use web3_proxy_cli::test_utils::create_provider_with_rpc_key::create_provider_for_user; @@ -175,6 +175,7 @@ async fn test_single_proxy_stats_add_up() { .replace('"', "") ) .unwrap() + .round_dp_with_strategy(10, RoundingStrategy::ToNegativeInfinity) ); assert_eq!( Decimal::from_str( @@ -189,6 +190,7 @@ async fn test_single_proxy_stats_add_up() { .replace('"', "") ) .unwrap() + .round_dp_with_strategy(10, RoundingStrategy::ToNegativeInfinity) ); assert_eq!( Decimal::from_str(&mysql_stats["sum_request_bytes"].to_string()).unwrap(),