Misc. dependency cleanup (#6810)

* remove ensure_dir_exists (2 deps saved)

* group UNHANDLED_ERRORs into a generic (2 deps saved)

* Introduce separate `health_metrics` crate

* separate health_metrics crate

* remove metrics from warp_utils

* move ProcessHealth::observe and SystemHealth::observe to health_metrics

* fix errors

* nitpick `Cargo.toml`s

---------

Co-authored-by: Daniel Knopik <daniel@dknopik.de>
# Conflicts:
#	Cargo.toml
This commit is contained in:
Daniel Knopik
2025-01-16 02:48:50 +01:00
committed by GitHub
parent b1a19a8b20
commit 669932aa67
43 changed files with 303 additions and 315 deletions

21
Cargo.lock generated
View File

@@ -43,7 +43,6 @@ dependencies = [
name = "account_utils" name = "account_utils"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"directory",
"eth2_keystore", "eth2_keystore",
"eth2_wallet", "eth2_wallet",
"filesystem", "filesystem",
@@ -2572,9 +2571,7 @@ dependencies = [
"lighthouse_network", "lighthouse_network",
"mediatype", "mediatype",
"pretty_reqwest_error", "pretty_reqwest_error",
"procfs",
"proto_array", "proto_array",
"psutil",
"reqwest", "reqwest",
"reqwest-eventsource", "reqwest-eventsource",
"sensitive_url", "sensitive_url",
@@ -3710,6 +3707,16 @@ dependencies = [
"http 0.2.12", "http 0.2.12",
] ]
[[package]]
name = "health_metrics"
version = "0.1.0"
dependencies = [
"eth2",
"metrics",
"procfs",
"psutil",
]
[[package]] [[package]]
name = "heck" name = "heck"
version = "0.4.1" version = "0.4.1"
@@ -3951,6 +3958,7 @@ dependencies = [
"execution_layer", "execution_layer",
"futures", "futures",
"genesis", "genesis",
"health_metrics",
"hex", "hex",
"lighthouse_network", "lighthouse_network",
"lighthouse_version", "lighthouse_version",
@@ -3986,6 +3994,7 @@ name = "http_metrics"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"beacon_chain", "beacon_chain",
"health_metrics",
"lighthouse_network", "lighthouse_network",
"lighthouse_version", "lighthouse_version",
"logging", "logging",
@@ -5716,6 +5725,7 @@ name = "monitoring_api"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"eth2", "eth2",
"health_metrics",
"lighthouse_version", "lighthouse_version",
"metrics", "metrics",
"regex", "regex",
@@ -9561,7 +9571,6 @@ dependencies = [
"bls", "bls",
"deposit_contract", "deposit_contract",
"derivative", "derivative",
"directory",
"eth2_keystore", "eth2_keystore",
"filesystem", "filesystem",
"hex", "hex",
@@ -9589,6 +9598,7 @@ dependencies = [
"filesystem", "filesystem",
"futures", "futures",
"graffiti_file", "graffiti_file",
"health_metrics",
"initialized_validators", "initialized_validators",
"itertools 0.10.5", "itertools 0.10.5",
"lighthouse_version", "lighthouse_version",
@@ -9621,6 +9631,7 @@ dependencies = [
name = "validator_http_metrics" name = "validator_http_metrics"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"health_metrics",
"lighthouse_version", "lighthouse_version",
"malloc_utils", "malloc_utils",
"metrics", "metrics",
@@ -9799,7 +9810,6 @@ dependencies = [
name = "warp_utils" name = "warp_utils"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"beacon_chain",
"bytes", "bytes",
"eth2", "eth2",
"headers", "headers",
@@ -9808,7 +9818,6 @@ dependencies = [
"serde", "serde",
"serde_array_query", "serde_array_query",
"serde_json", "serde_json",
"state_processing",
"tokio", "tokio",
"types", "types",
"warp", "warp",

View File

@@ -33,6 +33,7 @@ members = [
"common/eth2_network_config", "common/eth2_network_config",
"common/eth2_wallet_manager", "common/eth2_wallet_manager",
"common/filesystem", "common/filesystem",
"common/health_metrics",
"common/lighthouse_version", "common/lighthouse_version",
"common/lockfile", "common/lockfile",
"common/logging", "common/logging",
@@ -252,6 +253,7 @@ filesystem = { path = "common/filesystem" }
fork_choice = { path = "consensus/fork_choice" } fork_choice = { path = "consensus/fork_choice" }
genesis = { path = "beacon_node/genesis" } genesis = { path = "beacon_node/genesis" }
gossipsub = { path = "beacon_node/lighthouse_network/gossipsub/" } gossipsub = { path = "beacon_node/lighthouse_network/gossipsub/" }
health_metrics = { path = "common/health_metrics" }
http_api = { path = "beacon_node/http_api" } http_api = { path = "beacon_node/http_api" }
initialized_validators = { path = "validator_client/initialized_validators" } initialized_validators = { path = "validator_client/initialized_validators" }
int_to_bytes = { path = "consensus/int_to_bytes" } int_to_bytes = { path = "consensus/int_to_bytes" }

View File

@@ -6,14 +6,13 @@ use account_utils::{
}; };
use clap::{Arg, ArgAction, ArgMatches, Command}; use clap::{Arg, ArgAction, ArgMatches, Command};
use clap_utils::FLAG_HEADER; use clap_utils::FLAG_HEADER;
use directory::{ use directory::{parse_path_or_default_with_flag, DEFAULT_SECRET_DIR, DEFAULT_WALLET_DIR};
ensure_dir_exists, parse_path_or_default_with_flag, DEFAULT_SECRET_DIR, DEFAULT_WALLET_DIR,
};
use environment::Environment; use environment::Environment;
use eth2_wallet_manager::WalletManager; use eth2_wallet_manager::WalletManager;
use slashing_protection::{SlashingDatabase, SLASHING_PROTECTION_FILENAME}; use slashing_protection::{SlashingDatabase, SLASHING_PROTECTION_FILENAME};
use std::ffi::OsStr; use std::ffi::OsStr;
use std::fs; use std::fs;
use std::fs::create_dir_all;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use types::EthSpec; use types::EthSpec;
use validator_dir::Builder as ValidatorDirBuilder; use validator_dir::Builder as ValidatorDirBuilder;
@@ -156,8 +155,10 @@ pub fn cli_run<E: EthSpec>(
)); ));
} }
ensure_dir_exists(&validator_dir)?; create_dir_all(&validator_dir)
ensure_dir_exists(&secrets_dir)?; .map_err(|e| format!("Could not create validator dir at {validator_dir:?}: {e:?}"))?;
create_dir_all(&secrets_dir)
.map_err(|e| format!("Could not create secrets dir at {secrets_dir:?}: {e:?}"))?;
eprintln!("secrets-dir path {:?}", secrets_dir); eprintln!("secrets-dir path {:?}", secrets_dir);
eprintln!("wallets-dir path {:?}", wallet_base_dir); eprintln!("wallets-dir path {:?}", wallet_base_dir);

View File

@@ -5,10 +5,10 @@ use account_utils::eth2_keystore::{keypair_from_secret, Keystore, KeystoreBuilde
use account_utils::{random_password, read_mnemonic_from_cli, STDIN_INPUTS_FLAG}; use account_utils::{random_password, read_mnemonic_from_cli, STDIN_INPUTS_FLAG};
use clap::{Arg, ArgAction, ArgMatches, Command}; use clap::{Arg, ArgAction, ArgMatches, Command};
use clap_utils::FLAG_HEADER; use clap_utils::FLAG_HEADER;
use directory::ensure_dir_exists;
use directory::{parse_path_or_default_with_flag, DEFAULT_SECRET_DIR}; use directory::{parse_path_or_default_with_flag, DEFAULT_SECRET_DIR};
use eth2_wallet::bip39::Seed; use eth2_wallet::bip39::Seed;
use eth2_wallet::{recover_validator_secret_from_mnemonic, KeyType, ValidatorKeystores}; use eth2_wallet::{recover_validator_secret_from_mnemonic, KeyType, ValidatorKeystores};
use std::fs::create_dir_all;
use std::path::PathBuf; use std::path::PathBuf;
use validator_dir::Builder as ValidatorDirBuilder; use validator_dir::Builder as ValidatorDirBuilder;
pub const CMD: &str = "recover"; pub const CMD: &str = "recover";
@@ -91,8 +91,10 @@ pub fn cli_run(matches: &ArgMatches, validator_dir: PathBuf) -> Result<(), Strin
eprintln!("secrets-dir path: {:?}", secrets_dir); eprintln!("secrets-dir path: {:?}", secrets_dir);
ensure_dir_exists(&validator_dir)?; create_dir_all(&validator_dir)
ensure_dir_exists(&secrets_dir)?; .map_err(|e| format!("Could not create validator dir at {validator_dir:?}: {e:?}"))?;
create_dir_all(&secrets_dir)
.map_err(|e| format!("Could not create secrets dir at {secrets_dir:?}: {e:?}"))?;
eprintln!(); eprintln!();
eprintln!("WARNING: KEY RECOVERY CAN LEAD TO DUPLICATING VALIDATORS KEYS, WHICH CAN LEAD TO SLASHING."); eprintln!("WARNING: KEY RECOVERY CAN LEAD TO DUPLICATING VALIDATORS KEYS, WHICH CAN LEAD TO SLASHING.");

View File

@@ -5,7 +5,8 @@ pub mod recover;
use crate::WALLETS_DIR_FLAG; use crate::WALLETS_DIR_FLAG;
use clap::{Arg, ArgAction, ArgMatches, Command}; use clap::{Arg, ArgAction, ArgMatches, Command};
use clap_utils::FLAG_HEADER; use clap_utils::FLAG_HEADER;
use directory::{ensure_dir_exists, parse_path_or_default_with_flag, DEFAULT_WALLET_DIR}; use directory::{parse_path_or_default_with_flag, DEFAULT_WALLET_DIR};
use std::fs::create_dir_all;
use std::path::PathBuf; use std::path::PathBuf;
pub const CMD: &str = "wallet"; pub const CMD: &str = "wallet";
@@ -44,7 +45,7 @@ pub fn cli_run(matches: &ArgMatches) -> Result<(), String> {
} else { } else {
parse_path_or_default_with_flag(matches, WALLETS_DIR_FLAG, DEFAULT_WALLET_DIR)? parse_path_or_default_with_flag(matches, WALLETS_DIR_FLAG, DEFAULT_WALLET_DIR)?
}; };
ensure_dir_exists(&wallet_base_dir)?; create_dir_all(&wallet_base_dir).map_err(|_| "Could not create wallet base dir")?;
eprintln!("wallet-dir path: {:?}", wallet_base_dir); eprintln!("wallet-dir path: {:?}", wallet_base_dir);

View File

@@ -17,6 +17,7 @@ ethereum_serde_utils = { workspace = true }
ethereum_ssz = { workspace = true } ethereum_ssz = { workspace = true }
execution_layer = { workspace = true } execution_layer = { workspace = true }
futures = { workspace = true } futures = { workspace = true }
health_metrics = { workspace = true }
hex = { workspace = true } hex = { workspace = true }
lighthouse_network = { workspace = true } lighthouse_network = { workspace = true }
lighthouse_version = { workspace = true } lighthouse_version = { workspace = true }

View File

@@ -7,7 +7,7 @@ use state_processing::{
}; };
use std::sync::Arc; use std::sync::Arc;
use types::{BeaconState, BeaconStateError, EthSpec, Hash256}; use types::{BeaconState, BeaconStateError, EthSpec, Hash256};
use warp_utils::reject::{beacon_chain_error, custom_bad_request, custom_server_error}; use warp_utils::reject::{custom_bad_request, custom_server_error, unhandled_error};
const MAX_REQUEST_RANGE_EPOCHS: usize = 100; const MAX_REQUEST_RANGE_EPOCHS: usize = 100;
const BLOCK_ROOT_CHUNK_SIZE: usize = 100; const BLOCK_ROOT_CHUNK_SIZE: usize = 100;
@@ -50,7 +50,7 @@ pub fn get_attestation_performance<T: BeaconChainTypes>(
let end_slot = end_epoch.end_slot(T::EthSpec::slots_per_epoch()); let end_slot = end_epoch.end_slot(T::EthSpec::slots_per_epoch());
// Ensure end_epoch is smaller than the current epoch - 1. // Ensure end_epoch is smaller than the current epoch - 1.
let current_epoch = chain.epoch().map_err(beacon_chain_error)?; let current_epoch = chain.epoch().map_err(unhandled_error)?;
if query.end_epoch >= current_epoch - 1 { if query.end_epoch >= current_epoch - 1 {
return Err(custom_bad_request(format!( return Err(custom_bad_request(format!(
"end_epoch must be less than the current epoch - 1. current: {}, end: {}", "end_epoch must be less than the current epoch - 1. current: {}, end: {}",
@@ -83,7 +83,7 @@ pub fn get_attestation_performance<T: BeaconChainTypes>(
let index_range = if target.to_lowercase() == "global" { let index_range = if target.to_lowercase() == "global" {
chain chain
.with_head(|head| Ok((0..head.beacon_state.validators().len() as u64).collect())) .with_head(|head| Ok((0..head.beacon_state.validators().len() as u64).collect()))
.map_err(beacon_chain_error)? .map_err(unhandled_error::<BeaconChainError>)?
} else { } else {
vec![target.parse::<u64>().map_err(|_| { vec![target.parse::<u64>().map_err(|_| {
custom_bad_request(format!( custom_bad_request(format!(
@@ -96,10 +96,10 @@ pub fn get_attestation_performance<T: BeaconChainTypes>(
// Load block roots. // Load block roots.
let mut block_roots: Vec<Hash256> = chain let mut block_roots: Vec<Hash256> = chain
.forwards_iter_block_roots_until(start_slot, end_slot) .forwards_iter_block_roots_until(start_slot, end_slot)
.map_err(beacon_chain_error)? .map_err(unhandled_error)?
.map(|res| res.map(|(root, _)| root)) .map(|res| res.map(|(root, _)| root))
.collect::<Result<Vec<Hash256>, _>>() .collect::<Result<Vec<Hash256>, _>>()
.map_err(beacon_chain_error)?; .map_err(unhandled_error)?;
block_roots.dedup(); block_roots.dedup();
// Load first block so we can get its parent. // Load first block so we can get its parent.
@@ -113,7 +113,7 @@ pub fn get_attestation_performance<T: BeaconChainTypes>(
.and_then(|maybe_block| { .and_then(|maybe_block| {
maybe_block.ok_or(BeaconChainError::MissingBeaconBlock(*first_block_root)) maybe_block.ok_or(BeaconChainError::MissingBeaconBlock(*first_block_root))
}) })
.map_err(beacon_chain_error)?; .map_err(unhandled_error)?;
// Load the block of the prior slot which will be used to build the starting state. // Load the block of the prior slot which will be used to build the starting state.
let prior_block = chain let prior_block = chain
@@ -122,14 +122,14 @@ pub fn get_attestation_performance<T: BeaconChainTypes>(
maybe_block maybe_block
.ok_or_else(|| BeaconChainError::MissingBeaconBlock(first_block.parent_root())) .ok_or_else(|| BeaconChainError::MissingBeaconBlock(first_block.parent_root()))
}) })
.map_err(beacon_chain_error)?; .map_err(unhandled_error)?;
// Load state for block replay. // Load state for block replay.
let state_root = prior_block.state_root(); let state_root = prior_block.state_root();
let state = chain let state = chain
.get_state(&state_root, Some(prior_slot)) .get_state(&state_root, Some(prior_slot))
.and_then(|maybe_state| maybe_state.ok_or(BeaconChainError::MissingBeaconState(state_root))) .and_then(|maybe_state| maybe_state.ok_or(BeaconChainError::MissingBeaconState(state_root)))
.map_err(beacon_chain_error)?; .map_err(unhandled_error)?;
// Allocate an AttestationPerformance vector for each validator in the range. // Allocate an AttestationPerformance vector for each validator in the range.
let mut perfs: Vec<AttestationPerformance> = let mut perfs: Vec<AttestationPerformance> =
@@ -198,7 +198,7 @@ pub fn get_attestation_performance<T: BeaconChainTypes>(
.and_then(|maybe_block| { .and_then(|maybe_block| {
maybe_block.ok_or(BeaconChainError::MissingBeaconBlock(*root)) maybe_block.ok_or(BeaconChainError::MissingBeaconBlock(*root))
}) })
.map_err(beacon_chain_error) .map_err(unhandled_error)
}) })
.collect::<Result<Vec<_>, _>>()?; .collect::<Result<Vec<_>, _>>()?;

View File

@@ -16,9 +16,7 @@ pub fn attester_duties<T: BeaconChainTypes>(
request_indices: &[u64], request_indices: &[u64],
chain: &BeaconChain<T>, chain: &BeaconChain<T>,
) -> Result<ApiDuties, warp::reject::Rejection> { ) -> Result<ApiDuties, warp::reject::Rejection> {
let current_epoch = chain let current_epoch = chain.epoch().map_err(warp_utils::reject::unhandled_error)?;
.epoch()
.map_err(warp_utils::reject::beacon_chain_error)?;
// Determine what the current epoch would be if we fast-forward our system clock by // Determine what the current epoch would be if we fast-forward our system clock by
// `MAXIMUM_GOSSIP_CLOCK_DISPARITY`. // `MAXIMUM_GOSSIP_CLOCK_DISPARITY`.
@@ -57,7 +55,7 @@ fn cached_attestation_duties<T: BeaconChainTypes>(
let (duties, dependent_root, execution_status) = chain let (duties, dependent_root, execution_status) = chain
.validator_attestation_duties(request_indices, request_epoch, head_block_root) .validator_attestation_duties(request_indices, request_epoch, head_block_root)
.map_err(warp_utils::reject::beacon_chain_error)?; .map_err(warp_utils::reject::unhandled_error)?;
convert_to_api_response( convert_to_api_response(
duties, duties,
@@ -82,7 +80,7 @@ fn compute_historic_attester_duties<T: BeaconChainTypes>(
let (cached_head, execution_status) = chain let (cached_head, execution_status) = chain
.canonical_head .canonical_head
.head_and_execution_status() .head_and_execution_status()
.map_err(warp_utils::reject::beacon_chain_error)?; .map_err(warp_utils::reject::unhandled_error)?;
let head = &cached_head.snapshot; let head = &cached_head.snapshot;
if head.beacon_state.current_epoch() <= request_epoch { if head.beacon_state.current_epoch() <= request_epoch {
@@ -131,13 +129,13 @@ fn compute_historic_attester_duties<T: BeaconChainTypes>(
state state
.build_committee_cache(relative_epoch, &chain.spec) .build_committee_cache(relative_epoch, &chain.spec)
.map_err(BeaconChainError::from) .map_err(BeaconChainError::from)
.map_err(warp_utils::reject::beacon_chain_error)?; .map_err(warp_utils::reject::unhandled_error)?;
let dependent_root = state let dependent_root = state
// The only block which decides its own shuffling is the genesis block. // The only block which decides its own shuffling is the genesis block.
.attester_shuffling_decision_root(chain.genesis_block_root, relative_epoch) .attester_shuffling_decision_root(chain.genesis_block_root, relative_epoch)
.map_err(BeaconChainError::from) .map_err(BeaconChainError::from)
.map_err(warp_utils::reject::beacon_chain_error)?; .map_err(warp_utils::reject::unhandled_error)?;
let duties = request_indices let duties = request_indices
.iter() .iter()
@@ -147,7 +145,7 @@ fn compute_historic_attester_duties<T: BeaconChainTypes>(
.map_err(BeaconChainError::from) .map_err(BeaconChainError::from)
}) })
.collect::<Result<_, _>>() .collect::<Result<_, _>>()
.map_err(warp_utils::reject::beacon_chain_error)?; .map_err(warp_utils::reject::unhandled_error)?;
convert_to_api_response( convert_to_api_response(
duties, duties,
@@ -181,7 +179,7 @@ fn ensure_state_knows_attester_duties_for_epoch<E: EthSpec>(
// A "partial" state advance is adequate since attester duties don't rely on state roots. // A "partial" state advance is adequate since attester duties don't rely on state roots.
partial_state_advance(state, Some(state_root), target_slot, spec) partial_state_advance(state, Some(state_root), target_slot, spec)
.map_err(BeaconChainError::from) .map_err(BeaconChainError::from)
.map_err(warp_utils::reject::beacon_chain_error)?; .map_err(warp_utils::reject::unhandled_error)?;
} }
Ok(()) Ok(())
@@ -208,7 +206,7 @@ fn convert_to_api_response<T: BeaconChainTypes>(
let usize_indices = indices.iter().map(|i| *i as usize).collect::<Vec<_>>(); let usize_indices = indices.iter().map(|i| *i as usize).collect::<Vec<_>>();
let index_to_pubkey_map = chain let index_to_pubkey_map = chain
.validator_pubkey_bytes_many(&usize_indices) .validator_pubkey_bytes_many(&usize_indices)
.map_err(warp_utils::reject::beacon_chain_error)?; .map_err(warp_utils::reject::unhandled_error)?;
let data = duties let data = duties
.into_iter() .into_iter()

View File

@@ -38,7 +38,7 @@ impl BlockId {
let (cached_head, execution_status) = chain let (cached_head, execution_status) = chain
.canonical_head .canonical_head
.head_and_execution_status() .head_and_execution_status()
.map_err(warp_utils::reject::beacon_chain_error)?; .map_err(warp_utils::reject::unhandled_error)?;
Ok(( Ok((
cached_head.head_block_root(), cached_head.head_block_root(),
execution_status.is_optimistic_or_invalid(), execution_status.is_optimistic_or_invalid(),
@@ -63,10 +63,10 @@ impl BlockId {
CoreBlockId::Slot(slot) => { CoreBlockId::Slot(slot) => {
let execution_optimistic = chain let execution_optimistic = chain
.is_optimistic_or_invalid_head() .is_optimistic_or_invalid_head()
.map_err(warp_utils::reject::beacon_chain_error)?; .map_err(warp_utils::reject::unhandled_error)?;
let root = chain let root = chain
.block_root_at_slot(*slot, WhenSlotSkipped::None) .block_root_at_slot(*slot, WhenSlotSkipped::None)
.map_err(warp_utils::reject::beacon_chain_error) .map_err(warp_utils::reject::unhandled_error)
.and_then(|root_opt| { .and_then(|root_opt| {
root_opt.ok_or_else(|| { root_opt.ok_or_else(|| {
warp_utils::reject::custom_not_found(format!( warp_utils::reject::custom_not_found(format!(
@@ -96,17 +96,17 @@ impl BlockId {
.store .store
.block_exists(root) .block_exists(root)
.map_err(BeaconChainError::DBError) .map_err(BeaconChainError::DBError)
.map_err(warp_utils::reject::beacon_chain_error)? .map_err(warp_utils::reject::unhandled_error)?
{ {
let execution_optimistic = chain let execution_optimistic = chain
.canonical_head .canonical_head
.fork_choice_read_lock() .fork_choice_read_lock()
.is_optimistic_or_invalid_block(root) .is_optimistic_or_invalid_block(root)
.map_err(BeaconChainError::ForkChoiceError) .map_err(BeaconChainError::ForkChoiceError)
.map_err(warp_utils::reject::beacon_chain_error)?; .map_err(warp_utils::reject::unhandled_error)?;
let blinded_block = chain let blinded_block = chain
.get_blinded_block(root) .get_blinded_block(root)
.map_err(warp_utils::reject::beacon_chain_error)? .map_err(warp_utils::reject::unhandled_error)?
.ok_or_else(|| { .ok_or_else(|| {
warp_utils::reject::custom_not_found(format!( warp_utils::reject::custom_not_found(format!(
"beacon block with root {}", "beacon block with root {}",
@@ -116,7 +116,7 @@ impl BlockId {
let block_slot = blinded_block.slot(); let block_slot = blinded_block.slot();
let finalized = chain let finalized = chain
.is_finalized_block(root, block_slot) .is_finalized_block(root, block_slot)
.map_err(warp_utils::reject::beacon_chain_error)?; .map_err(warp_utils::reject::unhandled_error)?;
Ok((*root, execution_optimistic, finalized)) Ok((*root, execution_optimistic, finalized))
} else { } else {
Err(warp_utils::reject::custom_not_found(format!( Err(warp_utils::reject::custom_not_found(format!(
@@ -134,7 +134,7 @@ impl BlockId {
) -> Result<Option<SignedBlindedBeaconBlock<T::EthSpec>>, warp::Rejection> { ) -> Result<Option<SignedBlindedBeaconBlock<T::EthSpec>>, warp::Rejection> {
chain chain
.get_blinded_block(root) .get_blinded_block(root)
.map_err(warp_utils::reject::beacon_chain_error) .map_err(warp_utils::reject::unhandled_error)
} }
/// Return the `SignedBeaconBlock` identified by `self`. /// Return the `SignedBeaconBlock` identified by `self`.
@@ -154,7 +154,7 @@ impl BlockId {
let (cached_head, execution_status) = chain let (cached_head, execution_status) = chain
.canonical_head .canonical_head
.head_and_execution_status() .head_and_execution_status()
.map_err(warp_utils::reject::beacon_chain_error)?; .map_err(warp_utils::reject::unhandled_error)?;
Ok(( Ok((
cached_head.snapshot.beacon_block.clone_as_blinded(), cached_head.snapshot.beacon_block.clone_as_blinded(),
execution_status.is_optimistic_or_invalid(), execution_status.is_optimistic_or_invalid(),
@@ -211,7 +211,7 @@ impl BlockId {
let (cached_head, execution_status) = chain let (cached_head, execution_status) = chain
.canonical_head .canonical_head
.head_and_execution_status() .head_and_execution_status()
.map_err(warp_utils::reject::beacon_chain_error)?; .map_err(warp_utils::reject::unhandled_error)?;
Ok(( Ok((
cached_head.snapshot.beacon_block.clone(), cached_head.snapshot.beacon_block.clone(),
execution_status.is_optimistic_or_invalid(), execution_status.is_optimistic_or_invalid(),
@@ -223,7 +223,7 @@ impl BlockId {
chain chain
.get_block(&root) .get_block(&root)
.await .await
.map_err(warp_utils::reject::beacon_chain_error) .map_err(warp_utils::reject::unhandled_error)
.and_then(|block_opt| match block_opt { .and_then(|block_opt| match block_opt {
Some(block) => { Some(block) => {
if block.slot() != *slot { if block.slot() != *slot {
@@ -245,7 +245,7 @@ impl BlockId {
chain chain
.get_block(&root) .get_block(&root)
.await .await
.map_err(warp_utils::reject::beacon_chain_error) .map_err(warp_utils::reject::unhandled_error)
.and_then(|block_opt| { .and_then(|block_opt| {
block_opt block_opt
.map(|block| (Arc::new(block), execution_optimistic, finalized)) .map(|block| (Arc::new(block), execution_optimistic, finalized))
@@ -311,7 +311,7 @@ impl BlockId {
let blob_sidecar_list = chain let blob_sidecar_list = chain
.store .store
.get_blobs(&root) .get_blobs(&root)
.map_err(|e| warp_utils::reject::beacon_chain_error(e.into()))? .map_err(|e| warp_utils::reject::unhandled_error(BeaconChainError::from(e)))?
.blobs() .blobs()
.ok_or_else(|| { .ok_or_else(|| {
warp_utils::reject::custom_not_found(format!("no blobs stored for block {root}")) warp_utils::reject::custom_not_found(format!("no blobs stored for block {root}"))
@@ -356,7 +356,7 @@ impl BlockId {
|column_index| match chain.get_data_column(&root, &column_index) { |column_index| match chain.get_data_column(&root, &column_index) {
Ok(Some(data_column)) => Some(Ok(data_column)), Ok(Some(data_column)) => Some(Ok(data_column)),
Ok(None) => None, Ok(None) => None,
Err(e) => Some(Err(warp_utils::reject::beacon_chain_error(e))), Err(e) => Some(Err(warp_utils::reject::unhandled_error(e))),
}, },
) )
.collect::<Result<Vec<_>, _>>()?; .collect::<Result<Vec<_>, _>>()?;

View File

@@ -13,7 +13,7 @@ use types::{
AttestationRef, BeaconCommittee, BeaconState, BeaconStateError, BlindedPayload, ChainSpec, AttestationRef, BeaconCommittee, BeaconState, BeaconStateError, BlindedPayload, ChainSpec,
Epoch, EthSpec, Hash256, OwnedBeaconCommittee, RelativeEpoch, SignedBeaconBlock, Slot, Epoch, EthSpec, Hash256, OwnedBeaconCommittee, RelativeEpoch, SignedBeaconBlock, Slot,
}; };
use warp_utils::reject::{beacon_chain_error, custom_bad_request, custom_server_error}; use warp_utils::reject::{custom_bad_request, custom_server_error, unhandled_error};
/// Load blocks from block roots in chunks to reduce load on memory. /// Load blocks from block roots in chunks to reduce load on memory.
const BLOCK_ROOT_CHUNK_SIZE: usize = 100; const BLOCK_ROOT_CHUNK_SIZE: usize = 100;
@@ -263,9 +263,9 @@ pub fn get_block_packing_efficiency<T: BeaconChainTypes>(
// Load block roots. // Load block roots.
let mut block_roots: Vec<Hash256> = chain let mut block_roots: Vec<Hash256> = chain
.forwards_iter_block_roots_until(start_slot_of_prior_epoch, end_slot) .forwards_iter_block_roots_until(start_slot_of_prior_epoch, end_slot)
.map_err(beacon_chain_error)? .map_err(unhandled_error)?
.collect::<Result<Vec<(Hash256, Slot)>, _>>() .collect::<Result<Vec<(Hash256, Slot)>, _>>()
.map_err(beacon_chain_error)? .map_err(unhandled_error)?
.iter() .iter()
.map(|(root, _)| *root) .map(|(root, _)| *root)
.collect(); .collect();
@@ -280,7 +280,7 @@ pub fn get_block_packing_efficiency<T: BeaconChainTypes>(
.and_then(|maybe_block| { .and_then(|maybe_block| {
maybe_block.ok_or(BeaconChainError::MissingBeaconBlock(*first_block_root)) maybe_block.ok_or(BeaconChainError::MissingBeaconBlock(*first_block_root))
}) })
.map_err(beacon_chain_error)?; .map_err(unhandled_error)?;
// Load state for block replay. // Load state for block replay.
let starting_state_root = first_block.state_root(); let starting_state_root = first_block.state_root();
@@ -290,7 +290,7 @@ pub fn get_block_packing_efficiency<T: BeaconChainTypes>(
.and_then(|maybe_state| { .and_then(|maybe_state| {
maybe_state.ok_or(BeaconChainError::MissingBeaconState(starting_state_root)) maybe_state.ok_or(BeaconChainError::MissingBeaconState(starting_state_root))
}) })
.map_err(beacon_chain_error)?; .map_err(unhandled_error)?;
// Initialize response vector. // Initialize response vector.
let mut response = Vec::new(); let mut response = Vec::new();
@@ -392,7 +392,7 @@ pub fn get_block_packing_efficiency<T: BeaconChainTypes>(
.and_then(|maybe_block| { .and_then(|maybe_block| {
maybe_block.ok_or(BeaconChainError::MissingBeaconBlock(*root)) maybe_block.ok_or(BeaconChainError::MissingBeaconBlock(*root))
}) })
.map_err(beacon_chain_error) .map_err(unhandled_error)
}) })
.collect::<Result<Vec<_>, _>>()?; .collect::<Result<Vec<_>, _>>()?;

View File

@@ -7,7 +7,7 @@ use std::num::NonZeroUsize;
use std::sync::Arc; use std::sync::Arc;
use types::beacon_block::BlindedBeaconBlock; use types::beacon_block::BlindedBeaconBlock;
use types::non_zero_usize::new_non_zero_usize; use types::non_zero_usize::new_non_zero_usize;
use warp_utils::reject::{beacon_chain_error, beacon_state_error, custom_bad_request}; use warp_utils::reject::{beacon_state_error, custom_bad_request, unhandled_error};
const STATE_CACHE_SIZE: NonZeroUsize = new_non_zero_usize(2); const STATE_CACHE_SIZE: NonZeroUsize = new_non_zero_usize(2);
@@ -30,23 +30,23 @@ pub fn get_block_rewards<T: BeaconChainTypes>(
let end_block_root = chain let end_block_root = chain
.block_root_at_slot(end_slot, WhenSlotSkipped::Prev) .block_root_at_slot(end_slot, WhenSlotSkipped::Prev)
.map_err(beacon_chain_error)? .map_err(unhandled_error)?
.ok_or_else(|| custom_bad_request(format!("block at end slot {} unknown", end_slot)))?; .ok_or_else(|| custom_bad_request(format!("block at end slot {} unknown", end_slot)))?;
let blocks = chain let blocks = chain
.store .store
.load_blocks_to_replay(start_slot, end_slot, end_block_root) .load_blocks_to_replay(start_slot, end_slot, end_block_root)
.map_err(|e| beacon_chain_error(e.into()))?; .map_err(|e| unhandled_error(BeaconChainError::from(e)))?;
let state_root = chain let state_root = chain
.state_root_at_slot(prior_slot) .state_root_at_slot(prior_slot)
.map_err(beacon_chain_error)? .map_err(unhandled_error)?
.ok_or_else(|| custom_bad_request(format!("prior state at slot {} unknown", prior_slot)))?; .ok_or_else(|| custom_bad_request(format!("prior state at slot {} unknown", prior_slot)))?;
let mut state = chain let mut state = chain
.get_state(&state_root, Some(prior_slot)) .get_state(&state_root, Some(prior_slot))
.and_then(|maybe_state| maybe_state.ok_or(BeaconChainError::MissingBeaconState(state_root))) .and_then(|maybe_state| maybe_state.ok_or(BeaconChainError::MissingBeaconState(state_root)))
.map_err(beacon_chain_error)?; .map_err(unhandled_error)?;
state state
.build_caches(&chain.spec) .build_caches(&chain.spec)
@@ -73,12 +73,12 @@ pub fn get_block_rewards<T: BeaconChainTypes>(
.state_root_iter( .state_root_iter(
chain chain
.forwards_iter_state_roots_until(prior_slot, end_slot) .forwards_iter_state_roots_until(prior_slot, end_slot)
.map_err(beacon_chain_error)?, .map_err(unhandled_error)?,
) )
.no_signature_verification() .no_signature_verification()
.minimal_block_root_verification() .minimal_block_root_verification()
.apply_blocks(blocks, None) .apply_blocks(blocks, None)
.map_err(beacon_chain_error)?; .map_err(unhandled_error)?;
if block_replayer.state_root_miss() { if block_replayer.state_root_miss() {
warn!( warn!(
@@ -125,7 +125,7 @@ pub fn compute_block_rewards<T: BeaconChainTypes>(
); );
let parent_block = chain let parent_block = chain
.get_blinded_block(&parent_root) .get_blinded_block(&parent_root)
.map_err(beacon_chain_error)? .map_err(unhandled_error)?
.ok_or_else(|| { .ok_or_else(|| {
custom_bad_request(format!( custom_bad_request(format!(
"parent block not known or not canonical: {:?}", "parent block not known or not canonical: {:?}",
@@ -135,7 +135,7 @@ pub fn compute_block_rewards<T: BeaconChainTypes>(
let parent_state = chain let parent_state = chain
.get_state(&parent_block.state_root(), Some(parent_block.slot())) .get_state(&parent_block.state_root(), Some(parent_block.slot()))
.map_err(beacon_chain_error)? .map_err(unhandled_error)?
.ok_or_else(|| { .ok_or_else(|| {
custom_bad_request(format!( custom_bad_request(format!(
"no state known for parent block: {:?}", "no state known for parent block: {:?}",
@@ -148,7 +148,7 @@ pub fn compute_block_rewards<T: BeaconChainTypes>(
.state_root_iter([Ok((parent_block.state_root(), parent_block.slot()))].into_iter()) .state_root_iter([Ok((parent_block.state_root(), parent_block.slot()))].into_iter())
.minimal_block_root_verification() .minimal_block_root_verification()
.apply_blocks(vec![], Some(block.slot())) .apply_blocks(vec![], Some(block.slot()))
.map_err(beacon_chain_error)?; .map_err(unhandled_error::<BeaconChainError>)?;
if block_replayer.state_root_miss() { if block_replayer.state_root_miss() {
warn!( warn!(
@@ -176,7 +176,7 @@ pub fn compute_block_rewards<T: BeaconChainTypes>(
&mut reward_cache, &mut reward_cache,
true, true,
) )
.map_err(beacon_chain_error)?; .map_err(unhandled_error)?;
block_rewards.push(block_reward); block_rewards.push(block_reward);
} }

View File

@@ -23,7 +23,7 @@ pub fn build_block_contents<E: EthSpec>(
} = block; } = block;
let Some((kzg_proofs, blobs)) = blob_items else { let Some((kzg_proofs, blobs)) = blob_items else {
return Err(warp_utils::reject::block_production_error( return Err(warp_utils::reject::unhandled_error(
BlockProductionError::MissingBlobs, BlockProductionError::MissingBlobs,
)); ));
}; };

View File

@@ -50,6 +50,7 @@ use eth2::types::{
ValidatorStatus, ValidatorsRequestBody, ValidatorStatus, ValidatorsRequestBody,
}; };
use eth2::{CONSENSUS_VERSION_HEADER, CONTENT_TYPE_HEADER, SSZ_CONTENT_TYPE_HEADER}; use eth2::{CONSENSUS_VERSION_HEADER, CONTENT_TYPE_HEADER, SSZ_CONTENT_TYPE_HEADER};
use health_metrics::observe::Observe;
use lighthouse_network::{types::SyncState, EnrExt, NetworkGlobals, PeerId, PubsubMessage}; use lighthouse_network::{types::SyncState, EnrExt, NetworkGlobals, PeerId, PubsubMessage};
use lighthouse_version::version_with_platform; use lighthouse_version::version_with_platform;
use logging::SSELoggingComponents; use logging::SSELoggingComponents;
@@ -938,9 +939,9 @@ pub fn serve<T: BeaconChainTypes>(
) )
} }
} }
_ => { _ => warp_utils::reject::unhandled_error(
warp_utils::reject::beacon_chain_error(e.into()) BeaconChainError::from(e),
} ),
} }
})?; })?;
@@ -1067,7 +1068,7 @@ pub fn serve<T: BeaconChainTypes>(
let validators = chain let validators = chain
.validator_indices(sync_committee.pubkeys.iter()) .validator_indices(sync_committee.pubkeys.iter())
.map_err(warp_utils::reject::beacon_chain_error)?; .map_err(warp_utils::reject::unhandled_error)?;
let validator_aggregates = validators let validator_aggregates = validators
.chunks_exact(T::EthSpec::sync_subcommittee_size()) .chunks_exact(T::EthSpec::sync_subcommittee_size())
@@ -1147,7 +1148,7 @@ pub fn serve<T: BeaconChainTypes>(
let (cached_head, execution_status) = chain let (cached_head, execution_status) = chain
.canonical_head .canonical_head
.head_and_execution_status() .head_and_execution_status()
.map_err(warp_utils::reject::beacon_chain_error)?; .map_err(warp_utils::reject::unhandled_error)?;
( (
cached_head.head_block_root(), cached_head.head_block_root(),
cached_head.snapshot.beacon_block.clone_as_blinded(), cached_head.snapshot.beacon_block.clone_as_blinded(),
@@ -1161,13 +1162,13 @@ pub fn serve<T: BeaconChainTypes>(
BlockId::from_root(parent_root).blinded_block(&chain)?; BlockId::from_root(parent_root).blinded_block(&chain)?;
let (root, _slot) = chain let (root, _slot) = chain
.forwards_iter_block_roots(parent.slot()) .forwards_iter_block_roots(parent.slot())
.map_err(warp_utils::reject::beacon_chain_error)? .map_err(warp_utils::reject::unhandled_error)?
// Ignore any skip-slots immediately following the parent. // Ignore any skip-slots immediately following the parent.
.find(|res| { .find(|res| {
res.as_ref().is_ok_and(|(root, _)| *root != parent_root) res.as_ref().is_ok_and(|(root, _)| *root != parent_root)
}) })
.transpose() .transpose()
.map_err(warp_utils::reject::beacon_chain_error)? .map_err(warp_utils::reject::unhandled_error)?
.ok_or_else(|| { .ok_or_else(|| {
warp_utils::reject::custom_not_found(format!( warp_utils::reject::custom_not_found(format!(
"child of block with root {}", "child of block with root {}",
@@ -1248,7 +1249,7 @@ pub fn serve<T: BeaconChainTypes>(
let canonical = chain let canonical = chain
.block_root_at_slot(block.slot(), WhenSlotSkipped::None) .block_root_at_slot(block.slot(), WhenSlotSkipped::None)
.map_err(warp_utils::reject::beacon_chain_error)? .map_err(warp_utils::reject::unhandled_error)?
.is_some_and(|canonical| root == canonical); .is_some_and(|canonical| root == canonical);
let data = api_types::BlockHeaderData { let data = api_types::BlockHeaderData {
@@ -2932,7 +2933,7 @@ pub fn serve<T: BeaconChainTypes>(
let (head, head_execution_status) = chain let (head, head_execution_status) = chain
.canonical_head .canonical_head
.head_and_execution_status() .head_and_execution_status()
.map_err(warp_utils::reject::beacon_chain_error)?; .map_err(warp_utils::reject::unhandled_error)?;
let head_slot = head.head_slot(); let head_slot = head.head_slot();
let current_slot = let current_slot =
chain.slot_clock.now_or_genesis().ok_or_else(|| { chain.slot_clock.now_or_genesis().ok_or_else(|| {
@@ -2992,7 +2993,7 @@ pub fn serve<T: BeaconChainTypes>(
.blocking_response_task(Priority::P0, move || { .blocking_response_task(Priority::P0, move || {
let is_optimistic = chain let is_optimistic = chain
.is_optimistic_or_invalid_head() .is_optimistic_or_invalid_head()
.map_err(warp_utils::reject::beacon_chain_error)?; .map_err(warp_utils::reject::unhandled_error)?;
let is_syncing = !network_globals.sync_state.read().is_synced(); let is_syncing = !network_globals.sync_state.read().is_synced();
@@ -3302,9 +3303,7 @@ pub fn serve<T: BeaconChainTypes>(
task_spawner.blocking_json_task(Priority::P0, move || { task_spawner.blocking_json_task(Priority::P0, move || {
not_synced_filter?; not_synced_filter?;
let current_slot = chain let current_slot = chain.slot().map_err(warp_utils::reject::unhandled_error)?;
.slot()
.map_err(warp_utils::reject::beacon_chain_error)?;
// allow a tolerance of one slot to account for clock skew // allow a tolerance of one slot to account for clock skew
if query.slot > current_slot + 1 { if query.slot > current_slot + 1 {
@@ -3318,7 +3317,7 @@ pub fn serve<T: BeaconChainTypes>(
.produce_unaggregated_attestation(query.slot, query.committee_index) .produce_unaggregated_attestation(query.slot, query.committee_index)
.map(|attestation| attestation.data().clone()) .map(|attestation| attestation.data().clone())
.map(api_types::GenericResponse::from) .map(api_types::GenericResponse::from)
.map_err(warp_utils::reject::beacon_chain_error) .map_err(warp_utils::reject::unhandled_error)
}) })
}, },
); );
@@ -3690,11 +3689,9 @@ pub fn serve<T: BeaconChainTypes>(
.execution_layer .execution_layer
.as_ref() .as_ref()
.ok_or(BeaconChainError::ExecutionLayerMissing) .ok_or(BeaconChainError::ExecutionLayerMissing)
.map_err(warp_utils::reject::beacon_chain_error)?; .map_err(warp_utils::reject::unhandled_error)?;
let current_slot = chain let current_slot = chain.slot().map_err(warp_utils::reject::unhandled_error)?;
.slot()
.map_err(warp_utils::reject::beacon_chain_error)?;
let current_epoch = current_slot.epoch(T::EthSpec::slots_per_epoch()); let current_epoch = current_slot.epoch(T::EthSpec::slots_per_epoch());
debug!( debug!(
@@ -3747,12 +3744,12 @@ pub fn serve<T: BeaconChainTypes>(
.execution_layer .execution_layer
.as_ref() .as_ref()
.ok_or(BeaconChainError::ExecutionLayerMissing) .ok_or(BeaconChainError::ExecutionLayerMissing)
.map_err(warp_utils::reject::beacon_chain_error)?; .map_err(warp_utils::reject::unhandled_error)?;
let current_slot = chain let current_slot = chain
.slot_clock .slot_clock
.now_or_genesis() .now_or_genesis()
.ok_or(BeaconChainError::UnableToReadSlot) .ok_or(BeaconChainError::UnableToReadSlot)
.map_err(warp_utils::reject::beacon_chain_error)?; .map_err(warp_utils::reject::unhandled_error)?;
let current_epoch = current_slot.epoch(T::EthSpec::slots_per_epoch()); let current_epoch = current_slot.epoch(T::EthSpec::slots_per_epoch());
debug!( debug!(
@@ -3848,12 +3845,12 @@ pub fn serve<T: BeaconChainTypes>(
.execution_layer .execution_layer
.as_ref() .as_ref()
.ok_or(BeaconChainError::ExecutionLayerMissing) .ok_or(BeaconChainError::ExecutionLayerMissing)
.map_err(warp_utils::reject::beacon_chain_error)? .map_err(warp_utils::reject::unhandled_error)?
.builder(); .builder();
let builder = arc_builder let builder = arc_builder
.as_ref() .as_ref()
.ok_or(BeaconChainError::BuilderMissing) .ok_or(BeaconChainError::BuilderMissing)
.map_err(warp_utils::reject::beacon_chain_error)?; .map_err(warp_utils::reject::unhandled_error)?;
builder builder
.post_builder_validators(&filtered_registration_data) .post_builder_validators(&filtered_registration_data)
.await .await
@@ -3969,9 +3966,8 @@ pub fn serve<T: BeaconChainTypes>(
chain: Arc<BeaconChain<T>>| { chain: Arc<BeaconChain<T>>| {
task_spawner.blocking_json_task(Priority::P0, move || { task_spawner.blocking_json_task(Priority::P0, move || {
// Ensure the request is for either the current, previous or next epoch. // Ensure the request is for either the current, previous or next epoch.
let current_epoch = chain let current_epoch =
.epoch() chain.epoch().map_err(warp_utils::reject::unhandled_error)?;
.map_err(warp_utils::reject::beacon_chain_error)?;
let prev_epoch = current_epoch.saturating_sub(Epoch::new(1)); let prev_epoch = current_epoch.saturating_sub(Epoch::new(1));
let next_epoch = current_epoch.saturating_add(Epoch::new(1)); let next_epoch = current_epoch.saturating_add(Epoch::new(1));
@@ -4010,9 +4006,8 @@ pub fn serve<T: BeaconChainTypes>(
chain: Arc<BeaconChain<T>>| { chain: Arc<BeaconChain<T>>| {
task_spawner.blocking_json_task(Priority::P0, move || { task_spawner.blocking_json_task(Priority::P0, move || {
// Ensure the request is for either the current, previous or next epoch. // Ensure the request is for either the current, previous or next epoch.
let current_epoch = chain let current_epoch =
.epoch() chain.epoch().map_err(warp_utils::reject::unhandled_error)?;
.map_err(warp_utils::reject::beacon_chain_error)?;
let prev_epoch = current_epoch.saturating_sub(Epoch::new(1)); let prev_epoch = current_epoch.saturating_sub(Epoch::new(1));
let next_epoch = current_epoch.saturating_add(Epoch::new(1)); let next_epoch = current_epoch.saturating_add(Epoch::new(1));

View File

@@ -153,7 +153,7 @@ pub async fn produce_blinded_block_v2<T: BeaconChainTypes>(
BlockProductionVersion::BlindedV2, BlockProductionVersion::BlindedV2,
) )
.await .await
.map_err(warp_utils::reject::block_production_error)?; .map_err(warp_utils::reject::unhandled_error)?;
build_response_v2(chain, block_response_type, endpoint_version, accept_header) build_response_v2(chain, block_response_type, endpoint_version, accept_header)
} }
@@ -184,7 +184,7 @@ pub async fn produce_block_v2<T: BeaconChainTypes>(
BlockProductionVersion::FullV2, BlockProductionVersion::FullV2,
) )
.await .await
.map_err(warp_utils::reject::block_production_error)?; .map_err(warp_utils::reject::unhandled_error)?;
build_response_v2(chain, block_response_type, endpoint_version, accept_header) build_response_v2(chain, block_response_type, endpoint_version, accept_header)
} }

View File

@@ -26,7 +26,7 @@ pub fn proposer_duties<T: BeaconChainTypes>(
.now_or_genesis() .now_or_genesis()
.map(|slot| slot.epoch(T::EthSpec::slots_per_epoch())) .map(|slot| slot.epoch(T::EthSpec::slots_per_epoch()))
.ok_or(BeaconChainError::UnableToReadSlot) .ok_or(BeaconChainError::UnableToReadSlot)
.map_err(warp_utils::reject::beacon_chain_error)?; .map_err(warp_utils::reject::unhandled_error)?;
// Determine what the current epoch would be if we fast-forward our system clock by // Determine what the current epoch would be if we fast-forward our system clock by
// `MAXIMUM_GOSSIP_CLOCK_DISPARITY`. // `MAXIMUM_GOSSIP_CLOCK_DISPARITY`.
@@ -66,7 +66,7 @@ pub fn proposer_duties<T: BeaconChainTypes>(
{ {
let (proposers, dependent_root, execution_status, _fork) = let (proposers, dependent_root, execution_status, _fork) =
compute_proposer_duties_from_head(request_epoch, chain) compute_proposer_duties_from_head(request_epoch, chain)
.map_err(warp_utils::reject::beacon_chain_error)?; .map_err(warp_utils::reject::unhandled_error)?;
convert_to_api_response( convert_to_api_response(
chain, chain,
request_epoch, request_epoch,
@@ -114,7 +114,7 @@ fn try_proposer_duties_from_cache<T: BeaconChainTypes>(
.map_err(warp_utils::reject::beacon_state_error)?; .map_err(warp_utils::reject::beacon_state_error)?;
let execution_optimistic = chain let execution_optimistic = chain
.is_optimistic_or_invalid_head_block(head_block) .is_optimistic_or_invalid_head_block(head_block)
.map_err(warp_utils::reject::beacon_chain_error)?; .map_err(warp_utils::reject::unhandled_error)?;
let dependent_root = match head_epoch.cmp(&request_epoch) { let dependent_root = match head_epoch.cmp(&request_epoch) {
// head_epoch == request_epoch // head_epoch == request_epoch
@@ -163,7 +163,7 @@ fn compute_and_cache_proposer_duties<T: BeaconChainTypes>(
) -> Result<ApiDuties, warp::reject::Rejection> { ) -> Result<ApiDuties, warp::reject::Rejection> {
let (indices, dependent_root, execution_status, fork) = let (indices, dependent_root, execution_status, fork) =
compute_proposer_duties_from_head(current_epoch, chain) compute_proposer_duties_from_head(current_epoch, chain)
.map_err(warp_utils::reject::beacon_chain_error)?; .map_err(warp_utils::reject::unhandled_error)?;
// Prime the proposer shuffling cache with the newly-learned value. // Prime the proposer shuffling cache with the newly-learned value.
chain chain
@@ -171,7 +171,7 @@ fn compute_and_cache_proposer_duties<T: BeaconChainTypes>(
.lock() .lock()
.insert(current_epoch, dependent_root, indices.clone(), fork) .insert(current_epoch, dependent_root, indices.clone(), fork)
.map_err(BeaconChainError::from) .map_err(BeaconChainError::from)
.map_err(warp_utils::reject::beacon_chain_error)?; .map_err(warp_utils::reject::unhandled_error)?;
convert_to_api_response( convert_to_api_response(
chain, chain,
@@ -195,7 +195,7 @@ fn compute_historic_proposer_duties<T: BeaconChainTypes>(
let (cached_head, execution_status) = chain let (cached_head, execution_status) = chain
.canonical_head .canonical_head
.head_and_execution_status() .head_and_execution_status()
.map_err(warp_utils::reject::beacon_chain_error)?; .map_err(warp_utils::reject::unhandled_error)?;
let head = &cached_head.snapshot; let head = &cached_head.snapshot;
if head.beacon_state.current_epoch() <= epoch { if head.beacon_state.current_epoch() <= epoch {
@@ -214,7 +214,7 @@ fn compute_historic_proposer_duties<T: BeaconChainTypes>(
// If we've loaded the head state it might be from a previous epoch, ensure it's in a // If we've loaded the head state it might be from a previous epoch, ensure it's in a
// suitable epoch. // suitable epoch.
ensure_state_is_in_epoch(&mut state, state_root, epoch, &chain.spec) ensure_state_is_in_epoch(&mut state, state_root, epoch, &chain.spec)
.map_err(warp_utils::reject::beacon_chain_error)?; .map_err(warp_utils::reject::unhandled_error)?;
(state, execution_optimistic) (state, execution_optimistic)
} else { } else {
let (state, execution_optimistic, _finalized) = let (state, execution_optimistic, _finalized) =
@@ -234,14 +234,14 @@ fn compute_historic_proposer_duties<T: BeaconChainTypes>(
let indices = state let indices = state
.get_beacon_proposer_indices(&chain.spec) .get_beacon_proposer_indices(&chain.spec)
.map_err(BeaconChainError::from) .map_err(BeaconChainError::from)
.map_err(warp_utils::reject::beacon_chain_error)?; .map_err(warp_utils::reject::unhandled_error)?;
// We can supply the genesis block root as the block root since we know that the only block that // We can supply the genesis block root as the block root since we know that the only block that
// decides its own root is the genesis block. // decides its own root is the genesis block.
let dependent_root = state let dependent_root = state
.proposer_shuffling_decision_root(chain.genesis_block_root) .proposer_shuffling_decision_root(chain.genesis_block_root)
.map_err(BeaconChainError::from) .map_err(BeaconChainError::from)
.map_err(warp_utils::reject::beacon_chain_error)?; .map_err(warp_utils::reject::unhandled_error)?;
convert_to_api_response(chain, epoch, dependent_root, execution_optimistic, indices) convert_to_api_response(chain, epoch, dependent_root, execution_optimistic, indices)
} }
@@ -257,7 +257,7 @@ fn convert_to_api_response<T: BeaconChainTypes>(
) -> Result<ApiDuties, warp::reject::Rejection> { ) -> Result<ApiDuties, warp::reject::Rejection> {
let index_to_pubkey_map = chain let index_to_pubkey_map = chain
.validator_pubkey_bytes_many(&indices) .validator_pubkey_bytes_many(&indices)
.map_err(warp_utils::reject::beacon_chain_error)?; .map_err(warp_utils::reject::unhandled_error)?;
// Map our internal data structure into the API structure. // Map our internal data structure into the API structure.
let proposer_data = indices let proposer_data = indices

View File

@@ -4,7 +4,7 @@ use crate::ExecutionOptimistic;
use beacon_chain::{BeaconChain, BeaconChainTypes}; use beacon_chain::{BeaconChain, BeaconChainTypes};
use eth2::lighthouse::StandardBlockReward; use eth2::lighthouse::StandardBlockReward;
use std::sync::Arc; use std::sync::Arc;
use warp_utils::reject::beacon_chain_error; use warp_utils::reject::unhandled_error;
/// The difference between block_rewards and beacon_block_rewards is the later returns block /// The difference between block_rewards and beacon_block_rewards is the later returns block
/// reward format that satisfies beacon-api specs /// reward format that satisfies beacon-api specs
pub fn compute_beacon_block_rewards<T: BeaconChainTypes>( pub fn compute_beacon_block_rewards<T: BeaconChainTypes>(
@@ -19,7 +19,7 @@ pub fn compute_beacon_block_rewards<T: BeaconChainTypes>(
let rewards = chain let rewards = chain
.compute_beacon_block_reward(block_ref, &mut state) .compute_beacon_block_reward(block_ref, &mut state)
.map_err(beacon_chain_error)?; .map_err(unhandled_error)?;
Ok((rewards, execution_optimistic, finalized)) Ok((rewards, execution_optimistic, finalized))
} }

View File

@@ -30,7 +30,7 @@ impl StateId {
let (cached_head, execution_status) = chain let (cached_head, execution_status) = chain
.canonical_head .canonical_head
.head_and_execution_status() .head_and_execution_status()
.map_err(warp_utils::reject::beacon_chain_error)?; .map_err(warp_utils::reject::unhandled_error)?;
return Ok(( return Ok((
cached_head.head_state_root(), cached_head.head_state_root(),
execution_status.is_optimistic_or_invalid(), execution_status.is_optimistic_or_invalid(),
@@ -56,7 +56,7 @@ impl StateId {
*slot, *slot,
chain chain
.is_optimistic_or_invalid_head() .is_optimistic_or_invalid_head()
.map_err(warp_utils::reject::beacon_chain_error)?, .map_err(warp_utils::reject::unhandled_error)?,
*slot *slot
<= chain <= chain
.canonical_head .canonical_head
@@ -70,11 +70,11 @@ impl StateId {
.store .store
.load_hot_state_summary(root) .load_hot_state_summary(root)
.map_err(BeaconChainError::DBError) .map_err(BeaconChainError::DBError)
.map_err(warp_utils::reject::beacon_chain_error)? .map_err(warp_utils::reject::unhandled_error)?
{ {
let finalization_status = chain let finalization_status = chain
.state_finalization_and_canonicity(root, hot_summary.slot) .state_finalization_and_canonicity(root, hot_summary.slot)
.map_err(warp_utils::reject::beacon_chain_error)?; .map_err(warp_utils::reject::unhandled_error)?;
let finalized = finalization_status.is_finalized(); let finalized = finalization_status.is_finalized();
let fork_choice = chain.canonical_head.fork_choice_read_lock(); let fork_choice = chain.canonical_head.fork_choice_read_lock();
let execution_optimistic = if finalization_status.slot_is_finalized let execution_optimistic = if finalization_status.slot_is_finalized
@@ -94,14 +94,14 @@ impl StateId {
fork_choice fork_choice
.is_optimistic_or_invalid_block(&hot_summary.latest_block_root) .is_optimistic_or_invalid_block(&hot_summary.latest_block_root)
.map_err(BeaconChainError::ForkChoiceError) .map_err(BeaconChainError::ForkChoiceError)
.map_err(warp_utils::reject::beacon_chain_error)? .map_err(warp_utils::reject::unhandled_error)?
}; };
return Ok((*root, execution_optimistic, finalized)); return Ok((*root, execution_optimistic, finalized));
} else if let Some(_cold_state_slot) = chain } else if let Some(_cold_state_slot) = chain
.store .store
.load_cold_state_slot(root) .load_cold_state_slot(root)
.map_err(BeaconChainError::DBError) .map_err(BeaconChainError::DBError)
.map_err(warp_utils::reject::beacon_chain_error)? .map_err(warp_utils::reject::unhandled_error)?
{ {
let fork_choice = chain.canonical_head.fork_choice_read_lock(); let fork_choice = chain.canonical_head.fork_choice_read_lock();
let finalized_root = fork_choice let finalized_root = fork_choice
@@ -111,7 +111,7 @@ impl StateId {
let execution_optimistic = fork_choice let execution_optimistic = fork_choice
.is_optimistic_or_invalid_block_no_fallback(&finalized_root) .is_optimistic_or_invalid_block_no_fallback(&finalized_root)
.map_err(BeaconChainError::ForkChoiceError) .map_err(BeaconChainError::ForkChoiceError)
.map_err(warp_utils::reject::beacon_chain_error)?; .map_err(warp_utils::reject::unhandled_error)?;
return Ok((*root, execution_optimistic, true)); return Ok((*root, execution_optimistic, true));
} else { } else {
return Err(warp_utils::reject::custom_not_found(format!( return Err(warp_utils::reject::custom_not_found(format!(
@@ -124,7 +124,7 @@ impl StateId {
let root = chain let root = chain
.state_root_at_slot(slot) .state_root_at_slot(slot)
.map_err(warp_utils::reject::beacon_chain_error)? .map_err(warp_utils::reject::unhandled_error)?
.ok_or_else(|| { .ok_or_else(|| {
warp_utils::reject::custom_not_found(format!("beacon state at slot {}", slot)) warp_utils::reject::custom_not_found(format!("beacon state at slot {}", slot))
})?; })?;
@@ -178,7 +178,7 @@ impl StateId {
let (cached_head, execution_status) = chain let (cached_head, execution_status) = chain
.canonical_head .canonical_head
.head_and_execution_status() .head_and_execution_status()
.map_err(warp_utils::reject::beacon_chain_error)?; .map_err(warp_utils::reject::unhandled_error)?;
return Ok(( return Ok((
cached_head.snapshot.beacon_state.clone(), cached_head.snapshot.beacon_state.clone(),
execution_status.is_optimistic_or_invalid(), execution_status.is_optimistic_or_invalid(),
@@ -191,7 +191,7 @@ impl StateId {
let state = chain let state = chain
.get_state(&state_root, slot_opt) .get_state(&state_root, slot_opt)
.map_err(warp_utils::reject::beacon_chain_error) .map_err(warp_utils::reject::unhandled_error)
.and_then(|opt| { .and_then(|opt| {
opt.ok_or_else(|| { opt.ok_or_else(|| {
warp_utils::reject::custom_not_found(format!( warp_utils::reject::custom_not_found(format!(
@@ -224,7 +224,7 @@ impl StateId {
let (head, execution_status) = chain let (head, execution_status) = chain
.canonical_head .canonical_head
.head_and_execution_status() .head_and_execution_status()
.map_err(warp_utils::reject::beacon_chain_error)?; .map_err(warp_utils::reject::unhandled_error)?;
return func( return func(
&head.snapshot.beacon_state, &head.snapshot.beacon_state,
execution_status.is_optimistic_or_invalid(), execution_status.is_optimistic_or_invalid(),
@@ -273,7 +273,7 @@ pub fn checkpoint_slot_and_execution_optimistic<T: BeaconChainTypes>(
let execution_optimistic = fork_choice let execution_optimistic = fork_choice
.is_optimistic_or_invalid_block_no_fallback(root) .is_optimistic_or_invalid_block_no_fallback(root)
.map_err(BeaconChainError::ForkChoiceError) .map_err(BeaconChainError::ForkChoiceError)
.map_err(warp_utils::reject::beacon_chain_error)?; .map_err(warp_utils::reject::unhandled_error)?;
Ok((slot, execution_optimistic)) Ok((slot, execution_optimistic))
} }

View File

@@ -6,7 +6,7 @@ use slog::{debug, Logger};
use state_processing::BlockReplayer; use state_processing::BlockReplayer;
use std::sync::Arc; use std::sync::Arc;
use types::{BeaconState, SignedBlindedBeaconBlock}; use types::{BeaconState, SignedBlindedBeaconBlock};
use warp_utils::reject::{beacon_chain_error, custom_not_found}; use warp_utils::reject::{custom_not_found, unhandled_error};
pub fn compute_sync_committee_rewards<T: BeaconChainTypes>( pub fn compute_sync_committee_rewards<T: BeaconChainTypes>(
chain: Arc<BeaconChain<T>>, chain: Arc<BeaconChain<T>>,
@@ -20,7 +20,7 @@ pub fn compute_sync_committee_rewards<T: BeaconChainTypes>(
let reward_payload = chain let reward_payload = chain
.compute_sync_committee_rewards(block.message(), &mut state) .compute_sync_committee_rewards(block.message(), &mut state)
.map_err(beacon_chain_error)?; .map_err(unhandled_error)?;
let data = if reward_payload.is_empty() { let data = if reward_payload.is_empty() {
debug!(log, "compute_sync_committee_rewards returned empty"); debug!(log, "compute_sync_committee_rewards returned empty");
@@ -71,7 +71,7 @@ pub fn get_state_before_applying_block<T: BeaconChainTypes>(
.state_root_iter([Ok((parent_block.state_root(), parent_block.slot()))].into_iter()) .state_root_iter([Ok((parent_block.state_root(), parent_block.slot()))].into_iter())
.minimal_block_root_verification() .minimal_block_root_verification()
.apply_blocks(vec![], Some(block.slot())) .apply_blocks(vec![], Some(block.slot()))
.map_err(beacon_chain_error)?; .map_err(unhandled_error::<BeaconChainError>)?;
Ok(replayer.into_state()) Ok(replayer.into_state())
} }

View File

@@ -39,7 +39,7 @@ pub fn sync_committee_duties<T: BeaconChainTypes>(
// still dependent on the head. So using `is_optimistic_head` is fine for both cases. // still dependent on the head. So using `is_optimistic_head` is fine for both cases.
let execution_optimistic = chain let execution_optimistic = chain
.is_optimistic_or_invalid_head() .is_optimistic_or_invalid_head()
.map_err(warp_utils::reject::beacon_chain_error)?; .map_err(warp_utils::reject::unhandled_error)?;
// Try using the head's sync committees to satisfy the request. This should be sufficient for // Try using the head's sync committees to satisfy the request. This should be sufficient for
// the vast majority of requests. Rather than checking if we think the request will succeed in a // the vast majority of requests. Rather than checking if we think the request will succeed in a
@@ -55,7 +55,7 @@ pub fn sync_committee_duties<T: BeaconChainTypes>(
.. ..
})) }))
| Err(BeaconChainError::SyncDutiesError(BeaconStateError::IncorrectStateVariant)) => (), | Err(BeaconChainError::SyncDutiesError(BeaconStateError::IncorrectStateVariant)) => (),
Err(e) => return Err(warp_utils::reject::beacon_chain_error(e)), Err(e) => return Err(warp_utils::reject::unhandled_error(e)),
} }
let duties = duties_from_state_load(request_epoch, request_indices, altair_fork_epoch, chain) let duties = duties_from_state_load(request_epoch, request_indices, altair_fork_epoch, chain)
@@ -67,7 +67,7 @@ pub fn sync_committee_duties<T: BeaconChainTypes>(
"invalid epoch: {}, current epoch: {}", "invalid epoch: {}, current epoch: {}",
request_epoch, current_epoch request_epoch, current_epoch
)), )),
e => warp_utils::reject::beacon_chain_error(e), e => warp_utils::reject::unhandled_error(e),
})?; })?;
Ok(convert_to_response( Ok(convert_to_response(
verify_unknown_validators(duties, request_epoch, chain)?, verify_unknown_validators(duties, request_epoch, chain)?,
@@ -164,7 +164,7 @@ fn verify_unknown_validators<T: BeaconChainTypes>(
BeaconChainError::SyncDutiesError(BeaconStateError::UnknownValidator(idx)) => { BeaconChainError::SyncDutiesError(BeaconStateError::UnknownValidator(idx)) => {
warp_utils::reject::custom_bad_request(format!("invalid validator index: {idx}")) warp_utils::reject::custom_bad_request(format!("invalid validator index: {idx}"))
} }
e => warp_utils::reject::beacon_chain_error(e), e => warp_utils::reject::unhandled_error(e),
}) })
} }

View File

@@ -5,7 +5,7 @@ use eth2::types::{Epoch, ValidatorStatus};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use std::sync::Arc; use std::sync::Arc;
use warp_utils::reject::beacon_chain_error; use warp_utils::reject::unhandled_error;
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)] #[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct ValidatorCountResponse { pub struct ValidatorCountResponse {
@@ -58,7 +58,7 @@ pub fn get_validator_count<T: BeaconChainTypes>(
} }
Ok::<(), BeaconChainError>(()) Ok::<(), BeaconChainError>(())
}) })
.map_err(beacon_chain_error)?; .map_err(unhandled_error)?;
Ok(ValidatorCountResponse { Ok(ValidatorCountResponse {
active_ongoing, active_ongoing,
@@ -101,7 +101,7 @@ pub fn get_validator_info<T: BeaconChainTypes>(
request_data: ValidatorInfoRequestData, request_data: ValidatorInfoRequestData,
chain: Arc<BeaconChain<T>>, chain: Arc<BeaconChain<T>>,
) -> Result<ValidatorInfoResponse, warp::Rejection> { ) -> Result<ValidatorInfoResponse, warp::Rejection> {
let current_epoch = chain.epoch().map_err(beacon_chain_error)?; let current_epoch = chain.epoch().map_err(unhandled_error)?;
let epochs = current_epoch.saturating_sub(HISTORIC_EPOCHS).as_u64()..=current_epoch.as_u64(); let epochs = current_epoch.saturating_sub(HISTORIC_EPOCHS).as_u64()..=current_epoch.as_u64();

View File

@@ -7,6 +7,7 @@ edition = { workspace = true }
[dependencies] [dependencies]
beacon_chain = { workspace = true } beacon_chain = { workspace = true }
health_metrics = { workspace = true }
lighthouse_network = { workspace = true } lighthouse_network = { workspace = true }
lighthouse_version = { workspace = true } lighthouse_version = { workspace = true }
malloc_utils = { workspace = true } malloc_utils = { workspace = true }

View File

@@ -39,7 +39,7 @@ pub fn gather_prometheus_metrics<T: BeaconChainTypes>(
lighthouse_network::scrape_discovery_metrics(); lighthouse_network::scrape_discovery_metrics();
warp_utils::metrics::scrape_health_metrics(); health_metrics::metrics::scrape_health_metrics();
// It's important to ensure these metrics are explicitly enabled in the case that users aren't // It's important to ensure these metrics are explicitly enabled in the case that users aren't
// using glibc and this function causes panics. // using glibc and this function causes panics.

View File

@@ -6,7 +6,6 @@ edition = { workspace = true }
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
directory = { workspace = true }
eth2_keystore = { workspace = true } eth2_keystore = { workspace = true }
eth2_wallet = { workspace = true } eth2_wallet = { workspace = true }
filesystem = { workspace = true } filesystem = { workspace = true }

View File

@@ -4,13 +4,12 @@
//! attempt) to load into the `crate::intialized_validators::InitializedValidators` struct. //! attempt) to load into the `crate::intialized_validators::InitializedValidators` struct.
use crate::{default_keystore_password_path, read_password_string, write_file_via_temporary}; use crate::{default_keystore_password_path, read_password_string, write_file_via_temporary};
use directory::ensure_dir_exists;
use eth2_keystore::Keystore; use eth2_keystore::Keystore;
use regex::Regex; use regex::Regex;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use slog::{error, Logger}; use slog::{error, Logger};
use std::collections::HashSet; use std::collections::HashSet;
use std::fs::{self, File}; use std::fs::{self, create_dir_all, File};
use std::io; use std::io;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use types::{graffiti::GraffitiString, Address, PublicKey}; use types::{graffiti::GraffitiString, Address, PublicKey};
@@ -229,7 +228,7 @@ impl From<Vec<ValidatorDefinition>> for ValidatorDefinitions {
impl ValidatorDefinitions { impl ValidatorDefinitions {
/// Open an existing file or create a new, empty one if it does not exist. /// Open an existing file or create a new, empty one if it does not exist.
pub fn open_or_create<P: AsRef<Path>>(validators_dir: P) -> Result<Self, Error> { pub fn open_or_create<P: AsRef<Path>>(validators_dir: P) -> Result<Self, Error> {
ensure_dir_exists(validators_dir.as_ref()).map_err(|_| { create_dir_all(validators_dir.as_ref()).map_err(|_| {
Error::UnableToCreateValidatorDir(PathBuf::from(validators_dir.as_ref())) Error::UnableToCreateValidatorDir(PathBuf::from(validators_dir.as_ref()))
})?; })?;
let config_path = validators_dir.as_ref().join(CONFIG_FILENAME); let config_path = validators_dir.as_ref().join(CONFIG_FILENAME);

View File

@@ -1,6 +1,6 @@
use clap::ArgMatches; use clap::ArgMatches;
pub use eth2_network_config::DEFAULT_HARDCODED_NETWORK; pub use eth2_network_config::DEFAULT_HARDCODED_NETWORK;
use std::fs::{self, create_dir_all}; use std::fs;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
/// Names for the default directories. /// Names for the default directories.
@@ -30,17 +30,6 @@ pub fn get_network_dir(matches: &ArgMatches) -> String {
} }
} }
/// Checks if a directory exists in the given path and creates a directory if it does not exist.
pub fn ensure_dir_exists<P: AsRef<Path>>(path: P) -> Result<(), String> {
let path = path.as_ref();
if !path.exists() {
create_dir_all(path).map_err(|e| format!("Unable to create {:?}: {:?}", path, e))?;
}
Ok(())
}
/// If `arg` is in `matches`, parses the value as a path. /// If `arg` is in `matches`, parses the value as a path.
/// ///
/// Otherwise, attempts to find the default directory for the `testnet` from the `matches`. /// Otherwise, attempts to find the default directory for the `testnet` from the `matches`.

View File

@@ -31,10 +31,6 @@ zeroize = { workspace = true }
[dev-dependencies] [dev-dependencies]
tokio = { workspace = true } tokio = { workspace = true }
[target.'cfg(target_os = "linux")'.dependencies]
psutil = { version = "3.3.0", optional = true }
procfs = { version = "0.15.1", optional = true }
[features] [features]
default = ["lighthouse"] default = ["lighthouse"]
lighthouse = ["psutil", "procfs"] lighthouse = []

View File

@@ -88,12 +88,6 @@ pub struct ValidatorInclusionData {
pub is_previous_epoch_head_attester: bool, pub is_previous_epoch_head_attester: bool,
} }
#[cfg(target_os = "linux")]
use {
psutil::cpu::os::linux::CpuTimesExt, psutil::memory::os::linux::VirtualMemoryExt,
psutil::process::Process,
};
/// Reports on the health of the Lighthouse instance. /// Reports on the health of the Lighthouse instance.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct Health { pub struct Health {
@@ -164,69 +158,6 @@ pub struct SystemHealth {
pub misc_os: String, pub misc_os: String,
} }
impl SystemHealth {
#[cfg(not(target_os = "linux"))]
pub fn observe() -> Result<Self, String> {
Err("Health is only available on Linux".into())
}
#[cfg(target_os = "linux")]
pub fn observe() -> Result<Self, String> {
let vm = psutil::memory::virtual_memory()
.map_err(|e| format!("Unable to get virtual memory: {:?}", e))?;
let loadavg =
psutil::host::loadavg().map_err(|e| format!("Unable to get loadavg: {:?}", e))?;
let cpu =
psutil::cpu::cpu_times().map_err(|e| format!("Unable to get cpu times: {:?}", e))?;
let disk_usage = psutil::disk::disk_usage("/")
.map_err(|e| format!("Unable to disk usage info: {:?}", e))?;
let disk = psutil::disk::DiskIoCountersCollector::default()
.disk_io_counters()
.map_err(|e| format!("Unable to get disk counters: {:?}", e))?;
let net = psutil::network::NetIoCountersCollector::default()
.net_io_counters()
.map_err(|e| format!("Unable to get network io counters: {:?}", e))?;
let boot_time = psutil::host::boot_time()
.map_err(|e| format!("Unable to get system boot time: {:?}", e))?
.duration_since(std::time::UNIX_EPOCH)
.map_err(|e| format!("Boot time is lower than unix epoch: {}", e))?
.as_secs();
Ok(Self {
sys_virt_mem_total: vm.total(),
sys_virt_mem_available: vm.available(),
sys_virt_mem_used: vm.used(),
sys_virt_mem_free: vm.free(),
sys_virt_mem_cached: vm.cached(),
sys_virt_mem_buffers: vm.buffers(),
sys_virt_mem_percent: vm.percent(),
sys_loadavg_1: loadavg.one,
sys_loadavg_5: loadavg.five,
sys_loadavg_15: loadavg.fifteen,
cpu_cores: psutil::cpu::cpu_count_physical(),
cpu_threads: psutil::cpu::cpu_count(),
system_seconds_total: cpu.system().as_secs(),
cpu_time_total: cpu.total().as_secs(),
user_seconds_total: cpu.user().as_secs(),
iowait_seconds_total: cpu.iowait().as_secs(),
idle_seconds_total: cpu.idle().as_secs(),
disk_node_bytes_total: disk_usage.total(),
disk_node_bytes_free: disk_usage.free(),
disk_node_reads_total: disk.read_count(),
disk_node_writes_total: disk.write_count(),
network_node_bytes_total_received: net.bytes_recv(),
network_node_bytes_total_transmit: net.bytes_sent(),
misc_node_boot_ts_seconds: boot_time,
misc_os: std::env::consts::OS.to_string(),
})
}
}
/// Process specific health /// Process specific health
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct ProcessHealth { pub struct ProcessHealth {
@@ -244,59 +175,6 @@ pub struct ProcessHealth {
pub pid_process_seconds_total: u64, pub pid_process_seconds_total: u64,
} }
impl ProcessHealth {
#[cfg(not(target_os = "linux"))]
pub fn observe() -> Result<Self, String> {
Err("Health is only available on Linux".into())
}
#[cfg(target_os = "linux")]
pub fn observe() -> Result<Self, String> {
let process =
Process::current().map_err(|e| format!("Unable to get current process: {:?}", e))?;
let process_mem = process
.memory_info()
.map_err(|e| format!("Unable to get process memory info: {:?}", e))?;
let me = procfs::process::Process::myself()
.map_err(|e| format!("Unable to get process: {:?}", e))?;
let stat = me
.stat()
.map_err(|e| format!("Unable to get stat: {:?}", e))?;
let process_times = process
.cpu_times()
.map_err(|e| format!("Unable to get process cpu times : {:?}", e))?;
Ok(Self {
pid: process.pid(),
pid_num_threads: stat.num_threads,
pid_mem_resident_set_size: process_mem.rss(),
pid_mem_virtual_memory_size: process_mem.vms(),
pid_mem_shared_memory_size: process_mem.shared(),
pid_process_seconds_total: process_times.busy().as_secs()
+ process_times.children_system().as_secs()
+ process_times.children_system().as_secs(),
})
}
}
impl Health {
#[cfg(not(target_os = "linux"))]
pub fn observe() -> Result<Self, String> {
Err("Health is only available on Linux".into())
}
#[cfg(target_os = "linux")]
pub fn observe() -> Result<Self, String> {
Ok(Self {
process: ProcessHealth::observe()?,
system: SystemHealth::observe()?,
})
}
}
/// Indicates how up-to-date the Eth1 caches are. /// Indicates how up-to-date the Eth1 caches are.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct Eth1SyncStatusData { pub struct Eth1SyncStatusData {

View File

@@ -0,0 +1,12 @@
[package]
name = "health_metrics"
version = "0.1.0"
edition = { workspace = true }
[dependencies]
eth2 = { workspace = true }
metrics = { workspace = true }
[target.'cfg(target_os = "linux")'.dependencies]
psutil = "3.3.0"
procfs = "0.15.1"

View File

@@ -0,0 +1,2 @@
pub mod metrics;
pub mod observe;

View File

@@ -1,3 +1,4 @@
use crate::observe::Observe;
use eth2::lighthouse::{ProcessHealth, SystemHealth}; use eth2::lighthouse::{ProcessHealth, SystemHealth};
use metrics::*; use metrics::*;
use std::sync::LazyLock; use std::sync::LazyLock;

View File

@@ -0,0 +1,127 @@
use eth2::lighthouse::{Health, ProcessHealth, SystemHealth};
#[cfg(target_os = "linux")]
use {
psutil::cpu::os::linux::CpuTimesExt, psutil::memory::os::linux::VirtualMemoryExt,
psutil::process::Process,
};
pub trait Observe: Sized {
fn observe() -> Result<Self, String>;
}
impl Observe for Health {
#[cfg(not(target_os = "linux"))]
fn observe() -> Result<Self, String> {
Err("Health is only available on Linux".into())
}
#[cfg(target_os = "linux")]
fn observe() -> Result<Self, String> {
Ok(Self {
process: ProcessHealth::observe()?,
system: SystemHealth::observe()?,
})
}
}
impl Observe for SystemHealth {
#[cfg(not(target_os = "linux"))]
fn observe() -> Result<Self, String> {
Err("Health is only available on Linux".into())
}
#[cfg(target_os = "linux")]
fn observe() -> Result<Self, String> {
let vm = psutil::memory::virtual_memory()
.map_err(|e| format!("Unable to get virtual memory: {:?}", e))?;
let loadavg =
psutil::host::loadavg().map_err(|e| format!("Unable to get loadavg: {:?}", e))?;
let cpu =
psutil::cpu::cpu_times().map_err(|e| format!("Unable to get cpu times: {:?}", e))?;
let disk_usage = psutil::disk::disk_usage("/")
.map_err(|e| format!("Unable to disk usage info: {:?}", e))?;
let disk = psutil::disk::DiskIoCountersCollector::default()
.disk_io_counters()
.map_err(|e| format!("Unable to get disk counters: {:?}", e))?;
let net = psutil::network::NetIoCountersCollector::default()
.net_io_counters()
.map_err(|e| format!("Unable to get network io counters: {:?}", e))?;
let boot_time = psutil::host::boot_time()
.map_err(|e| format!("Unable to get system boot time: {:?}", e))?
.duration_since(std::time::UNIX_EPOCH)
.map_err(|e| format!("Boot time is lower than unix epoch: {}", e))?
.as_secs();
Ok(Self {
sys_virt_mem_total: vm.total(),
sys_virt_mem_available: vm.available(),
sys_virt_mem_used: vm.used(),
sys_virt_mem_free: vm.free(),
sys_virt_mem_cached: vm.cached(),
sys_virt_mem_buffers: vm.buffers(),
sys_virt_mem_percent: vm.percent(),
sys_loadavg_1: loadavg.one,
sys_loadavg_5: loadavg.five,
sys_loadavg_15: loadavg.fifteen,
cpu_cores: psutil::cpu::cpu_count_physical(),
cpu_threads: psutil::cpu::cpu_count(),
system_seconds_total: cpu.system().as_secs(),
cpu_time_total: cpu.total().as_secs(),
user_seconds_total: cpu.user().as_secs(),
iowait_seconds_total: cpu.iowait().as_secs(),
idle_seconds_total: cpu.idle().as_secs(),
disk_node_bytes_total: disk_usage.total(),
disk_node_bytes_free: disk_usage.free(),
disk_node_reads_total: disk.read_count(),
disk_node_writes_total: disk.write_count(),
network_node_bytes_total_received: net.bytes_recv(),
network_node_bytes_total_transmit: net.bytes_sent(),
misc_node_boot_ts_seconds: boot_time,
misc_os: std::env::consts::OS.to_string(),
})
}
}
impl Observe for ProcessHealth {
#[cfg(not(target_os = "linux"))]
fn observe() -> Result<Self, String> {
Err("Health is only available on Linux".into())
}
#[cfg(target_os = "linux")]
fn observe() -> Result<Self, String> {
let process =
Process::current().map_err(|e| format!("Unable to get current process: {:?}", e))?;
let process_mem = process
.memory_info()
.map_err(|e| format!("Unable to get process memory info: {:?}", e))?;
let me = procfs::process::Process::myself()
.map_err(|e| format!("Unable to get process: {:?}", e))?;
let stat = me
.stat()
.map_err(|e| format!("Unable to get stat: {:?}", e))?;
let process_times = process
.cpu_times()
.map_err(|e| format!("Unable to get process cpu times : {:?}", e))?;
Ok(Self {
pid: process.pid(),
pid_num_threads: stat.num_threads,
pid_mem_resident_set_size: process_mem.rss(),
pid_mem_virtual_memory_size: process_mem.vms(),
pid_mem_shared_memory_size: process_mem.shared(),
pid_process_seconds_total: process_times.busy().as_secs()
+ process_times.children_system().as_secs()
+ process_times.children_system().as_secs(),
})
}
}

View File

@@ -7,6 +7,7 @@ edition = { workspace = true }
[dependencies] [dependencies]
eth2 = { workspace = true } eth2 = { workspace = true }
health_metrics = { workspace = true }
lighthouse_version = { workspace = true } lighthouse_version = { workspace = true }
metrics = { workspace = true } metrics = { workspace = true }
regex = { workspace = true } regex = { workspace = true }

View File

@@ -1,4 +1,5 @@
use super::types::{BeaconProcessMetrics, ValidatorProcessMetrics}; use super::types::{BeaconProcessMetrics, ValidatorProcessMetrics};
use health_metrics::observe::Observe;
use metrics::{MetricFamily, MetricType}; use metrics::{MetricFamily, MetricType};
use serde_json::json; use serde_json::json;
use std::collections::HashMap; use std::collections::HashMap;

View File

@@ -4,6 +4,7 @@ use std::{path::PathBuf, time::Duration};
use eth2::lighthouse::SystemHealth; use eth2::lighthouse::SystemHealth;
use gather::{gather_beacon_metrics, gather_validator_metrics}; use gather::{gather_beacon_metrics, gather_validator_metrics};
use health_metrics::observe::Observe;
use reqwest::{IntoUrl, Response}; use reqwest::{IntoUrl, Response};
pub use reqwest::{StatusCode, Url}; pub use reqwest::{StatusCode, Url};
use sensitive_url::SensitiveUrl; use sensitive_url::SensitiveUrl;

View File

@@ -12,7 +12,6 @@ insecure_keys = []
bls = { workspace = true } bls = { workspace = true }
deposit_contract = { workspace = true } deposit_contract = { workspace = true }
derivative = { workspace = true } derivative = { workspace = true }
directory = { workspace = true }
eth2_keystore = { workspace = true } eth2_keystore = { workspace = true }
filesystem = { workspace = true } filesystem = { workspace = true }
hex = { workspace = true } hex = { workspace = true }

View File

@@ -1,7 +1,6 @@
use crate::{Error as DirError, ValidatorDir}; use crate::{Error as DirError, ValidatorDir};
use bls::get_withdrawal_credentials; use bls::get_withdrawal_credentials;
use deposit_contract::{encode_eth1_tx_data, Error as DepositError}; use deposit_contract::{encode_eth1_tx_data, Error as DepositError};
use directory::ensure_dir_exists;
use eth2_keystore::{Error as KeystoreError, Keystore, KeystoreBuilder, PlainText}; use eth2_keystore::{Error as KeystoreError, Keystore, KeystoreBuilder, PlainText};
use filesystem::create_with_600_perms; use filesystem::create_with_600_perms;
use rand::{distributions::Alphanumeric, Rng}; use rand::{distributions::Alphanumeric, Rng};
@@ -42,7 +41,7 @@ pub enum Error {
#[cfg(feature = "insecure_keys")] #[cfg(feature = "insecure_keys")]
InsecureKeysError(String), InsecureKeysError(String),
MissingPasswordDir, MissingPasswordDir,
UnableToCreatePasswordDir(String), UnableToCreatePasswordDir(io::Error),
} }
impl From<KeystoreError> for Error { impl From<KeystoreError> for Error {
@@ -163,7 +162,7 @@ impl<'a> Builder<'a> {
} }
if let Some(password_dir) = &self.password_dir { if let Some(password_dir) = &self.password_dir {
ensure_dir_exists(password_dir).map_err(Error::UnableToCreatePasswordDir)?; create_dir_all(password_dir).map_err(Error::UnableToCreatePasswordDir)?;
} }
// The withdrawal keystore must be initialized in order to store it or create an eth1 // The withdrawal keystore must be initialized in order to store it or create an eth1

View File

@@ -6,7 +6,6 @@ edition = { workspace = true }
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
beacon_chain = { workspace = true }
bytes = { workspace = true } bytes = { workspace = true }
eth2 = { workspace = true } eth2 = { workspace = true }
headers = "0.3.2" headers = "0.3.2"
@@ -15,7 +14,6 @@ safe_arith = { workspace = true }
serde = { workspace = true } serde = { workspace = true }
serde_array_query = "0.1.0" serde_array_query = "0.1.0"
serde_json = { workspace = true } serde_json = { workspace = true }
state_processing = { workspace = true }
tokio = { workspace = true } tokio = { workspace = true }
types = { workspace = true } types = { workspace = true }
warp = { workspace = true } warp = { workspace = true }

View File

@@ -3,7 +3,6 @@
pub mod cors; pub mod cors;
pub mod json; pub mod json;
pub mod metrics;
pub mod query; pub mod query;
pub mod reject; pub mod reject;
pub mod task; pub mod task;

View File

@@ -2,6 +2,7 @@ use eth2::types::{ErrorMessage, Failure, IndexedErrorMessage};
use std::convert::Infallible; use std::convert::Infallible;
use std::error::Error; use std::error::Error;
use std::fmt; use std::fmt;
use std::fmt::Debug;
use warp::{http::StatusCode, reject::Reject, reply::Response, Reply}; use warp::{http::StatusCode, reject::Reject, reply::Response, Reply};
#[derive(Debug)] #[derive(Debug)]
@@ -19,15 +20,6 @@ pub fn server_sent_event_error(s: String) -> ServerSentEventError {
ServerSentEventError(s) ServerSentEventError(s)
} }
#[derive(Debug)]
pub struct BeaconChainError(pub beacon_chain::BeaconChainError);
impl Reject for BeaconChainError {}
pub fn beacon_chain_error(e: beacon_chain::BeaconChainError) -> warp::reject::Rejection {
warp::reject::custom(BeaconChainError(e))
}
#[derive(Debug)] #[derive(Debug)]
pub struct BeaconStateError(pub types::BeaconStateError); pub struct BeaconStateError(pub types::BeaconStateError);
@@ -47,21 +39,12 @@ pub fn arith_error(e: safe_arith::ArithError) -> warp::reject::Rejection {
} }
#[derive(Debug)] #[derive(Debug)]
pub struct SlotProcessingError(pub state_processing::SlotProcessingError); pub struct UnhandledError(pub Box<dyn Debug + Send + Sync + 'static>);
impl Reject for SlotProcessingError {} impl Reject for UnhandledError {}
pub fn slot_processing_error(e: state_processing::SlotProcessingError) -> warp::reject::Rejection { pub fn unhandled_error<D: Debug + Send + Sync + 'static>(e: D) -> warp::reject::Rejection {
warp::reject::custom(SlotProcessingError(e)) warp::reject::custom(UnhandledError(Box::new(e)))
}
#[derive(Debug)]
pub struct BlockProductionError(pub beacon_chain::BlockProductionError);
impl Reject for BlockProductionError {}
pub fn block_production_error(e: beacon_chain::BlockProductionError) -> warp::reject::Rejection {
warp::reject::custom(BlockProductionError(e))
} }
#[derive(Debug)] #[derive(Debug)]
@@ -191,16 +174,7 @@ pub async fn handle_rejection(err: warp::Rejection) -> Result<impl warp::Reply,
} else if let Some(e) = err.find::<warp::reject::InvalidQuery>() { } else if let Some(e) = err.find::<warp::reject::InvalidQuery>() {
code = StatusCode::BAD_REQUEST; code = StatusCode::BAD_REQUEST;
message = format!("BAD_REQUEST: invalid query: {}", e); message = format!("BAD_REQUEST: invalid query: {}", e);
} else if let Some(e) = err.find::<crate::reject::BeaconChainError>() { } else if let Some(e) = err.find::<crate::reject::UnhandledError>() {
code = StatusCode::INTERNAL_SERVER_ERROR;
message = format!("UNHANDLED_ERROR: {:?}", e.0);
} else if let Some(e) = err.find::<crate::reject::BeaconStateError>() {
code = StatusCode::INTERNAL_SERVER_ERROR;
message = format!("UNHANDLED_ERROR: {:?}", e.0);
} else if let Some(e) = err.find::<crate::reject::SlotProcessingError>() {
code = StatusCode::INTERNAL_SERVER_ERROR;
message = format!("UNHANDLED_ERROR: {:?}", e.0);
} else if let Some(e) = err.find::<crate::reject::BlockProductionError>() {
code = StatusCode::INTERNAL_SERVER_ERROR; code = StatusCode::INTERNAL_SERVER_ERROR;
message = format!("UNHANDLED_ERROR: {:?}", e.0); message = format!("UNHANDLED_ERROR: {:?}", e.0);
} else if let Some(e) = err.find::<crate::reject::CustomNotFound>() { } else if let Some(e) = err.find::<crate::reject::CustomNotFound>() {

View File

@@ -21,6 +21,7 @@ eth2_keystore = { workspace = true }
ethereum_serde_utils = { workspace = true } ethereum_serde_utils = { workspace = true }
filesystem = { workspace = true } filesystem = { workspace = true }
graffiti_file = { workspace = true } graffiti_file = { workspace = true }
health_metrics = { workspace = true }
initialized_validators = { workspace = true } initialized_validators = { workspace = true }
lighthouse_version = { workspace = true } lighthouse_version = { workspace = true }
logging = { workspace = true } logging = { workspace = true }

View File

@@ -32,6 +32,7 @@ use eth2::lighthouse_vc::{
PublicKeyBytes, SetGraffitiRequest, PublicKeyBytes, SetGraffitiRequest,
}, },
}; };
use health_metrics::observe::Observe;
use lighthouse_version::version_with_platform; use lighthouse_version::version_with_platform;
use logging::SSELoggingComponents; use logging::SSELoggingComponents;
use parking_lot::RwLock; use parking_lot::RwLock;

View File

@@ -5,6 +5,7 @@ edition = { workspace = true }
authors = ["Sigma Prime <contact@sigmaprime.io>"] authors = ["Sigma Prime <contact@sigmaprime.io>"]
[dependencies] [dependencies]
health_metrics = { workspace = true }
lighthouse_version = { workspace = true } lighthouse_version = { workspace = true }
malloc_utils = { workspace = true } malloc_utils = { workspace = true }
metrics = { workspace = true } metrics = { workspace = true }

View File

@@ -206,7 +206,7 @@ pub fn gather_prometheus_metrics<E: EthSpec>(
scrape_allocator_metrics(); scrape_allocator_metrics();
} }
warp_utils::metrics::scrape_health_metrics(); health_metrics::metrics::scrape_health_metrics();
encoder encoder
.encode(&metrics::gather(), &mut buffer) .encode(&metrics::gather(), &mut buffer)