From 1ab98f1edc0d7d83769b22d30d019eeab473e2fb Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Mon, 15 May 2023 13:19:57 -0700 Subject: [PATCH 01/10] fix panic --- web3_proxy/src/rpcs/one.rs | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/web3_proxy/src/rpcs/one.rs b/web3_proxy/src/rpcs/one.rs index 5ec2bfac..4ae71d53 100644 --- a/web3_proxy/src/rpcs/one.rs +++ b/web3_proxy/src/rpcs/one.rs @@ -995,16 +995,25 @@ impl Web3Rpc { .await?; } Ok(Some(block)) => { - // don't send repeat blocks - let new_hash = - block.hash.expect("blocks here should always have hashes"); + if let Some(new_hash) = block.hash { + // don't send repeat blocks + if new_hash != last_hash { + // new hash! + last_hash = new_hash; - if new_hash != last_hash { - // new hash! - last_hash = new_hash; + self.send_head_block_result( + Ok(Some(block)), + &block_sender, + block_map.clone(), + ) + .await?; + } + } else { + // TODO: why is this happening? + warn!("empty head block on {}", self); self.send_head_block_result( - Ok(Some(block)), + Ok(None), &block_sender, block_map.clone(), ) From 11e14b12ddf9a364d11e61450983277b75b69631 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Fri, 26 May 2023 15:23:26 -0700 Subject: [PATCH 02/10] don't drop columns for now --- migration/src/lib.rs | 1 - ...emove_columns_statsv2_origin_and_method.rs | 49 ------------------- 2 files changed, 50 deletions(-) delete mode 100644 migration/src/m20230511_161214_remove_columns_statsv2_origin_and_method.rs diff --git a/migration/src/lib.rs b/migration/src/lib.rs index 91c45391..8d577618 100644 --- a/migration/src/lib.rs +++ b/migration/src/lib.rs @@ -60,7 +60,6 @@ impl MigratorTrait for Migrator { Box::new(m20230307_002623_migrate_rpc_accounting_to_rpc_accounting_v2::Migration), Box::new(m20230412_171916_modify_secondary_user_add_primary_user::Migration), Box::new(m20230422_172555_premium_downgrade_logic::Migration), - Box::new(m20230511_161214_remove_columns_statsv2_origin_and_method::Migration), Box::new(m20230512_220213_allow_null_rpc_key_id_in_stats_v2::Migration), Box::new(m20230514_114803_admin_add_credits::Migration), ] diff --git a/migration/src/m20230511_161214_remove_columns_statsv2_origin_and_method.rs b/migration/src/m20230511_161214_remove_columns_statsv2_origin_and_method.rs deleted file mode 100644 index a5463c69..00000000 --- a/migration/src/m20230511_161214_remove_columns_statsv2_origin_and_method.rs +++ /dev/null @@ -1,49 +0,0 @@ -use sea_orm_migration::prelude::*; - -#[derive(DeriveMigrationName)] -pub struct Migration; - -#[async_trait::async_trait] -impl MigrationTrait for Migration { - async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { - manager - .alter_table( - Table::alter() - .table(RpcAccountingV2::Table) - .drop_column(RpcAccountingV2::Origin) - .drop_column(RpcAccountingV2::Method) - .to_owned(), - ) - .await - } - - async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { - manager - .alter_table( - Table::alter() - .table(RpcAccountingV2::Table) - .add_column( - ColumnDef::new(RpcAccountingV2::Method) - .string() - .not_null() - .default(""), - ) - .add_column( - ColumnDef::new(RpcAccountingV2::Origin) - .string() - .not_null() - .default(""), - ) - .to_owned(), - ) - .await - } -} - -/// Learn more at https://docs.rs/sea-query#iden -#[derive(Iden)] -enum RpcAccountingV2 { - Table, - Origin, - Method, -} From 1598b64b56200187db19ea4911b7c74780a5211a Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Fri, 26 May 2023 15:27:02 -0700 Subject: [PATCH 03/10] remove stale mod --- migration/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/migration/src/lib.rs b/migration/src/lib.rs index 8d577618..e5090698 100644 --- a/migration/src/lib.rs +++ b/migration/src/lib.rs @@ -25,7 +25,6 @@ mod m20230221_230953_track_spend; mod m20230307_002623_migrate_rpc_accounting_to_rpc_accounting_v2; mod m20230412_171916_modify_secondary_user_add_primary_user; mod m20230422_172555_premium_downgrade_logic; -mod m20230511_161214_remove_columns_statsv2_origin_and_method; mod m20230512_220213_allow_null_rpc_key_id_in_stats_v2; mod m20230514_114803_admin_add_credits; From 70196a49477dfbf8610f6930c727ad37dda59368 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Fri, 26 May 2023 16:32:54 -0700 Subject: [PATCH 04/10] Revert "don't drop columns for now" This reverts commit 11e14b12ddf9a364d11e61450983277b75b69631. --- migration/src/lib.rs | 1 + ...emove_columns_statsv2_origin_and_method.rs | 49 +++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 migration/src/m20230511_161214_remove_columns_statsv2_origin_and_method.rs diff --git a/migration/src/lib.rs b/migration/src/lib.rs index e5090698..c0199867 100644 --- a/migration/src/lib.rs +++ b/migration/src/lib.rs @@ -59,6 +59,7 @@ impl MigratorTrait for Migrator { Box::new(m20230307_002623_migrate_rpc_accounting_to_rpc_accounting_v2::Migration), Box::new(m20230412_171916_modify_secondary_user_add_primary_user::Migration), Box::new(m20230422_172555_premium_downgrade_logic::Migration), + Box::new(m20230511_161214_remove_columns_statsv2_origin_and_method::Migration), Box::new(m20230512_220213_allow_null_rpc_key_id_in_stats_v2::Migration), Box::new(m20230514_114803_admin_add_credits::Migration), ] diff --git a/migration/src/m20230511_161214_remove_columns_statsv2_origin_and_method.rs b/migration/src/m20230511_161214_remove_columns_statsv2_origin_and_method.rs new file mode 100644 index 00000000..a5463c69 --- /dev/null +++ b/migration/src/m20230511_161214_remove_columns_statsv2_origin_and_method.rs @@ -0,0 +1,49 @@ +use sea_orm_migration::prelude::*; + +#[derive(DeriveMigrationName)] +pub struct Migration; + +#[async_trait::async_trait] +impl MigrationTrait for Migration { + async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .alter_table( + Table::alter() + .table(RpcAccountingV2::Table) + .drop_column(RpcAccountingV2::Origin) + .drop_column(RpcAccountingV2::Method) + .to_owned(), + ) + .await + } + + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .alter_table( + Table::alter() + .table(RpcAccountingV2::Table) + .add_column( + ColumnDef::new(RpcAccountingV2::Method) + .string() + .not_null() + .default(""), + ) + .add_column( + ColumnDef::new(RpcAccountingV2::Origin) + .string() + .not_null() + .default(""), + ) + .to_owned(), + ) + .await + } +} + +/// Learn more at https://docs.rs/sea-query#iden +#[derive(Iden)] +enum RpcAccountingV2 { + Table, + Origin, + Method, +} From 50c8c4ab7d3bc3bc8d4057f79c68a768ef4a47f7 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Fri, 26 May 2023 16:32:55 -0700 Subject: [PATCH 05/10] Revert "remove stale mod" This reverts commit 1598b64b56200187db19ea4911b7c74780a5211a. --- migration/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/migration/src/lib.rs b/migration/src/lib.rs index c0199867..91c45391 100644 --- a/migration/src/lib.rs +++ b/migration/src/lib.rs @@ -25,6 +25,7 @@ mod m20230221_230953_track_spend; mod m20230307_002623_migrate_rpc_accounting_to_rpc_accounting_v2; mod m20230412_171916_modify_secondary_user_add_primary_user; mod m20230422_172555_premium_downgrade_logic; +mod m20230511_161214_remove_columns_statsv2_origin_and_method; mod m20230512_220213_allow_null_rpc_key_id_in_stats_v2; mod m20230514_114803_admin_add_credits; From 4aa34740a860eeb19772895eefe861a9936cc86b Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Fri, 26 May 2023 16:54:52 -0700 Subject: [PATCH 06/10] default balance to 0 --- web3_proxy/src/frontend/authorization.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/web3_proxy/src/frontend/authorization.rs b/web3_proxy/src/frontend/authorization.rs index dcc3b614..29d2779b 100644 --- a/web3_proxy/src/frontend/authorization.rs +++ b/web3_proxy/src/frontend/authorization.rs @@ -1112,20 +1112,20 @@ impl Web3ProxyApp { let user_model = user::Entity::find_by_id(rpc_key_model.user_id) .one(db_replica.conn()) .await? - .expect("related user"); + .context("no related user")?; let balance = balance::Entity::find() .filter(balance::Column::UserId.eq(user_model.id)) .one(db_replica.conn()) .await? - .expect("related balance") - .available_balance; + .map(|x| x.available_balance) + .unwrap_or_default(); let user_tier_model = user_tier::Entity::find_by_id(user_model.user_tier_id) .one(db_replica.conn()) .await? - .expect("related user tier"); + .context("no related user tier")?; let allowed_ips: Option> = if let Some(allowed_ips) = rpc_key_model.allowed_ips { From 0e7bd1fbf3e96386cfaf5de9763d6918cf583ce6 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Fri, 26 May 2023 17:00:39 -0700 Subject: [PATCH 07/10] add missing anyhow::Context --- web3_proxy/src/frontend/authorization.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/web3_proxy/src/frontend/authorization.rs b/web3_proxy/src/frontend/authorization.rs index 29d2779b..2f9ae0ee 100644 --- a/web3_proxy/src/frontend/authorization.rs +++ b/web3_proxy/src/frontend/authorization.rs @@ -7,6 +7,7 @@ use crate::jsonrpc::{JsonRpcForwardedResponse, JsonRpcRequest}; use crate::rpcs::one::Web3Rpc; use crate::stats::{AppStat, BackendRequests, RpcQueryStats}; use crate::user_token::UserBearerToken; +use anyhow::Context; use axum::headers::authorization::Bearer; use axum::headers::{Header, Origin, Referer, UserAgent}; use chrono::Utc; From 7cb07cc49f4b12fc3f3af8240e342e3f1b239f3a Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Sat, 27 May 2023 01:53:49 -0700 Subject: [PATCH 08/10] debug -> trace for some verbose logs --- web3_proxy/src/rpcs/consensus.rs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/web3_proxy/src/rpcs/consensus.rs b/web3_proxy/src/rpcs/consensus.rs index b7237ccb..2b1103bc 100644 --- a/web3_proxy/src/rpcs/consensus.rs +++ b/web3_proxy/src/rpcs/consensus.rs @@ -138,7 +138,7 @@ impl ConsensusWeb3Rpcs { let head_num = self.head_block.number(); if Some(head_num) >= needed_block_num { - debug!("best (head) block: {}", head_num); + trace!("best (head) block: {}", head_num); return ShouldWaitForBlock::Ready; } } @@ -153,15 +153,14 @@ impl ConsensusWeb3Rpcs { .iter() .any(|rpc| self.rpc_will_work_eventually(rpc, needed_block_num, skip_rpcs)) { - // TODO: too verbose - debug!("everything in this ranking ({:?}) is skipped", next_ranking); + trace!("everything in this ranking ({:?}) is skipped", next_ranking); continue; } let next_head_num = next_ranking.head_num.as_ref(); if next_head_num >= needed_block_num { - debug!("best (head) block: {:?}", next_head_num); + trace!("best (head) block: {:?}", next_head_num); return ShouldWaitForBlock::Ready; } @@ -170,14 +169,12 @@ impl ConsensusWeb3Rpcs { // TODO: this seems wrong if best_num.is_some() { - // TODO: too verbose - debug!("best (old) block: {:?}", best_num); + trace!("best (old) block: {:?}", best_num); ShouldWaitForBlock::Wait { current: best_num.copied(), } } else { - // TODO: too verbose - debug!("never ready"); + trace!("never ready"); ShouldWaitForBlock::NeverReady } } @@ -206,16 +203,16 @@ impl ConsensusWeb3Rpcs { if let Some(rpc_data) = self.rpc_data.get(rpc) { match rpc_data.head_block_num.cmp(needed_block_num) { Ordering::Less => { - debug!("{} is behind. let it catch up", rpc); + trace!("{} is behind. let it catch up", rpc); return true; } Ordering::Greater | Ordering::Equal => { // rpc is synced past the needed block. make sure the block isn't too old for it if self.has_block_data(rpc, needed_block_num) { - debug!("{} has {}", rpc, needed_block_num); + trace!("{} has {}", rpc, needed_block_num); return true; } else { - debug!("{} does not have {}", rpc, needed_block_num); + trace!("{} does not have {}", rpc, needed_block_num); return false; } } From 166b0d810cd25b895560d50d00383a57e1269ad4 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Sun, 28 May 2023 09:38:51 -0700 Subject: [PATCH 09/10] remove cache on /status and /health for now --- web3_proxy/src/frontend/status.rs | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/web3_proxy/src/frontend/status.rs b/web3_proxy/src/frontend/status.rs index 632f2839..b7d69fee 100644 --- a/web3_proxy/src/frontend/status.rs +++ b/web3_proxy/src/frontend/status.rs @@ -31,12 +31,15 @@ pub async fn health( Extension(app): Extension>, Extension(cache): Extension>, ) -> impl IntoResponse { - let (code, content_type, body) = cache - .get_or_insert_async::(&ResponseCacheKey::Health, async move { - Ok(_health(app).await) - }) - .await - .expect("this cache get is infallible"); + // let (code, content_type, body) = cache + // .get_or_insert_async::(&ResponseCacheKey::Health, async move { + // Ok(_health(app).await) + // }) + // .await + // .expect("this cache get is infallible"); + + // TODO: cache this once new TTLs work + let (code, content_type, body) = _health(app).await; Response::builder() .status(code) @@ -115,12 +118,15 @@ pub async fn status( Extension(app): Extension>, Extension(cache): Extension>, ) -> impl IntoResponse { - let (code, content_type, body) = cache - .get_or_insert_async::(&ResponseCacheKey::Status, async move { - Ok(_status(app).await) - }) - .await - .expect("this cache get is infallible"); + // let (code, content_type, body) = cache + // .get_or_insert_async::(&ResponseCacheKey::Status, async move { + // Ok(_status(app).await) + // }) + // .await + // .expect("this cache get is infallible"); + + // TODO: cache this once new TTLs work + let (code, content_type, body) = _status(app).await; Response::builder() .status(code) From 4597967def2f1daa71a277ec6731db4739ead640 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Sun, 28 May 2023 09:39:24 -0700 Subject: [PATCH 10/10] remove cache on backups needed, too --- web3_proxy/src/frontend/status.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/web3_proxy/src/frontend/status.rs b/web3_proxy/src/frontend/status.rs index b7d69fee..b75d7528 100644 --- a/web3_proxy/src/frontend/status.rs +++ b/web3_proxy/src/frontend/status.rs @@ -68,12 +68,15 @@ pub async fn backups_needed( Extension(app): Extension>, Extension(cache): Extension>, ) -> impl IntoResponse { - let (code, content_type, body) = cache - .get_or_insert_async::(&ResponseCacheKey::BackupsNeeded, async move { - Ok(_backups_needed(app).await) - }) - .await - .expect("this cache get is infallible"); + // let (code, content_type, body) = cache + // .get_or_insert_async::(&ResponseCacheKey::BackupsNeeded, async move { + // Ok(_backups_needed(app).await) + // }) + // .await + // .expect("this cache get is infallible"); + + // TODO: cache this once new TTLs work + let (code, content_type, body) = _backups_needed(app).await; Response::builder() .status(code)