From 7c1afbf16735bafa05701a13afb8ec4b5decc404 Mon Sep 17 00:00:00 2001 From: realbigsean Date: Wed, 2 Dec 2020 11:33:48 -0500 Subject: [PATCH 1/2] update status codes for path param parsing errors --- beacon_node/http_api/src/lib.rs | 56 ++++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 7 deletions(-) diff --git a/beacon_node/http_api/src/lib.rs b/beacon_node/http_api/src/lib.rs index 8c3902fcd4d..ea08066344d 100644 --- a/beacon_node/http_api/src/lib.rs +++ b/beacon_node/http_api/src/lib.rs @@ -551,7 +551,13 @@ pub fn serve( let get_beacon_state_validators_id = beacon_states_path .clone() .and(warp::path("validators")) - .and(warp::path::param::()) + .and(warp::path::param::().or_else(|_| { + blocking_task(|| { + Err(warp_utils::reject::custom_bad_request( + "Invalid validator ID".to_string(), + )) + }) + })) .and(warp::path::end()) .and_then( |state_id: StateId, chain: Arc>, validator_id: ValidatorId| { @@ -760,7 +766,13 @@ pub fn serve( let get_beacon_headers_block_id = eth1_v1 .and(warp::path("beacon")) .and(warp::path("headers")) - .and(warp::path::param::()) + .and(warp::path::param::().or_else(|_| { + blocking_task(|| { + Err(warp_utils::reject::custom_bad_request( + "Invalid block ID".to_string(), + )) + }) + })) .and(warp::path::end()) .and(chain_filter.clone()) .and_then(|block_id: BlockId, chain: Arc>| { @@ -845,7 +857,13 @@ pub fn serve( let beacon_blocks_path = eth1_v1 .and(warp::path("beacon")) .and(warp::path("blocks")) - .and(warp::path::param::()) + .and(warp::path::param::().or_else(|_| { + blocking_task(|| { + Err(warp_utils::reject::custom_bad_request( + "Invalid block ID".to_string(), + )) + }) + })) .and(chain_filter.clone()); // GET beacon/blocks/{block_id} @@ -1222,7 +1240,13 @@ pub fn serve( .and(warp::path("debug")) .and(warp::path("beacon")) .and(warp::path("states")) - .and(warp::path::param::()) + .and(warp::path::param::().or_else(|_| { + blocking_task(|| { + Err(warp_utils::reject::custom_bad_request( + "Invalid state ID".to_string(), + )) + }) + })) .and(warp::path::end()) .and(chain_filter.clone()) .and_then(|state_id: StateId, chain: Arc>| { @@ -1531,7 +1555,13 @@ pub fn serve( .and(warp::path("validator")) .and(warp::path("duties")) .and(warp::path("proposer")) - .and(warp::path::param::()) + .and(warp::path::param::().or_else(|_| { + blocking_task(|| { + Err(warp_utils::reject::custom_bad_request( + "Invalid epoch".to_string(), + )) + }) + })) .and(warp::path::end()) .and(not_while_syncing_filter.clone()) .and(chain_filter.clone()) @@ -1596,7 +1626,13 @@ pub fn serve( let get_validator_blocks = eth1_v1 .and(warp::path("validator")) .and(warp::path("blocks")) - .and(warp::path::param::()) + .and(warp::path::param::().or_else(|_| { + blocking_task(|| { + Err(warp_utils::reject::custom_bad_request( + "Invalid slot".to_string(), + )) + }) + })) .and(warp::path::end()) .and(not_while_syncing_filter.clone()) .and(warp::query::()) @@ -1683,7 +1719,13 @@ pub fn serve( .and(warp::path("validator")) .and(warp::path("duties")) .and(warp::path("attester")) - .and(warp::path::param::()) + .and(warp::path::param::().or_else(|_| { + blocking_task(|| { + Err(warp_utils::reject::custom_bad_request( + "Invalid epoch".to_string(), + )) + }) + })) .and(warp::path::end()) .and(not_while_syncing_filter.clone()) .and(warp::body::json()) From 3128555590b8390994a34349e7a0f8d5998a459f Mon Sep 17 00:00:00 2001 From: realbigsean Date: Thu, 3 Dec 2020 12:45:42 -0500 Subject: [PATCH 2/2] dont use blocking tasks for rejections --- beacon_node/http_api/src/lib.rs | 74 +++++++++++++-------------------- 1 file changed, 29 insertions(+), 45 deletions(-) diff --git a/beacon_node/http_api/src/lib.rs b/beacon_node/http_api/src/lib.rs index ea08066344d..159a3d2f041 100644 --- a/beacon_node/http_api/src/lib.rs +++ b/beacon_node/http_api/src/lib.rs @@ -388,12 +388,10 @@ pub fn serve( let beacon_states_path = eth1_v1 .and(warp::path("beacon")) .and(warp::path("states")) - .and(warp::path::param::().or_else(|_| { - blocking_task(|| { - Err(warp_utils::reject::custom_bad_request( - "Invalid state ID".to_string(), - )) - }) + .and(warp::path::param::().or_else(|_| async { + Err(warp_utils::reject::custom_bad_request( + "Invalid state ID".to_string(), + )) })) .and(chain_filter.clone()); @@ -551,12 +549,10 @@ pub fn serve( let get_beacon_state_validators_id = beacon_states_path .clone() .and(warp::path("validators")) - .and(warp::path::param::().or_else(|_| { - blocking_task(|| { - Err(warp_utils::reject::custom_bad_request( - "Invalid validator ID".to_string(), - )) - }) + .and(warp::path::param::().or_else(|_| async { + Err(warp_utils::reject::custom_bad_request( + "Invalid validator ID".to_string(), + )) })) .and(warp::path::end()) .and_then( @@ -766,12 +762,10 @@ pub fn serve( let get_beacon_headers_block_id = eth1_v1 .and(warp::path("beacon")) .and(warp::path("headers")) - .and(warp::path::param::().or_else(|_| { - blocking_task(|| { - Err(warp_utils::reject::custom_bad_request( - "Invalid block ID".to_string(), - )) - }) + .and(warp::path::param::().or_else(|_| async { + Err(warp_utils::reject::custom_bad_request( + "Invalid block ID".to_string(), + )) })) .and(warp::path::end()) .and(chain_filter.clone()) @@ -857,12 +851,10 @@ pub fn serve( let beacon_blocks_path = eth1_v1 .and(warp::path("beacon")) .and(warp::path("blocks")) - .and(warp::path::param::().or_else(|_| { - blocking_task(|| { - Err(warp_utils::reject::custom_bad_request( - "Invalid block ID".to_string(), - )) - }) + .and(warp::path::param::().or_else(|_| async { + Err(warp_utils::reject::custom_bad_request( + "Invalid block ID".to_string(), + )) })) .and(chain_filter.clone()); @@ -1240,12 +1232,10 @@ pub fn serve( .and(warp::path("debug")) .and(warp::path("beacon")) .and(warp::path("states")) - .and(warp::path::param::().or_else(|_| { - blocking_task(|| { - Err(warp_utils::reject::custom_bad_request( - "Invalid state ID".to_string(), - )) - }) + .and(warp::path::param::().or_else(|_| async { + Err(warp_utils::reject::custom_bad_request( + "Invalid state ID".to_string(), + )) })) .and(warp::path::end()) .and(chain_filter.clone()) @@ -1555,12 +1545,10 @@ pub fn serve( .and(warp::path("validator")) .and(warp::path("duties")) .and(warp::path("proposer")) - .and(warp::path::param::().or_else(|_| { - blocking_task(|| { + .and(warp::path::param::().or_else(|_| async { Err(warp_utils::reject::custom_bad_request( "Invalid epoch".to_string(), )) - }) })) .and(warp::path::end()) .and(not_while_syncing_filter.clone()) @@ -1626,12 +1614,10 @@ pub fn serve( let get_validator_blocks = eth1_v1 .and(warp::path("validator")) .and(warp::path("blocks")) - .and(warp::path::param::().or_else(|_| { - blocking_task(|| { - Err(warp_utils::reject::custom_bad_request( - "Invalid slot".to_string(), - )) - }) + .and(warp::path::param::().or_else(|_| async { + Err(warp_utils::reject::custom_bad_request( + "Invalid slot".to_string(), + )) })) .and(warp::path::end()) .and(not_while_syncing_filter.clone()) @@ -1719,12 +1705,10 @@ pub fn serve( .and(warp::path("validator")) .and(warp::path("duties")) .and(warp::path("attester")) - .and(warp::path::param::().or_else(|_| { - blocking_task(|| { - Err(warp_utils::reject::custom_bad_request( - "Invalid epoch".to_string(), - )) - }) + .and(warp::path::param::().or_else(|_| async { + Err(warp_utils::reject::custom_bad_request( + "Invalid epoch".to_string(), + )) })) .and(warp::path::end()) .and(not_while_syncing_filter.clone())