increase cost of eth_subscribe(newPendingTransactions)

This commit is contained in:
Bryan Stitt 2023-09-18 14:18:05 -07:00
parent f4a648223b
commit 3174fa5bad
3 changed files with 12 additions and 6 deletions

View File

@ -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)
}

View File

@ -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(),

View File

@ -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(),