dedicated error for lagged servers
This commit is contained in:
parent
85928b299d
commit
6cb2accd0d
|
@ -3,6 +3,8 @@
|
||||||
use crate::frontend::authorization::Authorization;
|
use crate::frontend::authorization::Authorization;
|
||||||
use crate::jsonrpc::{self, JsonRpcErrorData, ParsedResponse, StreamResponse};
|
use crate::jsonrpc::{self, JsonRpcErrorData, ParsedResponse, StreamResponse};
|
||||||
use crate::response_cache::ForwardedResponse;
|
use crate::response_cache::ForwardedResponse;
|
||||||
|
use crate::rpcs::blockchain::Web3ProxyBlock;
|
||||||
|
use crate::rpcs::one::Web3Rpc;
|
||||||
use crate::rpcs::provider::EthersHttpProvider;
|
use crate::rpcs::provider::EthersHttpProvider;
|
||||||
use axum::extract::rejection::JsonRejection;
|
use axum::extract::rejection::JsonRejection;
|
||||||
use axum::extract::ws::Message;
|
use axum::extract::ws::Message;
|
||||||
|
@ -135,6 +137,10 @@ pub enum Web3ProxyError {
|
||||||
#[from(ignore)]
|
#[from(ignore)]
|
||||||
MethodNotFound(Cow<'static, str>),
|
MethodNotFound(Cow<'static, str>),
|
||||||
NoVolatileRedisDatabase,
|
NoVolatileRedisDatabase,
|
||||||
|
#[error(ignore)]
|
||||||
|
#[from(ignore)]
|
||||||
|
#[display(fmt = "{} @ {}", _0, _1)]
|
||||||
|
OldHead(Arc<Web3Rpc>, Web3ProxyBlock),
|
||||||
OriginRequired,
|
OriginRequired,
|
||||||
#[error(ignore)]
|
#[error(ignore)]
|
||||||
#[from(ignore)]
|
#[from(ignore)]
|
||||||
|
@ -820,6 +826,20 @@ impl Web3ProxyError {
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Self::OldHead(rpc, old_head) => {
|
||||||
|
warn!(?old_head, "{} is lagged", rpc);
|
||||||
|
(
|
||||||
|
StatusCode::BAD_GATEWAY,
|
||||||
|
JsonRpcErrorData {
|
||||||
|
message: "RPC is lagged".into(),
|
||||||
|
code: StatusCode::BAD_REQUEST.as_u16().into(),
|
||||||
|
data: Some(json!({
|
||||||
|
"rpc": rpc.name,
|
||||||
|
"head": old_head,
|
||||||
|
})),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
Self::OriginRequired => {
|
Self::OriginRequired => {
|
||||||
trace!("OriginRequired");
|
trace!("OriginRequired");
|
||||||
(
|
(
|
||||||
|
|
|
@ -642,9 +642,9 @@ impl Web3Rpc {
|
||||||
let head_block = self.head_block_sender.as_ref().unwrap().borrow().clone();
|
let head_block = self.head_block_sender.as_ref().unwrap().borrow().clone();
|
||||||
|
|
||||||
if let Some(head_block) = head_block {
|
if let Some(head_block) = head_block {
|
||||||
// TODO: if head block is very old and not expected to be syncing, emit warning
|
|
||||||
if head_block.age() > self.max_head_block_age {
|
if head_block.age() > self.max_head_block_age {
|
||||||
return Err(anyhow::anyhow!("head_block is too old!").into());
|
// TODO: if the server is expected to be syncing, make a way to quiet this error
|
||||||
|
return Err(Web3ProxyError::OldHead(self.clone(), head_block));
|
||||||
}
|
}
|
||||||
|
|
||||||
if detailed_healthcheck {
|
if detailed_healthcheck {
|
||||||
|
|
Loading…
Reference in New Issue