diff --git a/Cargo.lock b/Cargo.lock index af9d0a0ad88..21fea637f0a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8437,6 +8437,7 @@ dependencies = [ "slashing_protection", "slog", "slot_clock", + "strum", "sysinfo", "system_health", "task_executor", diff --git a/validator_client/Cargo.toml b/validator_client/Cargo.toml index 0b648a81553..90a82b7e3b2 100644 --- a/validator_client/Cargo.toml +++ b/validator_client/Cargo.toml @@ -61,3 +61,4 @@ malloc_utils = { workspace = true } sysinfo = { workspace = true } system_health = { path = "../common/system_health" } logging = { workspace = true } +strum = { workspace = true } diff --git a/validator_client/src/beacon_node_fallback.rs b/validator_client/src/beacon_node_fallback.rs index efff46f9c70..de7ecb5a361 100644 --- a/validator_client/src/beacon_node_fallback.rs +++ b/validator_client/src/beacon_node_fallback.rs @@ -14,9 +14,9 @@ use std::fmt; use std::fmt::Debug; use std::future::Future; use std::marker::PhantomData; -use std::str::FromStr; use std::sync::Arc; use std::time::{Duration, Instant}; +use strum::{EnumString, EnumVariantNames}; use tokio::{sync::RwLock, time::sleep}; use types::{ChainSpec, Config, EthSpec}; @@ -714,24 +714,11 @@ impl BeaconNodeFallback { } /// Serves as a cue for `BeaconNodeFallback` to tell which requests need to be broadcasted. -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +#[derive(Clone, Debug, PartialEq, Deserialize, Serialize, EnumString, EnumVariantNames)] +#[strum(serialize_all = "kebab-case")] pub enum ApiTopic { Attestations, Blocks, Subscriptions, SyncCommittee, } - -impl FromStr for ApiTopic { - type Err = String; - - fn from_str(s: &str) -> Result { - match s.trim() { - "attestations" => Ok(ApiTopic::Attestations), - "blocks" => Ok(ApiTopic::Blocks), - "subscriptions" => Ok(ApiTopic::Subscriptions), - "sync-committee" => Ok(ApiTopic::SyncCommittee), - _ => Err(format!("Unknown API topic: `{s}`")), - } - } -} diff --git a/validator_client/src/config.rs b/validator_client/src/config.rs index cdae217ba6a..f75ab1ae710 100644 --- a/validator_client/src/config.rs +++ b/validator_client/src/config.rs @@ -14,7 +14,6 @@ use slog::{info, Logger}; use std::fs; use std::net::IpAddr; use std::path::PathBuf; -use std::str::FromStr; use std::time::Duration; use types::{Address, GRAFFITI_BYTES_LEN}; @@ -227,9 +226,12 @@ impl Config { config.broadcast_topics = broadcast_topics .split(',') .filter(|t| *t != "none") - .map(ApiTopic::from_str) - .collect::>() - .map_err(|e| format!("Unable to parse API topics to broadcast: {:?}", e))?; + .map(|t| { + t.trim() + .parse::() + .map_err(|_| format!("Unknown API topic to broadcast: {t}")) + }) + .collect::>()?; } /*