send UNAUTHORIZED to unknown keys
This commit is contained in:
parent
7ff319e9b0
commit
05e94ff81c
@ -24,6 +24,7 @@ pub enum FrontendErrorResponse {
|
||||
Database(DbErr),
|
||||
RateLimitedUser(u64, Option<Instant>),
|
||||
RateLimitedIp(IpAddr, Option<Instant>),
|
||||
UnknownKey,
|
||||
NotFound,
|
||||
}
|
||||
|
||||
@ -117,6 +118,14 @@ impl IntoResponse for FrontendErrorResponse {
|
||||
),
|
||||
)
|
||||
}
|
||||
Self::UnknownKey => (
|
||||
StatusCode::UNAUTHORIZED,
|
||||
JsonRpcForwardedResponse::from_str(
|
||||
"unknown api key!",
|
||||
Some(StatusCode::UNAUTHORIZED.as_u16().into()),
|
||||
None,
|
||||
),
|
||||
),
|
||||
Self::NotFound => {
|
||||
// TODO: emit a stat?
|
||||
(
|
||||
|
@ -8,6 +8,7 @@ use tracing::instrument;
|
||||
/// Health check page for load balancers to use
|
||||
#[instrument(skip_all)]
|
||||
pub async fn health(Extension(app): Extension<Arc<Web3ProxyApp>>) -> impl IntoResponse {
|
||||
// TODO: also check that the head block is not too old
|
||||
if app.balanced_rpcs.synced() {
|
||||
(StatusCode::OK, "OK")
|
||||
} else {
|
||||
@ -26,10 +27,10 @@ pub async fn prometheus(Extension(app): Extension<Arc<Web3ProxyApp>>) -> impl In
|
||||
/// TODO: replace this with proper stats and monitoring
|
||||
#[instrument(skip_all)]
|
||||
pub async fn status(Extension(app): Extension<Arc<Web3ProxyApp>>) -> impl IntoResponse {
|
||||
// TODO: what else should we include? uptime?
|
||||
app.pending_transactions.sync();
|
||||
app.user_cache.sync();
|
||||
|
||||
// TODO: what else should we include? uptime, cache hit rates, cpu load
|
||||
let body = json!({
|
||||
"pending_transactions_count": app.pending_transactions.entry_count(),
|
||||
"pending_transactions_size": app.pending_transactions.weighted_size(),
|
||||
|
@ -29,6 +29,7 @@ pub async fn rate_limit_by_ip(
|
||||
RateLimitResult::RateLimitedIp(x, retry_at) => {
|
||||
Err(FrontendErrorResponse::RateLimitedIp(x, retry_at))
|
||||
}
|
||||
// TODO: don't panic. give the user an error
|
||||
x => unimplemented!("rate_limit_by_ip shouldn't ever see these: {:?}", x),
|
||||
}
|
||||
}
|
||||
@ -43,6 +44,8 @@ pub async fn rate_limit_by_key(
|
||||
RateLimitResult::RateLimitedUser(x, retry_at) => {
|
||||
Err(FrontendErrorResponse::RateLimitedUser(x, retry_at))
|
||||
}
|
||||
RateLimitResult::UnknownKey => Err(FrontendErrorResponse::UnknownKey),
|
||||
// TODO: don't panic. give the user an error
|
||||
x => unimplemented!("rate_limit_by_key shouldn't ever see these: {:?}", x),
|
||||
}
|
||||
}
|
||||
|
@ -281,19 +281,19 @@ impl Web3Connections {
|
||||
// iterate the known heads to find the highest_work_block
|
||||
let mut checked_heads = HashSet::new();
|
||||
let mut highest_work_block: Option<ArcBlock> = None;
|
||||
for (conn_name, conn_head_hash) in connection_heads.iter() {
|
||||
if checked_heads.contains(conn_head_hash) {
|
||||
for (conn_name, connection_head_hash) in connection_heads.iter() {
|
||||
if checked_heads.contains(connection_head_hash) {
|
||||
// we already checked this head from another rpc
|
||||
continue;
|
||||
}
|
||||
// don't check the same hash multiple times
|
||||
checked_heads.insert(conn_head_hash);
|
||||
checked_heads.insert(connection_head_hash);
|
||||
|
||||
let conn_head_block = if let Some(x) = self.block_hashes.get(conn_head_hash) {
|
||||
let conn_head_block = if let Some(x) = self.block_hashes.get(connection_head_hash) {
|
||||
x
|
||||
} else {
|
||||
// TODO: why does this happen?
|
||||
warn!(%conn_head_hash, %conn_name, %rpc, "Missing block in connection_heads");
|
||||
warn!(%connection_head_hash, %conn_name, %rpc, "Missing connection_head_block in block_hashes");
|
||||
continue;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user