Skip to content

Commit 669932a

Browse files
authored
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 <[email protected]> # Conflicts: # Cargo.toml
1 parent b1a19a8 commit 669932a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+303
-315
lines changed

Cargo.lock

Lines changed: 15 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ members = [
3333
"common/eth2_network_config",
3434
"common/eth2_wallet_manager",
3535
"common/filesystem",
36+
"common/health_metrics",
3637
"common/lighthouse_version",
3738
"common/lockfile",
3839
"common/logging",
@@ -252,6 +253,7 @@ filesystem = { path = "common/filesystem" }
252253
fork_choice = { path = "consensus/fork_choice" }
253254
genesis = { path = "beacon_node/genesis" }
254255
gossipsub = { path = "beacon_node/lighthouse_network/gossipsub/" }
256+
health_metrics = { path = "common/health_metrics" }
255257
http_api = { path = "beacon_node/http_api" }
256258
initialized_validators = { path = "validator_client/initialized_validators" }
257259
int_to_bytes = { path = "consensus/int_to_bytes" }

account_manager/src/validator/create.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ use account_utils::{
66
};
77
use clap::{Arg, ArgAction, ArgMatches, Command};
88
use clap_utils::FLAG_HEADER;
9-
use directory::{
10-
ensure_dir_exists, parse_path_or_default_with_flag, DEFAULT_SECRET_DIR, DEFAULT_WALLET_DIR,
11-
};
9+
use directory::{parse_path_or_default_with_flag, DEFAULT_SECRET_DIR, DEFAULT_WALLET_DIR};
1210
use environment::Environment;
1311
use eth2_wallet_manager::WalletManager;
1412
use slashing_protection::{SlashingDatabase, SLASHING_PROTECTION_FILENAME};
1513
use std::ffi::OsStr;
1614
use std::fs;
15+
use std::fs::create_dir_all;
1716
use std::path::{Path, PathBuf};
1817
use types::EthSpec;
1918
use validator_dir::Builder as ValidatorDirBuilder;
@@ -156,8 +155,10 @@ pub fn cli_run<E: EthSpec>(
156155
));
157156
}
158157

159-
ensure_dir_exists(&validator_dir)?;
160-
ensure_dir_exists(&secrets_dir)?;
158+
create_dir_all(&validator_dir)
159+
.map_err(|e| format!("Could not create validator dir at {validator_dir:?}: {e:?}"))?;
160+
create_dir_all(&secrets_dir)
161+
.map_err(|e| format!("Could not create secrets dir at {secrets_dir:?}: {e:?}"))?;
161162

162163
eprintln!("secrets-dir path {:?}", secrets_dir);
163164
eprintln!("wallets-dir path {:?}", wallet_base_dir);

