From 7d9429060b252ce3be946e2a21e6e53afc4b9632 Mon Sep 17 00:00:00 2001 From: Tumas Date: Tue, 19 Mar 2024 16:17:51 +0200 Subject: [PATCH] Support keystore files with no extension (#21). Other changes: - Improve user messages regarding validator key loading. --- grandine/src/validators.rs | 50 ++++++++++++++++++++++++++++---------- runtime/src/runtime.rs | 8 +++--- 2 files changed, 40 insertions(+), 18 deletions(-) diff --git a/grandine/src/validators.rs b/grandine/src/validators.rs index 11ccb8c2..18341492 100644 --- a/grandine/src/validators.rs +++ b/grandine/src/validators.rs @@ -8,7 +8,7 @@ use anyhow::{Error, Result}; use bls::{PublicKeyBytes, SecretKey}; use educe::Educe; use eip_2335::Keystore; -use log::warn; +use log::{info, warn}; use rayon::iter::{IntoParallelIterator as _, ParallelIterator as _}; use signer::KeyOrigin; use std_ext::ArcExt; @@ -30,6 +30,11 @@ pub enum Validators { }, } +enum KeystoreExtension { + Json, + None, +} + impl Validators { fn keymap_from_paths( keystore_dir: impl AsRef, @@ -38,7 +43,7 @@ impl Validators { let keystore_dir = keystore_dir.as_ref(); let keystore_password_file = keystore_password_file.as_ref(); let individual_passwords = keystore_password_file.is_dir(); - let keystore_glob = "*.json"; + let keystore_glob = "*"; let old_working_directory = std::env::current_dir()?; @@ -47,20 +52,35 @@ impl Validators { let keystores = glob::glob(keystore_glob) .expect("glob pattern should be valid") .flatten() - .map(|path| { - let keystore_file = keystore_dir.join(path.as_path()); + .filter_map(|path| { + // None is a supported extension + let supported_extension = match path.extension() { + None => Some(KeystoreExtension::None), + Some(extension) => (extension == "json").then_some(KeystoreExtension::Json), + }; - let password_file = if individual_passwords { - let file_stem = path - .file_stem() - .expect("glob patterns above only match paths that have file names"); + if let Some(extension) = supported_extension { + let keystore_file = keystore_dir.join(path.as_path()); - keystore_password_file.join(file_stem).with_extension("txt") - } else { - keystore_password_file.to_path_buf() - }; + let password_file = if individual_passwords { + let file_stem = path + .file_stem() + .expect("glob patterns above only match paths that have file names"); - (keystore_file, password_file) + let password_file = keystore_password_file.join(file_stem); + + match extension { + KeystoreExtension::Json => password_file.with_extension("txt"), + KeystoreExtension::None => password_file, + } + } else { + keystore_password_file.to_path_buf() + }; + + Some((keystore_file, password_file)) + } else { + None + } }) .collect(); @@ -74,6 +94,8 @@ impl Validators { mut validator_key_cache: Option<&mut ValidatorKeyCache>, keystore_storage: &ValidatorKeyCache, ) -> Result, KeyOrigin)>> { + info!("started loading keystore and password files"); + // Collect all passwords and keystores first. // They may be used to load secret keys from the cache. // Secret keys are decrypted later. @@ -129,6 +151,8 @@ impl Validators { let public_key = secret_key.to_public_key().into(); + info!("decrypted validator key {public_key:?}"); + Ok((public_key, secret_key)) })?; diff --git a/runtime/src/runtime.rs b/runtime/src/runtime.rs index 727c8882..c497ab75 100644 --- a/runtime/src/runtime.rs +++ b/runtime/src/runtime.rs @@ -24,7 +24,7 @@ use genesis::GenesisProvider; use http_api::{Channels as HttpApiChannels, HttpApi, HttpApiConfig}; use keymanager::KeyManager; use liveness_tracker::LivenessTracker; -use log::info; +use log::{info, warn}; use metrics::{run_metrics_server, MetricsChannels, MetricsService}; use operation_pools::{AttestationAggPool, BlsToExecutionChangePool, SyncCommitteeAggPool}; use p2p::{ @@ -82,12 +82,10 @@ pub async fn run_after_genesis( .. } = storage_config; - for pubkey in signer.keys() { - info!("loaded validator key {pubkey:?}"); - } - if !signer.is_empty() { info!("loaded {} validator key(s)", signer.keys().len()); + } else if validator_config.keystore_storage_password_file.is_some() { + warn!("failed to load validator keys"); } let (execution_service_tx, execution_service_rx) = mpsc::unbounded();