From 339bd41f50c8633246bd3eb5b6c4c570cd39cb6d Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Wed, 21 Sep 2022 19:54:40 +0000 Subject: [PATCH] change rpm to u64 and create RevertLogs table --- TODO.md | 4 ++-- entities/src/user_keys.rs | 2 +- migration/src/lib.rs | 8 ++++++-- migration/src/m20220101_000001_create_table.rs | 2 +- web3_proxy/src/bin/web3_proxy_cli/create_user.rs | 7 ++++--- web3_proxy/src/config.rs | 9 +++++---- 6 files changed, 19 insertions(+), 13 deletions(-) diff --git a/TODO.md b/TODO.md index 16ceb811..b81646a7 100644 --- a/TODO.md +++ b/TODO.md @@ -154,6 +154,8 @@ These are roughly in order of completition - WARN http_request: redis_rate_limit::errors: redis error err=Response was of incompatible type: "Response type not string compatible." (response was int(500237)) id=01GC6514JWN5PS1NCWJCGJTC94 method=POST - [x] web3_proxy_error_count{path = "backend_rpc/request"} is inflated by a bunch of reverts. do not log reverts as warn. - erigon gives `method=eth_call reqid=986147 t=1.151551ms err="execution reverted"` +- [x] database migration to change user_keys.requests_per_minute to bigunsigned (max of 18446744073709551615) +- [x] change user creation script to have a "unlimited requests per minute" flag that sets it to u64::MAX (18446744073709551615) - [ ] opt-in debug mode that inspects responses for reverts and saves the request to the database for the user. let them choose a % to log (or maybe x/second). someone like curve logging all reverts will be a BIG database very quickly - this must be opt-in or spawned since it will slow things down and will make their calls less private - [-] add configurable size limits to all the Caches @@ -166,8 +168,6 @@ These are roughly in order of completition - since users are actively using our service, we will need to support both - [ ] Ulid instead of Uuid for database ids - might have to use Uuid in sea-orm and then convert to Ulid on display -- [ ] database migration to change user_keys.requests_per_minute to bigint (max of 18446744073709551615) -- [ ] change user creation script to have a "unlimited requests per minute" flag that sets it to u64::MAX (18446744073709551615) ## V1 diff --git a/entities/src/user_keys.rs b/entities/src/user_keys.rs index 98126743..41ce1d28 100644 --- a/entities/src/user_keys.rs +++ b/entities/src/user_keys.rs @@ -15,7 +15,7 @@ pub struct Model { pub description: Option, pub private_txs: bool, pub active: bool, - pub requests_per_minute: u32, + pub requests_per_minute: u64, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] diff --git a/migration/src/lib.rs b/migration/src/lib.rs index 2c605afb..6e016ca9 100644 --- a/migration/src/lib.rs +++ b/migration/src/lib.rs @@ -1,12 +1,16 @@ pub use sea_orm_migration::prelude::*; -mod m20220101_000001_create_table; +pub mod m20220101_000001_create_table; +pub mod m20220921_181610_log_reverts; pub struct Migrator; #[async_trait::async_trait] impl MigratorTrait for Migrator { fn migrations() -> Vec> { - vec![Box::new(m20220101_000001_create_table::Migration)] + vec![ + Box::new(m20220101_000001_create_table::Migration), + Box::new(m20220921_181610_log_reverts::Migration), + ] } } diff --git a/migration/src/m20220101_000001_create_table.rs b/migration/src/m20220101_000001_create_table.rs index 364446a1..89cbee8d 100644 --- a/migration/src/m20220101_000001_create_table.rs +++ b/migration/src/m20220101_000001_create_table.rs @@ -174,7 +174,7 @@ enum SecondaryUser { -- TODO: more security features. likely similar to infura */ #[derive(Iden)] -enum UserKeys { +pub enum UserKeys { Table, Id, UserId, diff --git a/web3_proxy/src/bin/web3_proxy_cli/create_user.rs b/web3_proxy/src/bin/web3_proxy_cli/create_user.rs index c74feb07..71e50abf 100644 --- a/web3_proxy/src/bin/web3_proxy_cli/create_user.rs +++ b/web3_proxy/src/bin/web3_proxy_cli/create_user.rs @@ -7,8 +7,9 @@ use tracing::info; use uuid::Uuid; use web3_proxy::users::new_api_key; -fn default_rpm() -> u32 { - 6_000_000 +/// default to max int which the code sees as "unlimited" requests +fn default_rpm() -> u64 { + u64::MAX } #[derive(FromArgs, PartialEq, Debug, Eq)] @@ -30,7 +31,7 @@ pub struct CreateUserSubCommand { #[argh(option, default = "default_rpm()")] /// maximum requests per minute - rpm: u32, + rpm: u64, } impl CreateUserSubCommand { diff --git a/web3_proxy/src/config.rs b/web3_proxy/src/config.rs index 2e71ec70..5ae23238 100644 --- a/web3_proxy/src/config.rs +++ b/web3_proxy/src/config.rs @@ -54,7 +54,7 @@ pub struct AppConfig { /// If none, the minimum * 2 is used pub db_max_connections: Option, #[serde(default = "default_default_requests_per_minute")] - pub default_requests_per_minute: u32, + pub default_requests_per_minute: u64, pub invite_code: Option, #[serde(default = "default_min_sum_soft_limit")] pub min_sum_soft_limit: u32, @@ -75,9 +75,10 @@ pub struct AppConfig { pub redirect_user_url: String, } -// TODO: what should we default to? have different tiers for different paid amounts? -fn default_default_requests_per_minute() -> u32 { - 1_000_000 * 60 +/// default to unlimited requests +/// TODO: pick a lower limit so we don't get DOSd +fn default_default_requests_per_minute() -> u64 { + u64::MAX } fn default_min_sum_soft_limit() -> u32 {