account_manager/src/validator/recover.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ use account_utils::eth2_keystore::{keypair_from_secret, Keystore, KeystoreBuilde
55
use account_utils::{random_password, read_mnemonic_from_cli, STDIN_INPUTS_FLAG};
66
use clap::{Arg, ArgAction, ArgMatches, Command};
77
use clap_utils::FLAG_HEADER;
8-
use directory::ensure_dir_exists;
98
use directory::{parse_path_or_default_with_flag, DEFAULT_SECRET_DIR};
109
use eth2_wallet::bip39::Seed;
1110
use eth2_wallet::{recover_validator_secret_from_mnemonic, KeyType, ValidatorKeystores};
11+
use std::fs::create_dir_all;
1212
use std::path::PathBuf;
1313
use validator_dir::Builder as ValidatorDirBuilder;
1414
pub const CMD: &str = "recover";
@@ -91,8 +91,10 @@ pub fn cli_run(matches: &ArgMatches, validator_dir: PathBuf) -> Result<(), Strin
9191

9292
eprintln!("secrets-dir path: {:?}", secrets_dir);
9393

94-
ensure_dir_exists(&validator_dir)?;
95-
ensure_dir_exists(&secrets_dir)?;
94+
create_dir_all(&validator_dir)
95+
.map_err(|e| format!("Could not create validator dir at {validator_dir:?}: {e:?}"))?;
96+
create_dir_all(&secrets_dir)
97+
.map_err(|e| format!("Could not create secrets dir at {secrets_dir:?}: {e:?}"))?;
9698

9799
eprintln!();
98100
eprintln!("WARNING: KEY RECOVERY CAN LEAD TO DUPLICATING VALIDATORS KEYS, WHICH CAN LEAD TO SLASHING.");

account_manager/src/wallet/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ pub mod recover;
55
use crate::WALLETS_DIR_FLAG;
66
use clap::{Arg, ArgAction, ArgMatches, Command};
77
use clap_utils::FLAG_HEADER;
8-
use directory::{ensure_dir_exists, parse_path_or_default_with_flag, DEFAULT_WALLET_DIR};
8+
use directory::{parse_path_or_default_with_flag, DEFAULT_WALLET_DIR};
9+
use std::fs::create_dir_all;
910
use std::path::PathBuf;
1011

1112
pub const CMD: &str = "wallet";
@@ -44,7 +45,7 @@ pub fn cli_run(matches: &ArgMatches) -> Result<(), String> {
4445
} else {
4546
parse_path_or_default_with_flag(matches, WALLETS_DIR_FLAG, DEFAULT_WALLET_DIR)?
4647
};
47-
ensure_dir_exists(&wallet_base_dir)?;
48+
create_dir_all(&wallet_base_dir).map_err(|_| "Could not create wallet base dir")?;
4849

4950
eprintln!("wallet-dir path: {:?}", wallet_base_dir);
5051

beacon_node/http_api/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ ethereum_serde_utils = { workspace = true }
1717
ethereum_ssz = { workspace = true }
1818
execution_layer = { workspace = true }
1919
futures = { workspace = true }
20+
health_metrics = { workspace = true }
2021
hex = { workspace = true }
2122
lighthouse_network = { workspace = true }
2223
lighthouse_version = { workspace = true }

beacon_node/http_api/src/attestation_performance.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use state_processing::{
77
};
88
use std::sync::Arc;
99
use types::{BeaconState, BeaconStateError, EthSpec, Hash256};
10-
use warp_utils::reject::{beacon_chain_error, custom_bad_request, custom_server_error};
10+
use warp_utils::reject::{custom_bad_request, custom_server_error, unhandled_error};
1111

1212
const MAX_REQUEST_RANGE_EPOCHS: usize = 100;
1313
const BLOCK_ROOT_CHUNK_SIZE: usize = 100;
@@ -50,7 +50,7 @@ pub fn get_attestation_performance<T: BeaconChainTypes>(
5050
let end_slot = end_epoch.end_slot(T::EthSpec::slots_per_epoch());
5151

5252
// Ensure end_epoch is smaller than the current epoch - 1.
53-
let current_epoch = chain.epoch().map_err(beacon_chain_error)?;
53+
let current_epoch = chain.epoch().map_err(unhandled_error)?;
5454
if query.end_epoch >= current_epoch - 1 {
5555
return Err(custom_bad_request(format!(
5656
"end_epoch must be less than the current epoch - 1. current: {}, end: {}",
@@ -83,7 +83,7 @@ pub fn get_attestation_performance<T: BeaconChainTypes>(
8383
let index_range = if target.to_lowercase() == "global" {
8484
chain
8585
.with_head(|head| Ok((0..head.beacon_state.validators().len() as u64).collect()))
86-
.map_err(beacon_chain_error)?
86+
.map_err(unhandled_error::<BeaconChainError>)?
8787
} else {
8888
vec![target.parse::<u64>().map_err(|_| {
8989
custom_bad_request(format!(
@@ -96,10 +96,10 @@ pub fn get_attestation_performance<T: BeaconChainTypes>(
9696
// Load block roots.
9797
let mut block_roots: Vec<Hash256> = chain
9898
.forwards_iter_block_roots_until(start_slot, end_slot)
99-
.map_err(beacon_chain_error)?
99+
.map_err(unhandled_error)?
100100
.map(|res| res.map(|(root, _)| root))
101101
.collect::<Result<Vec<Hash256>, _>>()
102-
.map_err(beacon_chain_error)?;
102+
.map_err(unhandled_error)?;
103103
block_roots.dedup();
104104

105105
// Load first block so we can get its parent.
@@ -113,7 +113,7 @@ pub fn get_attestation_performance<T: BeaconChainTypes>(
113113
.and_then(|maybe_block| {
114114
maybe_block.ok_or(BeaconChainError::MissingBeaconBlock(*first_block_root))
115115
})
116-
.map_err(beacon_chain_error)?;
116+
.map_err(unhandled_error)?;
117117

118118
// Load the block of the prior slot which will be used to build the starting state.
119119
let prior_block = chain
@@ -122,14 +122,14 @@ pub fn get_attestation_performance<T: BeaconChainTypes>(
122122
maybe_block
123123
.ok_or_else(|| BeaconChainError::MissingBeaconBlock(first_block.parent_root()))
124124
})
125-
.map_err(beacon_chain_error)?;
125+
.map_err(unhandled_error)?;
126126

127127
// Load state for block replay.
128128
let state_root = prior_block.state_root();
129129
let state = chain
130130
.get_state(&state_root, Some(prior_slot))
131131
.and_then(|maybe_state| maybe_state.ok_or(BeaconChainError::MissingBeaconState(state_root)))
132-
.map_err(beacon_chain_error)?;
132+
.map_err(unhandled_error)?;
133133

134134
// Allocate an AttestationPerformance vector for each validator in the range.
135135
let mut perfs: Vec<AttestationPerformance> =
@@ -198,7 +198,7 @@ pub fn get_attestation_performance<T: BeaconChainTypes>(
198198
.and_then(|maybe_block| {
199199
maybe_block.ok_or(BeaconChainError::MissingBeaconBlock(*root))
200200
})
201-
.map_err(beacon_chain_error)
201+
.map_err(unhandled_error)
202202
})
203203
.collect::<Result<Vec<_>, _>>()?;
204204

beacon_node/http_api/src/attester_duties.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ pub fn attester_duties<T: BeaconChainTypes>(
1616
request_indices: &[u64],
1717
chain: &BeaconChain<T>,
1818
) -> Result<ApiDuties, warp::reject::Rejection> {
19-
let current_epoch = chain
20-
.epoch()
21-
.map_err(warp_utils::reject::beacon_chain_error)?;
19+
let current_epoch = chain.epoch().map_err(warp_utils::reject::unhandled_error)?;
2220

2321
// Determine what the current epoch would be if we fast-forward our system clock by
2422
// `MAXIMUM_GOSSIP_CLOCK_DISPARITY`.
@@ -57,7 +55,7 @@ fn cached_attestation_duties<T: BeaconChainTypes>(
5755

5856
let (duties, dependent_root, execution_status) = chain
5957
.validator_attestation_duties(request_indices, request_epoch, head_block_root)
60-
.map_err(warp_utils::reject::beacon_chain_error)?;
58+
.map_err(warp_utils::reject::unhandled_error)?;
6159

6260
convert_to_api_response(
6361
duties,
@@ -82,7 +80,7 @@ fn compute_historic_attester_duties<T: BeaconChainTypes>(
8280
let (cached_head, execution_status) = chain
8381
.canonical_head
8482
.head_and_execution_status()
85-
.map_err(warp_utils::reject::beacon_chain_error)?;
83+
.map_err(warp_utils::reject::unhandled_error)?;
8684
let head = &cached_head.snapshot;
8785

8886
if head.beacon_state.current_epoch() <= request_epoch {
@@ -131,13 +129,13 @@ fn compute_historic_attester_duties<T: BeaconChainTypes>(
131129
state
132130
.build_committee_cache(relative_epoch, &chain.spec)
133131
.map_err(BeaconChainError::from)
134-
.map_err(warp_utils::reject::beacon_chain_error)?;
132+
.map_err(warp_utils::reject::unhandled_error)?;
135133

136134
let dependent_root = state
137135
// The only block which decides its own shuffling is the genesis block.
138136
.attester_shuffling_decision_root(chain.genesis_block_root, relative_epoch)
139137
.map_err(BeaconChainError::from)
140-
.map_err(warp_utils::reject::beacon_chain_error)?;
138+
.map_err(warp_utils::reject::unhandled_error)?;
141139

142140
let duties = request_indices
143141
.iter()
@@ -147,7 +145,7 @@ fn compute_historic_attester_duties<T: BeaconChainTypes>(
147145
.map_err(BeaconChainError::from)
148146
})
149147
.collect::<Result<_, _>>()
150-
.map_err(warp_utils::reject::beacon_chain_error)?;
148+
.map_err(warp_utils::reject::unhandled_error)?;
151149

152150
convert_to_api_response(
153151
duties,
@@ -181,7 +179,7 @@ fn ensure_state_knows_attester_duties_for_epoch<E: EthSpec>(
181179
// A "partial" state advance is adequate since attester duties don't rely on state roots.
182180
partial_state_advance(state, Some(state_root), target_slot, spec)
183181
.map_err(BeaconChainError::from)
184-
.map_err(warp_utils::reject::beacon_chain_error)?;
182+
.map_err(warp_utils::reject::unhandled_error)?;
185183
}
186184

187185
Ok(())
@@ -208,7 +206,7 @@ fn convert_to_api_response<T: BeaconChainTypes>(
208206
let usize_indices = indices.iter().map(|i| *i as usize).collect::<Vec<_>>();
209207
let index_to_pubkey_map = chain
210208
.validator_pubkey_bytes_many(&usize_indices)
211-
.map_err(warp_utils::reject::beacon_chain_error)?;
209+
.map_err(warp_utils::reject::unhandled_error)?;
212210

213211
let data = duties
214212
.into_iter()

0 commit comments

Comments
 (0)