From f7cfd39d932ef577b9bbaf4bbdf7688cf6e655aa Mon Sep 17 00:00:00 2001 From: yenicelik Date: Fri, 21 Jul 2023 18:03:55 -0400 Subject: [PATCH] Revert "Merge branch 'devel' of github.com:llamanodes/web3-proxy into devel" This reverts commit 4fc745b52b90b72fdd2d9e8e990ec2d42d9f680d, reversing changes made to bc6d18041d652502f83d44aedbea234e02b59f6f. --- README.md | 6 +++--- web3_proxy/src/stats/mod.rs | 20 +++++++++++++++++--- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9cc7553a..bd72948d 100644 --- a/README.md +++ b/README.md @@ -178,8 +178,8 @@ Test the proxy: wrk -t12 -c400 -d30s --latency http://127.0.0.1:8544/health wrk -t12 -c400 -d30s --latency http://127.0.0.1:8544/status - wrk -s ./wrk/getBlockNumber.lua -t12 -c400 -d30s --latency http://127.0.0.1:8544/rpc/$API_KEY - wrk -s ./wrk/getLatestBlockByNumber.lua -t12 -c400 -d30s --latency http://127.0.0.1:8544/rpc/$API_KEY + wrk -s ./wrk/getBlockNumber.lua -t12 -c400 -d30s --latency http://127.0.0.1:8544/u/$API_KEY + wrk -s ./wrk/getLatestBlockByNumber.lua -t12 -c400 -d30s --latency http://127.0.0.1:8544/u/$API_KEY Test geth (assuming it is on 8545): @@ -197,4 +197,4 @@ Run [ethspam](https://github.com/INFURA/versus) and [versus](https://github.com/ ethspam --rpc http://127.0.0.1:8544 | versus --concurrency=10 --stop-after=1000 http://127.0.0.1:8544 - ethspam --rpc http://127.0.0.1:8544/rpc/$API_KEY | versus --concurrency=100 --stop-after=10000 http://127.0.0.1:8544/rpc/$API_KEY + ethspam --rpc http://127.0.0.1:8544/u/$API_KEY | versus --concurrency=100 --stop-after=10000 http://127.0.0.1:8544/u/$API_KEY diff --git a/web3_proxy/src/stats/mod.rs b/web3_proxy/src/stats/mod.rs index 08db04b4..d4b571f9 100644 --- a/web3_proxy/src/stats/mod.rs +++ b/web3_proxy/src/stats/mod.rs @@ -12,6 +12,7 @@ use crate::errors::{Web3ProxyError, Web3ProxyResult}; use crate::frontend::authorization::{Authorization, RequestMetadata}; use crate::rpcs::one::Web3Rpc; use anyhow::{anyhow, Context}; +use axum::headers::Origin; use chrono::{DateTime, Months, TimeZone, Utc}; use derive_more::From; use entities::{referee, referrer, rpc_accounting_v2}; @@ -85,6 +86,8 @@ pub struct RpcQueryKey { user_error_response: bool, /// the rpc method used. method: Cow<'static, str>, + /// origin tracking **was** opt-in. Now, it is always "None" + origin: Option, /// None if the public url was used. rpc_secret_key_id: Option, /// None if the public url was used. @@ -110,23 +113,27 @@ impl RpcQueryStats { fn accounting_key(&self, period_seconds: i64) -> RpcQueryKey { let response_timestamp = round_timestamp(self.response_timestamp, period_seconds); + // TODO: change this to use 0 for anonymous queries let rpc_secret_key_id = self.authorization.checks.rpc_secret_key_id; - let rpc_key_user_id = self.authorization.checks.user_id.try_into().ok(); let method = self.method.clone(); + // we used to optionally store origin, but wallets don't set it, so its almost always None + let origin = None; + // user_error_response is always set to false because we don't bother tracking this in the database let user_error_response = false; // Depending on method, add some arithmetic around calculating credits_used // I think balance should not go here, this looks more like a key thingy RpcQueryKey { + response_timestamp, archive_needed: self.archive_request, error_response: self.error_response, method, - response_timestamp, - rpc_key_user_id, rpc_secret_key_id, + rpc_key_user_id: self.authorization.checks.user_id.try_into().ok(), + origin, user_error_response, } } @@ -136,6 +143,8 @@ impl RpcQueryStats { fn global_timeseries_key(&self) -> RpcQueryKey { // we include the method because that can be helpful for predicting load let method = self.method.clone(); + // we don't store origin in the timeseries db. its only used for optional accounting + let origin = None; // everyone gets grouped together let rpc_secret_key_id = None; let rpc_key_user_id = None; @@ -148,6 +157,7 @@ impl RpcQueryStats { rpc_secret_key_id, rpc_key_user_id, user_error_response: self.user_error_response, + origin, } } @@ -157,6 +167,9 @@ impl RpcQueryStats { return None; } + // we don't store origin in the timeseries db. its only optionaly used for accounting + let origin = None; + let method = self.method.clone(); let key = RpcQueryKey { @@ -167,6 +180,7 @@ impl RpcQueryStats { rpc_secret_key_id: self.authorization.checks.rpc_secret_key_id, rpc_key_user_id: self.authorization.checks.user_id.try_into().ok(), user_error_response: self.user_error_response, + origin, }; Some(key)