Skip to content

Commit

Permalink
chore: fast return for invalid request of node health (#5762)
Browse files Browse the repository at this point in the history
Co-authored-by: command-bot <>
  • Loading branch information
yjhmelody authored Sep 19, 2024
1 parent b230b0e commit d31bb8a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
10 changes: 10 additions & 0 deletions prdoc/pr_5762.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
title: Fast return for invalid request of node health

doc:
- audience: Node Dev
description: |
Return directly when invalid request for node health api

crates:
- name: sc-rpc-server
bump: patch
6 changes: 3 additions & 3 deletions substrate/client/rpc-servers/src/middleware/node_health.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,17 @@ where
let fut = self.0.call(req);

async move {
let res = fut.await.map_err(|err| err.into())?;

Ok(match maybe_intercept {
InterceptRequest::Deny =>
http_response(StatusCode::METHOD_NOT_ALLOWED, HttpBody::empty()),
InterceptRequest::No => res,
InterceptRequest::No => fut.await.map_err(|err| err.into())?,
InterceptRequest::Health => {
let res = fut.await.map_err(|err| err.into())?;
let health = parse_rpc_response(res.into_body()).await?;
http_ok_response(serde_json::to_string(&health)?)
},
InterceptRequest::Readiness => {
let res = fut.await.map_err(|err| err.into())?;
let health = parse_rpc_response(res.into_body()).await?;
if (!health.is_syncing && health.peers > 0) || !health.should_have_peers {
http_ok_response(HttpBody::empty())
Expand Down

0 comments on commit d31bb8a

Please sign in to comment.