Skip to content

Commit

Permalink
Appease Clippy 1.68 and refactor http_api (#4068)
Browse files Browse the repository at this point in the history
## Proposed Changes

Two tiny updates to satisfy Clippy 1.68

Plus refactoring of the `http_api` into less complex types so the compiler can chew and digest them more easily.

Co-authored-by: Michael Sproul <michael@sigmaprime.io>
  • Loading branch information
michaelsproul and michaelsproul committed Mar 13, 2023
1 parent 4a1c0c9 commit 90cef1d
Show file tree
Hide file tree
Showing 17 changed files with 164 additions and 133 deletions.
1 change: 0 additions & 1 deletion beacon_node/beacon_chain/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![recursion_limit = "128"] // For lazy-static
pub mod attestation_rewards;
pub mod attestation_verification;
mod attester_cache;
Expand Down
225 changes: 115 additions & 110 deletions beacon_node/http_api/src/lib.rs

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions beacon_node/http_api/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use serde::Serialize;
use types::{
ExecutionOptimisticForkVersionedResponse, ForkName, ForkVersionedResponse, InconsistentFork,
};
use warp::reply::{self, Reply, WithHeader};
use warp::reply::{self, Reply, Response};

pub const V1: EndpointVersion = EndpointVersion(1);
pub const V2: EndpointVersion = EndpointVersion(2);
Expand Down Expand Up @@ -48,8 +48,8 @@ pub fn execution_optimistic_fork_versioned_response<T: Serialize>(
}

/// Add the `Eth-Consensus-Version` header to a response.
pub fn add_consensus_version_header<T: Reply>(reply: T, fork_name: ForkName) -> WithHeader<T> {
reply::with_header(reply, CONSENSUS_VERSION_HEADER, fork_name.to_string())
pub fn add_consensus_version_header<T: Reply>(reply: T, fork_name: ForkName) -> Response {
reply::with_header(reply, CONSENSUS_VERSION_HEADER, fork_name.to_string()).into_response()
}

pub fn inconsistent_fork_rejection(error: InconsistentFork) -> warp::reject::Rejection {
Expand Down
1 change: 0 additions & 1 deletion beacon_node/http_api/tests/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![cfg(not(debug_assertions))] // Tests are too slow in debug.
#![recursion_limit = "256"]

pub mod common;
pub mod fork_tests;
Expand Down
1 change: 0 additions & 1 deletion beacon_node/tests/test.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![cfg(test)]
#![recursion_limit = "512"]

use beacon_chain::StateSkipConfig;
use node_test_rig::{
Expand Down
1 change: 0 additions & 1 deletion common/compare_fields_derive/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![recursion_limit = "256"]
extern crate proc_macro;

use proc_macro::TokenStream;
Expand Down
1 change: 1 addition & 0 deletions common/warp_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ pub mod metrics;
pub mod query;
pub mod reject;
pub mod task;
pub mod uor;
24 changes: 19 additions & 5 deletions common/warp_utils/src/task.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use serde::Serialize;
use warp::reply::{Reply, Response};

/// A convenience wrapper around `blocking_task`.
pub async fn blocking_task<F, T>(func: F) -> Result<T, warp::Rejection>
Expand All @@ -8,16 +9,29 @@ where
{
tokio::task::spawn_blocking(func)
.await
.unwrap_or_else(|_| Err(warp::reject::reject())) // This should really be a 500
.unwrap_or_else(|_| Err(warp::reject::reject()))
}

/// A convenience wrapper around `blocking_task` that returns a `warp::reply::Response`.
///
/// Using this method consistently makes it possible to simplify types using `.unify()` or `.uor()`.
pub async fn blocking_response_task<F, T>(func: F) -> Result<Response, warp::Rejection>
where
F: FnOnce() -> Result<T, warp::Rejection> + Send + 'static,
T: Reply + Send + 'static,
{
blocking_task(func).await.map(Reply::into_response)
}

/// A convenience wrapper around `blocking_task` for use with `warp` JSON responses.
pub async fn blocking_json_task<F, T>(func: F) -> Result<warp::reply::Json, warp::Rejection>
pub async fn blocking_json_task<F, T>(func: F) -> Result<Response, warp::Rejection>
where
F: FnOnce() -> Result<T, warp::Rejection> + Send + 'static,
T: Serialize + Send + 'static,
{
blocking_task(func)
.await
.map(|resp| warp::reply::json(&resp))
blocking_response_task(|| {
let response = func()?;
Ok(warp::reply::json(&response))
})
.await
}
25 changes: 25 additions & 0 deletions common/warp_utils/src/uor.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use warp::{filters::BoxedFilter, Filter, Rejection};

/// Mixin trait for `Filter` providing the unifying-or method.
pub trait UnifyingOrFilter: Filter<Error = Rejection> + Sized + Send + Sync + 'static
where
Self::Extract: Send,
{
/// Unifying `or`.
///
/// This is a shorthand for `self.or(other).unify().boxed()`, which is useful because it keeps
/// the filter type simple and prevents type-checker explosions.
fn uor<F>(self, other: F) -> BoxedFilter<Self::Extract>
where
F: Filter<Extract = Self::Extract, Error = Rejection> + Clone + Send + Sync + 'static,
{
self.or(other).unify().boxed()
}
}

impl<F> UnifyingOrFilter for F
where
F: Filter<Error = Rejection> + Sized + Send + Sync + 'static,
F::Extract: Send,
{
}
1 change: 0 additions & 1 deletion consensus/fork_choice/src/fork_choice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1695,7 +1695,6 @@ mod tests {

fn get_queued_attestations() -> Vec<QueuedAttestation> {
(1..4)
.into_iter()
.map(|i| QueuedAttestation {
slot: Slot::new(i),
attesting_indices: vec![],
Expand Down
1 change: 0 additions & 1 deletion consensus/ssz_derive/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![recursion_limit = "256"]
//! Provides procedural derive macros for the `Encode` and `Decode` traits of the `eth2_ssz` crate.
//!
//! ## Attributes
Expand Down
1 change: 0 additions & 1 deletion consensus/tree_hash_derive/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![recursion_limit = "256"]
use darling::FromDeriveInput;
use proc_macro::TokenStream;
use quote::quote;
Expand Down
2 changes: 0 additions & 2 deletions consensus/types/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
//! Ethereum 2.0 types
// Required for big type-level numbers
#![recursion_limit = "128"]
// Clippy lint set up
#![cfg_attr(
not(test),
Expand Down
2 changes: 1 addition & 1 deletion crypto/bls/src/generic_aggregate_signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ where
}

/// Hashes the `self.serialize()` bytes.
#[allow(clippy::derive_hash_xor_eq)]
#[allow(clippy::derived_hash_with_manual_eq)]
impl<Pub, AggPub, Sig, AggSig> Hash for GenericAggregateSignature<Pub, AggPub, Sig, AggSig>
where
Sig: TSignature<Pub>,
Expand Down
2 changes: 0 additions & 2 deletions lighthouse/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![recursion_limit = "256"]

mod metrics;

use beacon_node::ProductionBeaconNode;
Expand Down
1 change: 0 additions & 1 deletion testing/execution_engine_integration/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![recursion_limit = "1024"]
/// This binary runs integration tests between Lighthouse and execution engines.
///
/// It will first attempt to build any supported integration clients, then it will run tests.
Expand Down
2 changes: 0 additions & 2 deletions testing/simulator/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![recursion_limit = "256"]

//! This crate provides a simluation that creates `n` beacon node and validator clients, each with
//! `v` validators. A deposit contract is deployed at the start of the simulation using a local
//! `ganache` instance (you must have `ganache` installed and avaliable on your path). All
Expand Down

0 comments on commit 90cef1d

Please sign in to comment.