From 35bf49c48cbf9d4b08e059dea569ff44f2a1923d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Stuczy=C5=84ski?= Date: Thu, 6 Mar 2025 11:24:03 +0000 Subject: [PATCH] chore: additional logs when attempting to load ecash keys (#5567) --- common/pemstore/Cargo.toml | 1 + common/pemstore/src/lib.rs | 5 +++++ nym-api/src/ecash/dkg/controller/keys.rs | 17 ++++++++++------- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/common/pemstore/Cargo.toml b/common/pemstore/Cargo.toml index f3bc33a6ef..f8d13391dd 100644 --- a/common/pemstore/Cargo.toml +++ b/common/pemstore/Cargo.toml @@ -9,3 +9,4 @@ repository = { workspace = true } [dependencies] pem = { workspace = true } +tracing = { workspace = true } \ No newline at end of file diff --git a/common/pemstore/src/lib.rs b/common/pemstore/src/lib.rs index bd36158229..9f6d3e283b 100644 --- a/common/pemstore/src/lib.rs +++ b/common/pemstore/src/lib.rs @@ -6,6 +6,7 @@ use pem::Pem; use std::fs::File; use std::io::{self, Read, Write}; use std::path::{Path, PathBuf}; +use tracing::debug; pub mod traits; @@ -46,6 +47,10 @@ where T: PemStorableKey, P: AsRef, { + debug!( + "attempting to load key with the following pem type: {}", + T::pem_type() + ); let key_pem = read_pem_file(path)?; if T::pem_type() != key_pem.tag { diff --git a/nym-api/src/ecash/dkg/controller/keys.rs b/nym-api/src/ecash/dkg/controller/keys.rs index bfbaa8c28d..f0038e4869 100644 --- a/nym-api/src/ecash/dkg/controller/keys.rs +++ b/nym-api/src/ecash/dkg/controller/keys.rs @@ -10,7 +10,7 @@ use nym_dkg::bte::keys::KeyPair as DkgKeyPair; use rand::{CryptoRng, RngCore}; use std::path::Path; use thiserror::__private::AsDisplay; -use tracing::warn; +use tracing::{debug, warn}; pub(crate) fn init_bte_keypair( rng: &mut R, @@ -39,17 +39,20 @@ pub(crate) fn load_bte_keypair(config: &config::EcashSigner) -> anyhow::Result anyhow::Result> { + let storage_path = &config.storage_paths.ecash_key_path; + debug!( + "attempting to ecash keypair from {}", + storage_path.display() + ); if !config.storage_paths.ecash_key_path.exists() { + debug!("the provided filepath doesn't exist - the key won't be loaded"); return Ok(None); } - if let Ok(ecash_key) = + let ecash_key = nym_pemstore::load_key::(&config.storage_paths.ecash_key_path) - { - return Ok(Some(ecash_key)); - } - - bail!("ecash key load failure") + .context("failed to load ecash key")?; + Ok(Some(ecash_key)) } // the keys can be considered valid if they were generated for the current dkg epoch