From 5bb635d17fb68c1268fd8adf495087a532c197e3 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Tue, 7 Mar 2023 03:06:52 +0000 Subject: [PATCH 1/5] Set Capella fork epoch for Goerli (#4044) ## Issue Addressed NA ## Proposed Changes Sets the Capella fork epoch as per https://github.com/eth-clients/goerli/pull/160. The fork will occur at: - Epoch: 162304 - Slot: 5193728 - UTC: 14/03/2023, 10:25:36 pm ## Additional Info - [x] Blocked on https://github.com/eth-clients/goerli/pull/160 being merged --- .../built_in_network_configs/prater/config.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/common/eth2_network_config/built_in_network_configs/prater/config.yaml b/common/eth2_network_config/built_in_network_configs/prater/config.yaml index d173be20de5..69d65ca8fc8 100644 --- a/common/eth2_network_config/built_in_network_configs/prater/config.yaml +++ b/common/eth2_network_config/built_in_network_configs/prater/config.yaml @@ -35,8 +35,11 @@ ALTAIR_FORK_EPOCH: 36660 # Merge BELLATRIX_FORK_VERSION: 0x02001020 BELLATRIX_FORK_EPOCH: 112260 +# Capella +CAPELLA_FORK_VERSION: 0x03001020 +CAPELLA_FORK_EPOCH: 162304 # Sharding -SHARDING_FORK_VERSION: 0x03001020 +SHARDING_FORK_VERSION: 0x04001020 SHARDING_FORK_EPOCH: 18446744073709551615 # TBD, 2**32 is a placeholder. Merge transition approach is in active R&D. From 4c109115cabed2492aff1d1822d60129ce5fd5d7 Mon Sep 17 00:00:00 2001 From: Daniel Ramirez Chiquillo Date: Tue, 7 Mar 2023 05:37:28 +0000 Subject: [PATCH 2/5] Add a flag to always use payloads from builders (#4052) ## Issue Addressed #4040 ## Proposed Changes - Add the `always_prefer_builder_payload` field to `Config` in `beacon_node/client/src/config.rs`. - Add that same field to `Inner` in `beacon_node/execution_layer/src/lib.rs` - Modify the logic for picking the payload in `beacon_node/execution_layer/src/lib.rs` - Add the `always-prefer-builder-payload` flag to the beacon node CLI - Test the new flags in `lighthouse/tests/beacon_node.rs` Co-authored-by: Paul Hauner --- beacon_node/client/src/config.rs | 2 ++ beacon_node/execution_layer/src/lib.rs | 8 +++++++- beacon_node/src/cli.rs | 9 +++++++++ beacon_node/src/config.rs | 5 +++++ beacon_node/tests/test.rs | 2 +- lighthouse/tests/beacon_node.rs | 15 +++++++++++++++ 6 files changed, 39 insertions(+), 2 deletions(-) diff --git a/beacon_node/client/src/config.rs b/beacon_node/client/src/config.rs index 22b868256ad..95a00b37492 100644 --- a/beacon_node/client/src/config.rs +++ b/beacon_node/client/src/config.rs @@ -79,6 +79,7 @@ pub struct Config { pub monitoring_api: Option, pub slasher: Option, pub logger_config: LoggerConfig, + pub always_prefer_builder_payload: bool, } impl Default for Config { @@ -105,6 +106,7 @@ impl Default for Config { validator_monitor_pubkeys: vec![], validator_monitor_individual_tracking_threshold: DEFAULT_INDIVIDUAL_TRACKING_THRESHOLD, logger_config: LoggerConfig::default(), + always_prefer_builder_payload: false, } } } diff --git a/beacon_node/execution_layer/src/lib.rs b/beacon_node/execution_layer/src/lib.rs index 46da4a67d9f..d12f9996d87 100644 --- a/beacon_node/execution_layer/src/lib.rs +++ b/beacon_node/execution_layer/src/lib.rs @@ -219,6 +219,7 @@ struct Inner { payload_cache: PayloadCache, builder_profit_threshold: Uint256, log: Logger, + always_prefer_builder_payload: bool, } #[derive(Debug, Default, Clone, Serialize, Deserialize)] @@ -241,6 +242,7 @@ pub struct Config { /// The minimum value of an external payload for it to be considered in a proposal. pub builder_profit_threshold: u128, pub execution_timeout_multiplier: Option, + pub always_prefer_builder_payload: bool, } /// Provides access to one execution engine and provides a neat interface for consumption by the @@ -263,6 +265,7 @@ impl ExecutionLayer { default_datadir, builder_profit_threshold, execution_timeout_multiplier, + always_prefer_builder_payload, } = config; if urls.len() > 1 { @@ -335,6 +338,7 @@ impl ExecutionLayer { payload_cache: PayloadCache::default(), builder_profit_threshold: Uint256::from(builder_profit_threshold), log, + always_prefer_builder_payload, }; Ok(Self { @@ -796,7 +800,9 @@ impl ExecutionLayer { let relay_value = relay.data.message.value; let local_value = *local.block_value(); - if local_value >= relay_value { + if !self.inner.always_prefer_builder_payload + && local_value >= relay_value + { info!( self.log(), "Local block is more profitable than relay block"; diff --git a/beacon_node/src/cli.rs b/beacon_node/src/cli.rs index bc2e705cb34..792d6253482 100644 --- a/beacon_node/src/cli.rs +++ b/beacon_node/src/cli.rs @@ -957,4 +957,13 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> { This is equivalent to --http and --validator-monitor-auto.") .takes_value(false) ) + .arg( + Arg::with_name("always-prefer-builder-payload") + .long("always-prefer-builder-payload") + .help("If set, the beacon node always uses the payload from the builder instead of the local payload.") + // The builder profit threshold flag is used to provide preference + // to local payloads, therefore it fundamentally conflicts with + // always using the builder. + .conflicts_with("builder-profit-threshold") + ) } diff --git a/beacon_node/src/config.rs b/beacon_node/src/config.rs index fa0344e9579..55335081cb7 100644 --- a/beacon_node/src/config.rs +++ b/beacon_node/src/config.rs @@ -753,6 +753,11 @@ pub fn get_config( client_config.chain.optimistic_finalized_sync = !cli_args.is_present("disable-optimistic-finalized-sync"); + // Payload selection configs + if cli_args.is_present("always-prefer-builder-payload") { + client_config.always_prefer_builder_payload = true; + } + Ok(client_config) } diff --git a/beacon_node/tests/test.rs b/beacon_node/tests/test.rs index 1c11a8349dd..8ccb260d29b 100644 --- a/beacon_node/tests/test.rs +++ b/beacon_node/tests/test.rs @@ -1,5 +1,5 @@ #![cfg(test)] -#![recursion_limit = "256"] +#![recursion_limit = "512"] use beacon_chain::StateSkipConfig; use node_test_rig::{ diff --git a/lighthouse/tests/beacon_node.rs b/lighthouse/tests/beacon_node.rs index bdaec9948b8..7f957b626db 100644 --- a/lighthouse/tests/beacon_node.rs +++ b/lighthouse/tests/beacon_node.rs @@ -340,6 +340,21 @@ fn trusted_peers_flag() { }); } +#[test] +fn always_prefer_builder_payload_flag() { + CommandLineTest::new() + .flag("always-prefer-builder-payload", None) + .run_with_zero_port() + .with_config(|config| assert!(config.always_prefer_builder_payload)); +} + +#[test] +fn no_flag_sets_always_prefer_builder_payload_to_false() { + CommandLineTest::new() + .run_with_zero_port() + .with_config(|config| assert!(!config.always_prefer_builder_payload)); +} + // Tests for Eth1 flags. #[test] fn dummy_eth1_flag() { From 319cc61afeb1dbf3692e280dfa18e7b455542b16 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Tue, 7 Mar 2023 07:57:39 +0000 Subject: [PATCH 3/5] Release v3.5.1 (#4049) ## Issue Addressed NA ## Proposed Changes Bumps versions to v3.5.1. ## Additional Info - [x] Requires further testing --- Cargo.lock | 8 ++++---- beacon_node/Cargo.toml | 2 +- boot_node/Cargo.toml | 2 +- common/lighthouse_version/src/lib.rs | 4 ++-- lcli/Cargo.toml | 2 +- lighthouse/Cargo.toml | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 70dc4227a1e..5951b49c7e9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -617,7 +617,7 @@ dependencies = [ [[package]] name = "beacon_node" -version = "3.5.0" +version = "3.5.1" dependencies = [ "beacon_chain", "clap", @@ -785,7 +785,7 @@ dependencies = [ [[package]] name = "boot_node" -version = "3.5.0" +version = "3.5.1" dependencies = [ "beacon_node", "clap", @@ -3750,7 +3750,7 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "lcli" -version = "3.5.0" +version = "3.5.1" dependencies = [ "account_utils", "beacon_chain", @@ -4354,7 +4354,7 @@ dependencies = [ [[package]] name = "lighthouse" -version = "3.5.0" +version = "3.5.1" dependencies = [ "account_manager", "account_utils", diff --git a/beacon_node/Cargo.toml b/beacon_node/Cargo.toml index 3c37f41de68..521e2b89c19 100644 --- a/beacon_node/Cargo.toml +++ b/beacon_node/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "beacon_node" -version = "3.5.0" +version = "3.5.1" authors = ["Paul Hauner ", "Age Manning "] edition = "2021" diff --git a/common/lighthouse_version/src/lib.rs b/common/lighthouse_version/src/lib.rs index 8ad4aa86f31..10d1a8c3259 100644 --- a/common/lighthouse_version/src/lib.rs +++ b/common/lighthouse_version/src/lib.rs @@ -17,8 +17,8 @@ pub const VERSION: &str = git_version!( // NOTE: using --match instead of --exclude for compatibility with old Git "--match=thiswillnevermatchlol" ], - prefix = "Lighthouse/v3.5.0-", - fallback = "Lighthouse/v3.5.0" + prefix = "Lighthouse/v3.5.1-", + fallback = "Lighthouse/v3.5.1" ); /// Returns `VERSION`, but with platform information appended to the end. diff --git a/lcli/Cargo.toml b/lcli/Cargo.toml index 93fe17506bf..caceb997786 100644 --- a/lcli/Cargo.toml +++ b/lcli/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "lcli" description = "Lighthouse CLI (modeled after zcli)" -version = "3.5.0" +version = "3.5.1" authors = ["Paul Hauner "] edition = "2021" diff --git a/lighthouse/Cargo.toml b/lighthouse/Cargo.toml index ecac53fb147..9360c960083 100644 --- a/lighthouse/Cargo.toml +++ b/lighthouse/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lighthouse" -version = "3.5.0" +version = "3.5.1" authors = ["Sigma Prime "] edition = "2021" autotests = false From 4a1c0c96be26f287f435439679cabe4e98b805b9 Mon Sep 17 00:00:00 2001 From: Alex Wied Date: Mon, 13 Mar 2023 01:40:01 +0000 Subject: [PATCH 4/5] Fix order of arguments to log_count (#4060) See: https://github.com/sigp/lighthouse/pull/4027 ## Proposed Changes The order of the arguments to `log_count` is swapped in `beacon_node/beacon_chain/src/events.rs`. --- beacon_node/beacon_chain/src/events.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/beacon_node/beacon_chain/src/events.rs b/beacon_node/beacon_chain/src/events.rs index b3fa6627f74..fed05032374 100644 --- a/beacon_node/beacon_chain/src/events.rs +++ b/beacon_node/beacon_chain/src/events.rs @@ -65,43 +65,43 @@ impl ServerSentEventHandler { EventKind::Attestation(_) => self .attestation_tx .send(kind) - .map(|count| log_count(count, "attestation")), + .map(|count| log_count("attestation", count)), EventKind::Block(_) => self .block_tx .send(kind) - .map(|count| log_count(count, "block")), + .map(|count| log_count("block", count)), EventKind::FinalizedCheckpoint(_) => self .finalized_tx .send(kind) - .map(|count| log_count(count, "finalized checkpoint")), + .map(|count| log_count("finalized checkpoint", count)), EventKind::Head(_) => self .head_tx .send(kind) - .map(|count| log_count(count, "head")), + .map(|count| log_count("head", count)), EventKind::VoluntaryExit(_) => self .exit_tx .send(kind) - .map(|count| log_count(count, "exit")), + .map(|count| log_count("exit", count)), EventKind::ChainReorg(_) => self .chain_reorg_tx .send(kind) - .map(|count| log_count(count, "chain reorg")), + .map(|count| log_count("chain reorg", count)), EventKind::ContributionAndProof(_) => self .contribution_tx .send(kind) - .map(|count| log_count(count, "contribution and proof")), + .map(|count| log_count("contribution and proof", count)), EventKind::PayloadAttributes(_) => self .payload_attributes_tx .send(kind) - .map(|count| log_count(count, "payload attributes")), + .map(|count| log_count("payload attributes", count)), EventKind::LateHead(_) => self .late_head .send(kind) - .map(|count| log_count(count, "late head")), + .map(|count| log_count("late head", count)), EventKind::BlockReward(_) => self .block_reward_tx .send(kind) - .map(|count| log_count(count, "block reward")), + .map(|count| log_count("block reward", count)), }; if let Err(SendError(event)) = result { trace!(self.log, "No receivers registered to listen for event"; "event" => ?event); From 90cef1db868378ae7a10189b960b62bbc21b7fe6 Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Mon, 13 Mar 2023 01:40:03 +0000 Subject: [PATCH 5/5] Appease Clippy 1.68 and refactor `http_api` (#4068) ## 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 --- beacon_node/beacon_chain/src/lib.rs | 1 - beacon_node/http_api/src/lib.rs | 225 +++++++++--------- beacon_node/http_api/src/version.rs | 6 +- beacon_node/http_api/tests/main.rs | 1 - beacon_node/tests/test.rs | 1 - common/compare_fields_derive/src/lib.rs | 1 - common/warp_utils/src/lib.rs | 1 + common/warp_utils/src/task.rs | 24 +- common/warp_utils/src/uor.rs | 25 ++ consensus/fork_choice/src/fork_choice.rs | 1 - consensus/ssz_derive/src/lib.rs | 1 - consensus/tree_hash_derive/src/lib.rs | 1 - consensus/types/src/lib.rs | 2 - crypto/bls/src/generic_aggregate_signature.rs | 2 +- lighthouse/src/main.rs | 2 - .../execution_engine_integration/src/main.rs | 1 - testing/simulator/src/main.rs | 2 - 17 files changed, 164 insertions(+), 133 deletions(-) create mode 100644 common/warp_utils/src/uor.rs diff --git a/beacon_node/beacon_chain/src/lib.rs b/beacon_node/beacon_chain/src/lib.rs index 0f94c651aaf..173ce13b4a1 100644 --- a/beacon_node/beacon_chain/src/lib.rs +++ b/beacon_node/beacon_chain/src/lib.rs @@ -1,4 +1,3 @@ -#![recursion_limit = "128"] // For lazy-static pub mod attestation_rewards; pub mod attestation_verification; mod attester_cache; diff --git a/beacon_node/http_api/src/lib.rs b/beacon_node/http_api/src/lib.rs index 6cca673b85e..05fe2fe1040 100644 --- a/beacon_node/http_api/src/lib.rs +++ b/beacon_node/http_api/src/lib.rs @@ -1,4 +1,3 @@ -#![recursion_limit = "256"] //! This crate contains a HTTP server which serves the endpoints listed here: //! //! https://github.com/ethereum/beacon-APIs @@ -71,7 +70,8 @@ use warp::Reply; use warp::{http::Response, Filter}; use warp_utils::{ query::multi_key_query, - task::{blocking_json_task, blocking_task}, + task::{blocking_json_task, blocking_response_task}, + uor::UnifyingOrFilter, }; const API_PREFIX: &str = "eth"; @@ -1125,7 +1125,7 @@ pub fn serve( log: Logger| async move { publish_blocks::publish_block(None, block, chain, &network_tx, log) .await - .map(|()| warp::reply()) + .map(|()| warp::reply().into_response()) }, ); @@ -1149,7 +1149,7 @@ pub fn serve( log: Logger| async move { publish_blocks::publish_blinded_block(block, chain, &network_tx, log) .await - .map(|()| warp::reply()) + .map(|()| warp::reply().into_response()) }, ); @@ -1255,7 +1255,7 @@ pub fn serve( |block_id: BlockId, chain: Arc>, accept_header: Option| { - blocking_task(move || { + blocking_response_task(move || { let (block, execution_optimistic) = block_id.blinded_block(&chain)?; let fork_name = block .fork_name(&chain.spec) @@ -1767,7 +1767,7 @@ pub fn serve( .and(eth1_service_filter.clone()) .and_then( |accept_header: Option, eth1_service: eth1::Service| { - blocking_task(move || match accept_header { + blocking_response_task(move || match accept_header { Some(api_types::Accept::Json) | None => { let snapshot = eth1_service.get_deposit_snapshot(); Ok( @@ -1986,7 +1986,7 @@ pub fn serve( state_id: StateId, accept_header: Option, chain: Arc>| { - blocking_task(move || match accept_header { + blocking_response_task(move || match accept_header { Some(api_types::Accept::Ssz) => { // We can ignore the optimistic status for the "fork" since it's a // specification constant that doesn't change across competing heads of the @@ -1999,7 +1999,9 @@ pub fn serve( .status(200) .header("Content-Type", "application/octet-stream") .body(state.as_ssz_bytes().into()) - .map(|resp| add_consensus_version_header(resp, fork_name)) + .map(|resp: warp::reply::Response| { + add_consensus_version_header(resp, fork_name) + }) .map_err(|e| { warp_utils::reject::custom_server_error(format!( "failed to create response: {}", @@ -2162,7 +2164,7 @@ pub fn serve( .and(warp::path::end()) .and(network_globals.clone()) .and_then(|network_globals: Arc>| { - blocking_task(move || match *network_globals.sync_state.read() { + blocking_response_task(move || match *network_globals.sync_state.read() { SyncState::SyncingFinalized { .. } | SyncState::SyncingHead { .. } | SyncState::SyncTransition @@ -2426,7 +2428,7 @@ pub fn serve( .map_err(inconsistent_fork_rejection)?; fork_versioned_response(endpoint_version, fork_name, block) - .map(|response| warp::reply::json(&response)) + .map(|response| warp::reply::json(&response).into_response()) }, ); @@ -2483,7 +2485,7 @@ pub fn serve( // Pose as a V2 endpoint so we return the fork `version`. fork_versioned_response(V2, fork_name, block) - .map(|response| warp::reply::json(&response)) + .map(|response| warp::reply::json(&response).into_response()) }, ); @@ -2856,7 +2858,7 @@ pub fn serve( )) })?; - Ok::<_, warp::reject::Rejection>(warp::reply::json(&())) + Ok::<_, warp::reject::Rejection>(warp::reply::json(&()).into_response()) }, ); @@ -2965,7 +2967,7 @@ pub fn serve( builder .post_builder_validators(&filtered_registration_data) .await - .map(|resp| warp::reply::json(&resp)) + .map(|resp| warp::reply::json(&resp).into_response()) .map_err(|e| { warn!( log, @@ -3227,7 +3229,7 @@ pub fn serve( .and(warp::path::end()) .and(chain_filter.clone()) .and_then(|chain: Arc>| { - blocking_task(move || { + blocking_response_task(move || { Ok::<_, warp::Rejection>(warp::reply::json(&api_types::GenericResponseRef::from( chain .canonical_head @@ -3346,7 +3348,7 @@ pub fn serve( .and(warp::path::end()) .and(chain_filter.clone()) .and_then(|state_id: StateId, chain: Arc>| { - blocking_task(move || { + blocking_response_task(move || { // This debug endpoint provides no indication of optimistic status. let (state, _execution_optimistic) = state_id.state(&chain)?; Response::builder() @@ -3482,9 +3484,10 @@ pub fn serve( .and(chain_filter.clone()) .and_then(|chain: Arc>| async move { let merge_readiness = chain.check_merge_readiness().await; - Ok::<_, warp::reject::Rejection>(warp::reply::json(&api_types::GenericResponse::from( - merge_readiness, - ))) + Ok::<_, warp::reject::Rejection>( + warp::reply::json(&api_types::GenericResponse::from(merge_readiness)) + .into_response(), + ) }); let get_events = eth_v1 @@ -3495,7 +3498,7 @@ pub fn serve( .and_then( |topics_res: Result, chain: Arc>| { - blocking_task(move || { + blocking_response_task(move || { let topics = topics_res?; // for each topic subscribed spawn a new subscription let mut receivers = Vec::with_capacity(topics.topics.len()); @@ -3562,108 +3565,110 @@ pub fn serve( ); // Define the ultimate set of routes that will be provided to the server. + // Use `uor` rather than `or` in order to simplify types (see `UnifyingOrFilter`). let routes = warp::get() .and( get_beacon_genesis - .boxed() - .or(get_beacon_state_root.boxed()) - .or(get_beacon_state_fork.boxed()) - .or(get_beacon_state_finality_checkpoints.boxed()) - .or(get_beacon_state_validator_balances.boxed()) - .or(get_beacon_state_validators_id.boxed()) - .or(get_beacon_state_validators.boxed()) - .or(get_beacon_state_committees.boxed()) - .or(get_beacon_state_sync_committees.boxed()) - .or(get_beacon_state_randao.boxed()) - .or(get_beacon_headers.boxed()) - .or(get_beacon_headers_block_id.boxed()) - .or(get_beacon_block.boxed()) - .or(get_beacon_block_attestations.boxed()) - .or(get_beacon_blinded_block.boxed()) - .or(get_beacon_block_root.boxed()) - .or(get_beacon_pool_attestations.boxed()) - .or(get_beacon_pool_attester_slashings.boxed()) - .or(get_beacon_pool_proposer_slashings.boxed()) - .or(get_beacon_pool_voluntary_exits.boxed()) - .or(get_beacon_pool_bls_to_execution_changes.boxed()) - .or(get_beacon_deposit_snapshot.boxed()) - .or(get_beacon_rewards_blocks.boxed()) - .or(get_config_fork_schedule.boxed()) - .or(get_config_spec.boxed()) - .or(get_config_deposit_contract.boxed()) - .or(get_debug_beacon_states.boxed()) - .or(get_debug_beacon_heads.boxed()) - .or(get_node_identity.boxed()) - .or(get_node_version.boxed()) - .or(get_node_syncing.boxed()) - .or(get_node_health.boxed()) - .or(get_node_peers_by_id.boxed()) - .or(get_node_peers.boxed()) - .or(get_node_peer_count.boxed()) - .or(get_validator_duties_proposer.boxed()) - .or(get_validator_blocks.boxed()) - .or(get_validator_blinded_blocks.boxed()) - .or(get_validator_attestation_data.boxed()) - .or(get_validator_aggregate_attestation.boxed()) - .or(get_validator_sync_committee_contribution.boxed()) - .or(get_lighthouse_health.boxed()) - .or(get_lighthouse_ui_health.boxed()) - .or(get_lighthouse_ui_validator_count.boxed()) - .or(get_lighthouse_syncing.boxed()) - .or(get_lighthouse_nat.boxed()) - .or(get_lighthouse_peers.boxed()) - .or(get_lighthouse_peers_connected.boxed()) - .or(get_lighthouse_proto_array.boxed()) - .or(get_lighthouse_validator_inclusion_global.boxed()) - .or(get_lighthouse_validator_inclusion.boxed()) - .or(get_lighthouse_eth1_syncing.boxed()) - .or(get_lighthouse_eth1_block_cache.boxed()) - .or(get_lighthouse_eth1_deposit_cache.boxed()) - .or(get_lighthouse_beacon_states_ssz.boxed()) - .or(get_lighthouse_staking.boxed()) - .or(get_lighthouse_database_info.boxed()) - .or(get_lighthouse_block_rewards.boxed()) - .or(get_lighthouse_attestation_performance.boxed()) - .or(get_lighthouse_block_packing_efficiency.boxed()) - .or(get_lighthouse_merge_readiness.boxed()) - .or(get_events.boxed()) + .uor(get_beacon_state_root) + .uor(get_beacon_state_fork) + .uor(get_beacon_state_finality_checkpoints) + .uor(get_beacon_state_validator_balances) + .uor(get_beacon_state_validators_id) + .uor(get_beacon_state_validators) + .uor(get_beacon_state_committees) + .uor(get_beacon_state_sync_committees) + .uor(get_beacon_state_randao) + .uor(get_beacon_headers) + .uor(get_beacon_headers_block_id) + .uor(get_beacon_block) + .uor(get_beacon_block_attestations) + .uor(get_beacon_blinded_block) + .uor(get_beacon_block_root) + .uor(get_beacon_pool_attestations) + .uor(get_beacon_pool_attester_slashings) + .uor(get_beacon_pool_proposer_slashings) + .uor(get_beacon_pool_voluntary_exits) + .uor(get_beacon_pool_bls_to_execution_changes) + .uor(get_beacon_deposit_snapshot) + .uor(get_beacon_rewards_blocks) + .uor(get_config_fork_schedule) + .uor(get_config_spec) + .uor(get_config_deposit_contract) + .uor(get_debug_beacon_states) + .uor(get_debug_beacon_heads) + .uor(get_node_identity) + .uor(get_node_version) + .uor(get_node_syncing) + .uor(get_node_health) + .uor(get_node_peers_by_id) + .uor(get_node_peers) + .uor(get_node_peer_count) + .uor(get_validator_duties_proposer) + .uor(get_validator_blocks) + .uor(get_validator_blinded_blocks) + .uor(get_validator_attestation_data) + .uor(get_validator_aggregate_attestation) + .uor(get_validator_sync_committee_contribution) + .uor(get_lighthouse_health) + .uor(get_lighthouse_ui_health) + .uor(get_lighthouse_ui_validator_count) + .uor(get_lighthouse_syncing) + .uor(get_lighthouse_nat) + .uor(get_lighthouse_peers) + .uor(get_lighthouse_peers_connected) + .uor(get_lighthouse_proto_array) + .uor(get_lighthouse_validator_inclusion_global) + .uor(get_lighthouse_validator_inclusion) + .uor(get_lighthouse_eth1_syncing) + .uor(get_lighthouse_eth1_block_cache) + .uor(get_lighthouse_eth1_deposit_cache) + .uor(get_lighthouse_beacon_states_ssz) + .uor(get_lighthouse_staking) + .uor(get_lighthouse_database_info) + .uor(get_lighthouse_block_rewards) + .uor(get_lighthouse_attestation_performance) + .uor(get_lighthouse_block_packing_efficiency) + .uor(get_lighthouse_merge_readiness) + .uor(get_events) .recover(warp_utils::reject::handle_rejection), ) .boxed() - .or(warp::post().and( - post_beacon_blocks - .boxed() - .or(post_beacon_blinded_blocks.boxed()) - .or(post_beacon_pool_attestations.boxed()) - .or(post_beacon_pool_attester_slashings.boxed()) - .or(post_beacon_pool_proposer_slashings.boxed()) - .or(post_beacon_pool_voluntary_exits.boxed()) - .or(post_beacon_pool_sync_committees.boxed()) - .or(post_beacon_pool_bls_to_execution_changes.boxed()) - .or(post_beacon_rewards_attestations.boxed()) - .or(post_beacon_rewards_sync_committee.boxed()) - .or(post_validator_duties_attester.boxed()) - .or(post_validator_duties_sync.boxed()) - .or(post_validator_aggregate_and_proofs.boxed()) - .or(post_validator_contribution_and_proofs.boxed()) - .or(post_validator_beacon_committee_subscriptions.boxed()) - .or(post_validator_sync_committee_subscriptions.boxed()) - .or(post_validator_prepare_beacon_proposer.boxed()) - .or(post_validator_register_validator.boxed()) - .or(post_lighthouse_liveness.boxed()) - .or(post_lighthouse_database_reconstruct.boxed()) - .or(post_lighthouse_database_historical_blocks.boxed()) - .or(post_lighthouse_block_rewards.boxed()) - .or(post_lighthouse_ui_validator_metrics.boxed()) - .or(post_lighthouse_ui_validator_info.boxed()) - .recover(warp_utils::reject::handle_rejection), - )) + .uor( + warp::post().and( + post_beacon_blocks + .uor(post_beacon_blinded_blocks) + .uor(post_beacon_pool_attestations) + .uor(post_beacon_pool_attester_slashings) + .uor(post_beacon_pool_proposer_slashings) + .uor(post_beacon_pool_voluntary_exits) + .uor(post_beacon_pool_sync_committees) + .uor(post_beacon_pool_bls_to_execution_changes) + .uor(post_beacon_rewards_attestations) + .uor(post_beacon_rewards_sync_committee) + .uor(post_validator_duties_attester) + .uor(post_validator_duties_sync) + .uor(post_validator_aggregate_and_proofs) + .uor(post_validator_contribution_and_proofs) + .uor(post_validator_beacon_committee_subscriptions) + .uor(post_validator_sync_committee_subscriptions) + .uor(post_validator_prepare_beacon_proposer) + .uor(post_validator_register_validator) + .uor(post_lighthouse_liveness) + .uor(post_lighthouse_database_reconstruct) + .uor(post_lighthouse_database_historical_blocks) + .uor(post_lighthouse_block_rewards) + .uor(post_lighthouse_ui_validator_metrics) + .uor(post_lighthouse_ui_validator_info) + .recover(warp_utils::reject::handle_rejection), + ), + ) .recover(warp_utils::reject::handle_rejection) .with(slog_logging(log.clone())) .with(prometheus_metrics()) // Add a `Server` header. .map(|reply| warp::reply::with_header(reply, "Server", &version_with_platform())) - .with(cors_builder.build()); + .with(cors_builder.build()) + .boxed(); let http_socket: SocketAddr = SocketAddr::new(config.listen_addr, config.listen_port); let http_server: HttpServer = match config.tls_config { diff --git a/beacon_node/http_api/src/version.rs b/beacon_node/http_api/src/version.rs index 30f475e689c..e7fd8910b18 100644 --- a/beacon_node/http_api/src/version.rs +++ b/beacon_node/http_api/src/version.rs @@ -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); @@ -48,8 +48,8 @@ pub fn execution_optimistic_fork_versioned_response( } /// Add the `Eth-Consensus-Version` header to a response. -pub fn add_consensus_version_header(reply: T, fork_name: ForkName) -> WithHeader { - reply::with_header(reply, CONSENSUS_VERSION_HEADER, fork_name.to_string()) +pub fn add_consensus_version_header(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 { diff --git a/beacon_node/http_api/tests/main.rs b/beacon_node/http_api/tests/main.rs index ca6a27530a6..88e0032ecde 100644 --- a/beacon_node/http_api/tests/main.rs +++ b/beacon_node/http_api/tests/main.rs @@ -1,5 +1,4 @@ #![cfg(not(debug_assertions))] // Tests are too slow in debug. -#![recursion_limit = "256"] pub mod common; pub mod fork_tests; diff --git a/beacon_node/tests/test.rs b/beacon_node/tests/test.rs index 8ccb260d29b..bbec70330b7 100644 --- a/beacon_node/tests/test.rs +++ b/beacon_node/tests/test.rs @@ -1,5 +1,4 @@ #![cfg(test)] -#![recursion_limit = "512"] use beacon_chain::StateSkipConfig; use node_test_rig::{ diff --git a/common/compare_fields_derive/src/lib.rs b/common/compare_fields_derive/src/lib.rs index 752c09ee056..a8b92b3d548 100644 --- a/common/compare_fields_derive/src/lib.rs +++ b/common/compare_fields_derive/src/lib.rs @@ -1,4 +1,3 @@ -#![recursion_limit = "256"] extern crate proc_macro; use proc_macro::TokenStream; diff --git a/common/warp_utils/src/lib.rs b/common/warp_utils/src/lib.rs index 346361b18fe..77d61251f24 100644 --- a/common/warp_utils/src/lib.rs +++ b/common/warp_utils/src/lib.rs @@ -6,3 +6,4 @@ pub mod metrics; pub mod query; pub mod reject; pub mod task; +pub mod uor; diff --git a/common/warp_utils/src/task.rs b/common/warp_utils/src/task.rs index c3b3e86e2ed..001231f2c6b 100644 --- a/common/warp_utils/src/task.rs +++ b/common/warp_utils/src/task.rs @@ -1,4 +1,5 @@ use serde::Serialize; +use warp::reply::{Reply, Response}; /// A convenience wrapper around `blocking_task`. pub async fn blocking_task(func: F) -> Result @@ -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(func: F) -> Result +where + F: FnOnce() -> Result + 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(func: F) -> Result +pub async fn blocking_json_task(func: F) -> Result where F: FnOnce() -> Result + 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 } diff --git a/common/warp_utils/src/uor.rs b/common/warp_utils/src/uor.rs new file mode 100644 index 00000000000..363f1df7d4d --- /dev/null +++ b/common/warp_utils/src/uor.rs @@ -0,0 +1,25 @@ +use warp::{filters::BoxedFilter, Filter, Rejection}; + +/// Mixin trait for `Filter` providing the unifying-or method. +pub trait UnifyingOrFilter: Filter + 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(self, other: F) -> BoxedFilter + where + F: Filter + Clone + Send + Sync + 'static, + { + self.or(other).unify().boxed() + } +} + +impl UnifyingOrFilter for F +where + F: Filter + Sized + Send + Sync + 'static, + F::Extract: Send, +{ +} diff --git a/consensus/fork_choice/src/fork_choice.rs b/consensus/fork_choice/src/fork_choice.rs index 566764195d4..916b1d5582b 100644 --- a/consensus/fork_choice/src/fork_choice.rs +++ b/consensus/fork_choice/src/fork_choice.rs @@ -1695,7 +1695,6 @@ mod tests { fn get_queued_attestations() -> Vec { (1..4) - .into_iter() .map(|i| QueuedAttestation { slot: Slot::new(i), attesting_indices: vec![], diff --git a/consensus/ssz_derive/src/lib.rs b/consensus/ssz_derive/src/lib.rs index 40d63fd02fa..53752ba44b6 100644 --- a/consensus/ssz_derive/src/lib.rs +++ b/consensus/ssz_derive/src/lib.rs @@ -1,4 +1,3 @@ -#![recursion_limit = "256"] //! Provides procedural derive macros for the `Encode` and `Decode` traits of the `eth2_ssz` crate. //! //! ## Attributes diff --git a/consensus/tree_hash_derive/src/lib.rs b/consensus/tree_hash_derive/src/lib.rs index 21ff324d542..85ece80fb56 100644 --- a/consensus/tree_hash_derive/src/lib.rs +++ b/consensus/tree_hash_derive/src/lib.rs @@ -1,4 +1,3 @@ -#![recursion_limit = "256"] use darling::FromDeriveInput; use proc_macro::TokenStream; use quote::quote; diff --git a/consensus/types/src/lib.rs b/consensus/types/src/lib.rs index 6a5aef36fe2..82407424411 100644 --- a/consensus/types/src/lib.rs +++ b/consensus/types/src/lib.rs @@ -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), diff --git a/crypto/bls/src/generic_aggregate_signature.rs b/crypto/bls/src/generic_aggregate_signature.rs index fdb59626fb2..a61529af250 100644 --- a/crypto/bls/src/generic_aggregate_signature.rs +++ b/crypto/bls/src/generic_aggregate_signature.rs @@ -266,7 +266,7 @@ where } /// Hashes the `self.serialize()` bytes. -#[allow(clippy::derive_hash_xor_eq)] +#[allow(clippy::derived_hash_with_manual_eq)] impl Hash for GenericAggregateSignature where Sig: TSignature, diff --git a/lighthouse/src/main.rs b/lighthouse/src/main.rs index babe2f8dca7..b05e78fe5a7 100644 --- a/lighthouse/src/main.rs +++ b/lighthouse/src/main.rs @@ -1,5 +1,3 @@ -#![recursion_limit = "256"] - mod metrics; use beacon_node::ProductionBeaconNode; diff --git a/testing/execution_engine_integration/src/main.rs b/testing/execution_engine_integration/src/main.rs index bd3436602c1..e46bc13c8d3 100644 --- a/testing/execution_engine_integration/src/main.rs +++ b/testing/execution_engine_integration/src/main.rs @@ -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. diff --git a/testing/simulator/src/main.rs b/testing/simulator/src/main.rs index 9e05a539cfc..922149537cb 100644 --- a/testing/simulator/src/main.rs +++ b/testing/simulator/src/main.rs @@ -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