From f6e6244226b7017d96ce9655716ef72e56fca665 Mon Sep 17 00:00:00 2001 From: andrussal Date: Wed, 10 Dec 2025 13:29:40 +0100 Subject: [PATCH] Extract shared recovery path setup for nodes --- .../core/src/nodes/common/config/paths.rs | 25 ++++++++++++++++--- testing-framework/core/src/nodes/executor.rs | 16 ++---------- testing-framework/core/src/nodes/validator.rs | 16 ++---------- 3 files changed, 26 insertions(+), 31 deletions(-) diff --git a/testing-framework/core/src/nodes/common/config/paths.rs b/testing-framework/core/src/nodes/common/config/paths.rs index 66fdf66..74b39c9 100644 --- a/testing-framework/core/src/nodes/common/config/paths.rs +++ b/testing-framework/core/src/nodes/common/config/paths.rs @@ -1,4 +1,23 @@ -#![allow(dead_code)] +use std::{fs, io, path::Path}; -/// Shared config path helpers (placeholder). -pub struct RecoveryPathsSetup; +/// Ensure recovery-related directories and placeholder files exist under the +/// given base dir. +pub fn ensure_recovery_paths(base_dir: &Path) -> io::Result<()> { + let recovery_dir = base_dir.join("recovery"); + fs::create_dir_all(&recovery_dir)?; + + let mempool_path = recovery_dir.join("mempool.json"); + if !mempool_path.exists() { + fs::write(&mempool_path, "{}")?; + } + + let blend_core_path = recovery_dir.join("blend").join("core.json"); + if let Some(parent) = blend_core_path.parent() { + fs::create_dir_all(parent)?; + } + if !blend_core_path.exists() { + fs::write(&blend_core_path, "{}")?; + } + + Ok(()) +} diff --git a/testing-framework/core/src/nodes/executor.rs b/testing-framework/core/src/nodes/executor.rs index d793316..41f87c5 100644 --- a/testing-framework/core/src/nodes/executor.rs +++ b/testing-framework/core/src/nodes/executor.rs @@ -30,7 +30,7 @@ use crate::{ LOGS_PREFIX, common::{ binary::{BinaryConfig, BinaryResolver}, - config::injection::inject_ibd_into_cryptarchia, + config::{injection::inject_ibd_into_cryptarchia, paths::ensure_recovery_paths}, }, }, }; @@ -76,19 +76,7 @@ impl Executor { // Ensure recovery files/dirs exist so services that persist state do not fail // on startup. - let recovery_dir = dir.path().join("recovery"); - let _ = std::fs::create_dir_all(&recovery_dir); - let mempool_path = recovery_dir.join("mempool.json"); - if !mempool_path.exists() { - let _ = std::fs::write(&mempool_path, "{}"); - } - let blend_core_path = recovery_dir.join("blend").join("core.json"); - if let Some(parent) = blend_core_path.parent() { - let _ = std::fs::create_dir_all(parent); - } - if !blend_core_path.exists() { - let _ = std::fs::write(&blend_core_path, "{}"); - } + let _ = ensure_recovery_paths(dir.path()); if !*IS_DEBUG_TRACING { if let Ok(env_dir) = std::env::var("NOMOS_LOG_DIR") { diff --git a/testing-framework/core/src/nodes/validator.rs b/testing-framework/core/src/nodes/validator.rs index f136afe..5663b71 100644 --- a/testing-framework/core/src/nodes/validator.rs +++ b/testing-framework/core/src/nodes/validator.rs @@ -29,7 +29,7 @@ use crate::{ LOGS_PREFIX, common::{ binary::{BinaryConfig, BinaryResolver}, - config::injection::inject_ibd_into_cryptarchia, + config::{injection::inject_ibd_into_cryptarchia, paths::ensure_recovery_paths}, }, }, }; @@ -103,19 +103,7 @@ impl Validator { // Ensure recovery files/dirs exist so services that persist state do not fail // on startup. - let recovery_dir = dir.path().join("recovery"); - let _ = std::fs::create_dir_all(&recovery_dir); - let mempool_path = recovery_dir.join("mempool.json"); - if !mempool_path.exists() { - let _ = std::fs::write(&mempool_path, "{}"); - } - let blend_core_path = recovery_dir.join("blend").join("core.json"); - if let Some(parent) = blend_core_path.parent() { - let _ = std::fs::create_dir_all(parent); - } - if !blend_core_path.exists() { - let _ = std::fs::write(&blend_core_path, "{}"); - } + let _ = ensure_recovery_paths(dir.path()); if !*IS_DEBUG_TRACING { if let Ok(env_dir) = std::env::var("NOMOS_LOG_DIR") {