Merge remote-tracking branch 'origin/main' into devel

This commit is contained in:
Bryan Stitt 2023-05-29 09:42:21 -07:00
commit b05d866f8a
3 changed files with 39 additions and 32 deletions

@ -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;
@ -1112,20 +1113,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<Vec<IpNet>> =
if let Some(allowed_ips) = rpc_key_model.allowed_ips {

@ -31,12 +31,15 @@ pub async fn health(
Extension(app): Extension<Arc<Web3ProxyApp>>,
Extension(cache): Extension<Arc<ResponseCache>>,
) -> impl IntoResponse {
let (code, content_type, body) = cache
.get_or_insert_async::<Infallible, _>(&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::<Infallible, _>(&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)
@ -65,12 +68,15 @@ pub async fn backups_needed(
Extension(app): Extension<Arc<Web3ProxyApp>>,
Extension(cache): Extension<Arc<ResponseCache>>,
) -> impl IntoResponse {
let (code, content_type, body) = cache
.get_or_insert_async::<Infallible, _>(&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::<Infallible, _>(&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)
@ -115,12 +121,15 @@ pub async fn status(
Extension(app): Extension<Arc<Web3ProxyApp>>,
Extension(cache): Extension<Arc<ResponseCache>>,
) -> impl IntoResponse {
let (code, content_type, body) = cache
.get_or_insert_async::<Infallible, _>(&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::<Infallible, _>(&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)

@ -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
}
}
@ -212,10 +209,10 @@ impl ConsensusWeb3Rpcs {
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;
}
}