From 15f1fbeec52dec8413237fea8fcb17de217544c7 Mon Sep 17 00:00:00 2001 From: cuiweixie Date: Sat, 6 Dec 2025 22:38:41 +0800 Subject: [PATCH 1/3] feat: add --datadir.min-free-disk flag like in geth --- Cargo.lock | 1 + crates/cli/commands/src/node.rs | 79 +++++++++++- crates/node/core/Cargo.toml | 1 + crates/node/core/src/args/datadir_args.rs | 54 ++++++++ crates/node/core/src/utils.rs | 146 +++++++++++++++++++++- 5 files changed, 279 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7460cfc0513..294a8a08140 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9191,6 +9191,7 @@ dependencies = [ "serde", "shellexpand", "strum 0.27.2", + "sysinfo", "thiserror 2.0.17", "tokio", "toml", diff --git a/crates/cli/commands/src/node.rs b/crates/cli/commands/src/node.rs index cba857a3a84..6aea8362d45 100644 --- a/crates/cli/commands/src/node.rs +++ b/crates/cli/commands/src/node.rs @@ -12,10 +12,14 @@ use reth_node_core::{ DatabaseArgs, DatadirArgs, DebugArgs, DevArgs, EngineArgs, EraArgs, MetricArgs, NetworkArgs, PayloadBuilderArgs, PruningArgs, RpcServerArgs, StaticFilesArgs, TxPoolArgs, }, + dirs::DataDirPath, node_config::NodeConfig, + utils::is_disk_space_low, version, }; +use reth_tasks::{shutdown::Shutdown, TaskExecutor}; use std::{ffi::OsString, fmt, path::PathBuf, sync::Arc}; +use tracing::error; /// Start the node #[derive(Debug, Parser)] @@ -172,6 +176,9 @@ where ext, } = self; + // Save min_free_disk before moving datadir + let min_free_disk_mb = datadir.min_free_disk; + // set up node config let mut node_config = NodeConfig { datadir, @@ -195,6 +202,17 @@ where let data_dir = node_config.datadir(); let db_path = data_dir.db(); + // Check disk space at startup if min_free_disk is configured + if min_free_disk_mb > 0 { + use reth_node_core::utils::is_disk_space_low; + if is_disk_space_low(data_dir.data_dir(), min_free_disk_mb) { + eyre::bail!( + "Insufficient disk space: available space is below minimum threshold of {} MB", + min_free_disk_mb + ); + } + } + tracing::info!(target: "reth::cli", path = ?db_path, "Opening database"); let database = Arc::new(init_db(db_path.clone(), self.db.database_args())?.with_metrics()); @@ -202,9 +220,27 @@ where node_config = node_config.with_unused_ports(); } + // Spawn disk space monitoring task if min_free_disk is configured + // Start monitoring immediately after database is opened + if min_free_disk_mb > 0 { + let data_dir_for_monitor = data_dir.clone(); + let shutdown = ctx.task_executor.on_shutdown_signal().clone(); + let task_executor = ctx.task_executor.clone(); + + ctx.task_executor.spawn_critical( + "disk space monitor", + Box::pin(disk_space_monitor_task( + data_dir_for_monitor, + min_free_disk_mb, + shutdown, + task_executor, + )), + ); + } + let builder = NodeBuilder::new(node_config) .with_database(database) - .with_launch_context(ctx.task_executor); + .with_launch_context(ctx.task_executor.clone()); launcher.entrypoint(builder, ext).await } @@ -217,6 +253,47 @@ impl NodeCommand { } } +/// Disk space monitoring task that periodically checks disk space and triggers shutdown if below threshold. +async fn disk_space_monitor_task( + data_dir: reth_node_core::dirs::ChainPath, + min_free_disk_mb: u64, + mut shutdown: Shutdown, + task_executor: TaskExecutor, +) { + use tokio::time::{interval, Duration as TokioDuration}; + + let mut interval = interval(TokioDuration::from_secs(60)); // Check every minute + interval.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Skip); + + loop { + tokio::select! { + _ = interval.tick() => { + if is_disk_space_low(data_dir.data_dir(), min_free_disk_mb) { + error!( + target: "reth::cli", + ?data_dir, + available_threshold = min_free_disk_mb, + "Disk space below minimum threshold, initiating shutdown" + ); + // Trigger graceful shutdown + if let Err(e) = task_executor.initiate_graceful_shutdown() { + error!( + target: "reth::cli", + %e, + "Failed to initiate graceful shutdown" + ); + } + return; + } + } + _ = &mut shutdown => { + // Normal shutdown signal received + return; + } + } + } +} + /// No Additional arguments #[derive(Debug, Clone, Copy, Default, Args)] #[non_exhaustive] diff --git a/crates/node/core/Cargo.toml b/crates/node/core/Cargo.toml index 28dc12b2c7b..e4e99d0a803 100644 --- a/crates/node/core/Cargo.toml +++ b/crates/node/core/Cargo.toml @@ -60,6 +60,7 @@ ipnet.workspace = true # io dirs-next.workspace = true shellexpand.workspace = true +sysinfo = { workspace = true, features = ["disk"] } # obs tracing.workspace = true diff --git a/crates/node/core/src/args/datadir_args.rs b/crates/node/core/src/args/datadir_args.rs index cb0590f1779..1cc0424df5a 100644 --- a/crates/node/core/src/args/datadir_args.rs +++ b/crates/node/core/src/args/datadir_args.rs @@ -27,6 +27,16 @@ pub struct DatadirArgs { verbatim_doc_comment )] pub static_files_path: Option, + + /// Minimum free disk space in MB, once reached triggers auto shut down (default = 0, disabled). + #[arg( + long = "datadir.min-free-disk", + alias = "datadir.min_free_disk", + value_name = "MB", + default_value_t = 0, + verbatim_doc_comment + )] + pub min_free_disk: u64, } impl DatadirArgs { @@ -55,4 +65,48 @@ mod tests { let args = CommandParser::::parse_from(["reth"]).args; assert_eq!(args, default_args); } + + #[test] + fn test_parse_min_free_disk_flag() { + // Test with hyphen format + let args = CommandParser::::parse_from([ + "reth", + "--datadir.min-free-disk", + "1000", + ]) + .args; + assert_eq!(args.min_free_disk, 1000); + + // Test with underscore format (alias) + let args = CommandParser::::parse_from([ + "reth", + "--datadir.min_free_disk", + "500", + ]) + .args; + assert_eq!(args.min_free_disk, 500); + + // Test default value (0 = disabled) + let args = CommandParser::::parse_from(["reth"]).args; + assert_eq!(args.min_free_disk, 0); + } + + #[test] + fn test_min_free_disk_default() { + let args = DatadirArgs::default(); + assert_eq!(args.min_free_disk, 0, "Default should be 0 (disabled)"); + } + + #[test] + fn test_min_free_disk_with_datadir() { + let args = CommandParser::::parse_from([ + "reth", + "--datadir", + "/tmp/test-datadir", + "--datadir.min-free-disk", + "2000", + ]) + .args; + assert_eq!(args.min_free_disk, 2000); + } } diff --git a/crates/node/core/src/utils.rs b/crates/node/core/src/utils.rs index fbb56b24ee7..2387db21bfe 100644 --- a/crates/node/core/src/utils.rs +++ b/crates/node/core/src/utils.rs @@ -14,7 +14,7 @@ use std::{ env::VarError, path::{Path, PathBuf}, }; -use tracing::{debug, info}; +use tracing::{debug, info, warn}; /// Parses a user-specified path with support for environment variables and common shorthands (e.g. /// ~ for the user's home directory). @@ -89,3 +89,147 @@ where Ok(block) } + +/// Check available disk space for the given path using sysinfo. +/// +/// Returns the available space in MB, or None if the check fails. +pub fn get_available_disk_space_mb(path: &Path) -> Option { + use sysinfo::Disks; + + // Find the disk that contains the given path + let path_canonical = match std::fs::canonicalize(path) { + Ok(p) => p, + Err(_) => return None, + }; + + let disks = Disks::new_with_refreshed_list(); + + // Find the disk that contains the given path + for disk in disks.iter() { + let mount_point = disk.mount_point(); + if path_canonical.starts_with(mount_point) { + // Get available space in bytes, convert to MB + let available_bytes = disk.available_space(); + return Some(available_bytes / (1024 * 1024)); + } + } + + None +} + +/// Check if disk space is below the minimum threshold. +/// +/// Returns true if the available disk space is below the minimum threshold (in MB). +pub fn is_disk_space_low(path: &Path, min_free_disk_mb: u64) -> bool { + if min_free_disk_mb == 0 { + return false; // Feature disabled + } + + match get_available_disk_space_mb(path) { + Some(available_mb) => { + if available_mb <= min_free_disk_mb { + warn!( + target: "reth::cli", + ?path, + available_mb, + min_free_disk_mb, + "Disk space below minimum threshold" + ); + return true; + } + false + } + None => { + warn!( + target: "reth::cli", + ?path, + "Failed to check disk space, continuing anyway" + ); + false + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + use std::path::Path; + + #[test] + fn test_is_disk_space_low_disabled() { + // When min_free_disk is 0, feature is disabled + let temp_dir = std::env::temp_dir(); + assert!(!is_disk_space_low(&temp_dir, 0), "Should return false when disabled"); + } + + #[test] + fn test_is_disk_space_low_with_valid_path() { + // Test with a valid path (should not panic) + // We can't easily mock sysinfo, so we just test that it doesn't panic + // and returns a boolean value + let temp_dir = std::env::temp_dir(); + let result = is_disk_space_low(&temp_dir, 1_000_000_000); // Very large threshold + // Should return either true or false, but not panic + assert!(result == true || result == false); + } + + #[test] + fn test_is_disk_space_low_with_invalid_path() { + // Test with a non-existent path + let invalid_path = Path::new("/nonexistent/path/that/does/not/exist"); + // Should not panic, but may return false (feature disabled) or handle gracefully + let result = is_disk_space_low(invalid_path, 1000); + // Should not panic, result depends on sysinfo behavior + assert!(result == true || result == false); + } + + #[test] + fn test_get_available_disk_space_mb_with_valid_path() { + // Test with a valid path + let temp_dir = std::env::temp_dir(); + let result = get_available_disk_space_mb(&temp_dir); + // Should return Some(u64) if successful, or None if it fails + match result { + Some(mb) => { + // If successful, should be a reasonable value (not 0 for temp dir) + assert!(mb > 0 || mb == 0, "Available space should be a valid number"); + } + None => { + // It's okay if it fails, sysinfo might not work in all test environments + } + } + } + + #[test] + fn test_get_available_disk_space_mb_with_invalid_path() { + // Test with a non-existent path + let invalid_path = Path::new("/nonexistent/path/that/does/not/exist"); + let result = get_available_disk_space_mb(invalid_path); + // Should return None for invalid paths + assert_eq!(result, None); + } + + #[test] + fn test_is_disk_space_low_threshold_comparison() { + // Test that the function correctly compares available space with threshold + let temp_dir = std::env::temp_dir(); + + if let Some(available_mb) = get_available_disk_space_mb(&temp_dir) { + // Test with a threshold smaller than available space (should pass - space is sufficient) + if available_mb > 0 { + let result_small = is_disk_space_low(&temp_dir, available_mb.saturating_sub(1)); + assert!(!result_small, "Should pass (return false) when threshold is less than available space"); + } + + // Test with a threshold larger than available space (should fail - space is insufficient) + let result_large = is_disk_space_low(&temp_dir, available_mb.saturating_add(1)); + assert!(result_large, "Should fail (return true) when threshold is greater than available space"); + + // Test with threshold equal to available space (edge case) + // When available == threshold, should trigger shutdown (return true) because "once reached" includes equality + let result_equal = is_disk_space_low(&temp_dir, available_mb); + assert!(result_equal, "Should fail (return true) when threshold equals available space, as 'once reached' includes equality"); + } + // If we can't get disk space, that's okay - test environment might not support it + } +} From 2ccf8d1e7e51cdab6a59c080e0a04be124228d1e Mon Sep 17 00:00:00 2001 From: cuiweixie Date: Sat, 6 Dec 2025 23:06:17 +0800 Subject: [PATCH 2/3] fix: lint error --- crates/cli/commands/src/node.rs | 9 ++--- crates/node/core/src/args/datadir_args.rs | 21 +++++------ crates/node/core/src/utils.rs | 35 ++++++++++++------- docs/vocs/docs/pages/cli/op-reth/db.mdx | 6 ++++ .../vocs/docs/pages/cli/op-reth/import-op.mdx | 6 ++++ .../pages/cli/op-reth/import-receipts-op.mdx | 6 ++++ .../docs/pages/cli/op-reth/init-state.mdx | 6 ++++ docs/vocs/docs/pages/cli/op-reth/init.mdx | 6 ++++ docs/vocs/docs/pages/cli/op-reth/node.mdx | 6 ++++ docs/vocs/docs/pages/cli/op-reth/p2p/body.mdx | 6 ++++ .../docs/pages/cli/op-reth/p2p/header.mdx | 6 ++++ docs/vocs/docs/pages/cli/op-reth/prune.mdx | 6 ++++ .../docs/pages/cli/op-reth/re-execute.mdx | 6 ++++ .../docs/pages/cli/op-reth/stage/drop.mdx | 6 ++++ .../docs/pages/cli/op-reth/stage/dump.mdx | 6 ++++ .../vocs/docs/pages/cli/op-reth/stage/run.mdx | 6 ++++ .../docs/pages/cli/op-reth/stage/unwind.mdx | 6 ++++ docs/vocs/docs/pages/cli/reth/db.mdx | 6 ++++ docs/vocs/docs/pages/cli/reth/download.mdx | 6 ++++ docs/vocs/docs/pages/cli/reth/export-era.mdx | 6 ++++ docs/vocs/docs/pages/cli/reth/import-era.mdx | 6 ++++ docs/vocs/docs/pages/cli/reth/import.mdx | 6 ++++ docs/vocs/docs/pages/cli/reth/init-state.mdx | 6 ++++ docs/vocs/docs/pages/cli/reth/init.mdx | 6 ++++ docs/vocs/docs/pages/cli/reth/node.mdx | 6 ++++ docs/vocs/docs/pages/cli/reth/p2p/body.mdx | 6 ++++ docs/vocs/docs/pages/cli/reth/p2p/header.mdx | 6 ++++ docs/vocs/docs/pages/cli/reth/prune.mdx | 6 ++++ docs/vocs/docs/pages/cli/reth/re-execute.mdx | 6 ++++ docs/vocs/docs/pages/cli/reth/stage/drop.mdx | 6 ++++ docs/vocs/docs/pages/cli/reth/stage/dump.mdx | 6 ++++ docs/vocs/docs/pages/cli/reth/stage/run.mdx | 6 ++++ .../vocs/docs/pages/cli/reth/stage/unwind.mdx | 6 ++++ 33 files changed, 215 insertions(+), 30 deletions(-) diff --git a/crates/cli/commands/src/node.rs b/crates/cli/commands/src/node.rs index 6aea8362d45..100868aa83f 100644 --- a/crates/cli/commands/src/node.rs +++ b/crates/cli/commands/src/node.rs @@ -226,7 +226,7 @@ where let data_dir_for_monitor = data_dir.clone(); let shutdown = ctx.task_executor.on_shutdown_signal().clone(); let task_executor = ctx.task_executor.clone(); - + ctx.task_executor.spawn_critical( "disk space monitor", Box::pin(disk_space_monitor_task( @@ -253,7 +253,8 @@ impl NodeCommand { } } -/// Disk space monitoring task that periodically checks disk space and triggers shutdown if below threshold. +/// Disk space monitoring task that periodically checks disk space and triggers shutdown if below +/// threshold. async fn disk_space_monitor_task( data_dir: reth_node_core::dirs::ChainPath, min_free_disk_mb: u64, @@ -261,10 +262,10 @@ async fn disk_space_monitor_task( task_executor: TaskExecutor, ) { use tokio::time::{interval, Duration as TokioDuration}; - + let mut interval = interval(TokioDuration::from_secs(60)); // Check every minute interval.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Skip); - + loop { tokio::select! { _ = interval.tick() => { diff --git a/crates/node/core/src/args/datadir_args.rs b/crates/node/core/src/args/datadir_args.rs index 1cc0424df5a..90b153f2152 100644 --- a/crates/node/core/src/args/datadir_args.rs +++ b/crates/node/core/src/args/datadir_args.rs @@ -28,7 +28,8 @@ pub struct DatadirArgs { )] pub static_files_path: Option, - /// Minimum free disk space in MB, once reached triggers auto shut down (default = 0, disabled). + /// Minimum free disk space in MB, once reached triggers auto shut down (default = 0, + /// disabled). #[arg( long = "datadir.min-free-disk", alias = "datadir.min_free_disk", @@ -69,21 +70,15 @@ mod tests { #[test] fn test_parse_min_free_disk_flag() { // Test with hyphen format - let args = CommandParser::::parse_from([ - "reth", - "--datadir.min-free-disk", - "1000", - ]) - .args; + let args = + CommandParser::::parse_from(["reth", "--datadir.min-free-disk", "1000"]) + .args; assert_eq!(args.min_free_disk, 1000); // Test with underscore format (alias) - let args = CommandParser::::parse_from([ - "reth", - "--datadir.min_free_disk", - "500", - ]) - .args; + let args = + CommandParser::::parse_from(["reth", "--datadir.min_free_disk", "500"]) + .args; assert_eq!(args.min_free_disk, 500); // Test default value (0 = disabled) diff --git a/crates/node/core/src/utils.rs b/crates/node/core/src/utils.rs index 2387db21bfe..9087704bef8 100644 --- a/crates/node/core/src/utils.rs +++ b/crates/node/core/src/utils.rs @@ -95,15 +95,15 @@ where /// Returns the available space in MB, or None if the check fails. pub fn get_available_disk_space_mb(path: &Path) -> Option { use sysinfo::Disks; - + // Find the disk that contains the given path let path_canonical = match std::fs::canonicalize(path) { Ok(p) => p, Err(_) => return None, }; - + let disks = Disks::new_with_refreshed_list(); - + // Find the disk that contains the given path for disk in disks.iter() { let mount_point = disk.mount_point(); @@ -113,7 +113,7 @@ pub fn get_available_disk_space_mb(path: &Path) -> Option { return Some(available_bytes / (1024 * 1024)); } } - + None } @@ -169,7 +169,7 @@ mod tests { // and returns a boolean value let temp_dir = std::env::temp_dir(); let result = is_disk_space_low(&temp_dir, 1_000_000_000); // Very large threshold - // Should return either true or false, but not panic + // Should return either true or false, but not panic assert!(result == true || result == false); } @@ -213,20 +213,29 @@ mod tests { fn test_is_disk_space_low_threshold_comparison() { // Test that the function correctly compares available space with threshold let temp_dir = std::env::temp_dir(); - + if let Some(available_mb) = get_available_disk_space_mb(&temp_dir) { - // Test with a threshold smaller than available space (should pass - space is sufficient) + // Test with a threshold smaller than available space (should pass - space is + // sufficient) if available_mb > 0 { let result_small = is_disk_space_low(&temp_dir, available_mb.saturating_sub(1)); - assert!(!result_small, "Should pass (return false) when threshold is less than available space"); + assert!( + !result_small, + "Should pass (return false) when threshold is less than available space" + ); } - - // Test with a threshold larger than available space (should fail - space is insufficient) + + // Test with a threshold larger than available space (should fail - space is + // insufficient) let result_large = is_disk_space_low(&temp_dir, available_mb.saturating_add(1)); - assert!(result_large, "Should fail (return true) when threshold is greater than available space"); - + assert!( + result_large, + "Should fail (return true) when threshold is greater than available space" + ); + // Test with threshold equal to available space (edge case) - // When available == threshold, should trigger shutdown (return true) because "once reached" includes equality + // When available == threshold, should trigger shutdown (return true) because "once + // reached" includes equality let result_equal = is_disk_space_low(&temp_dir, available_mb); assert!(result_equal, "Should fail (return true) when threshold equals available space, as 'once reached' includes equality"); } diff --git a/docs/vocs/docs/pages/cli/op-reth/db.mdx b/docs/vocs/docs/pages/cli/op-reth/db.mdx index 4de2e9c0bd0..37f2d5401ed 100644 --- a/docs/vocs/docs/pages/cli/op-reth/db.mdx +++ b/docs/vocs/docs/pages/cli/op-reth/db.mdx @@ -43,6 +43,12 @@ Datadir: --datadir.static-files The absolute path to store static files in. + --datadir.min-free-disk + Minimum free disk space in MB, once reached triggers auto shut down (default = 0, + disabled). + + [default: 0] + --config The path to the configuration file to use diff --git a/docs/vocs/docs/pages/cli/op-reth/import-op.mdx b/docs/vocs/docs/pages/cli/op-reth/import-op.mdx index 4468b8f1c75..988c853a21f 100644 --- a/docs/vocs/docs/pages/cli/op-reth/import-op.mdx +++ b/docs/vocs/docs/pages/cli/op-reth/import-op.mdx @@ -27,6 +27,12 @@ Datadir: --datadir.static-files The absolute path to store static files in. + --datadir.min-free-disk + Minimum free disk space in MB, once reached triggers auto shut down (default = 0, + disabled). + + [default: 0] + --config The path to the configuration file to use diff --git a/docs/vocs/docs/pages/cli/op-reth/import-receipts-op.mdx b/docs/vocs/docs/pages/cli/op-reth/import-receipts-op.mdx index 15a61e503c7..89da5916315 100644 --- a/docs/vocs/docs/pages/cli/op-reth/import-receipts-op.mdx +++ b/docs/vocs/docs/pages/cli/op-reth/import-receipts-op.mdx @@ -27,6 +27,12 @@ Datadir: --datadir.static-files The absolute path to store static files in. + --datadir.min-free-disk + Minimum free disk space in MB, once reached triggers auto shut down (default = 0, + disabled). + + [default: 0] + --config The path to the configuration file to use diff --git a/docs/vocs/docs/pages/cli/op-reth/init-state.mdx b/docs/vocs/docs/pages/cli/op-reth/init-state.mdx index 6643ecf004b..3fb42a790df 100644 --- a/docs/vocs/docs/pages/cli/op-reth/init-state.mdx +++ b/docs/vocs/docs/pages/cli/op-reth/init-state.mdx @@ -27,6 +27,12 @@ Datadir: --datadir.static-files The absolute path to store static files in. + --datadir.min-free-disk + Minimum free disk space in MB, once reached triggers auto shut down (default = 0, + disabled). + + [default: 0] + --config The path to the configuration file to use diff --git a/docs/vocs/docs/pages/cli/op-reth/init.mdx b/docs/vocs/docs/pages/cli/op-reth/init.mdx index 09e28c848d2..2073d598636 100644 --- a/docs/vocs/docs/pages/cli/op-reth/init.mdx +++ b/docs/vocs/docs/pages/cli/op-reth/init.mdx @@ -27,6 +27,12 @@ Datadir: --datadir.static-files The absolute path to store static files in. + --datadir.min-free-disk + Minimum free disk space in MB, once reached triggers auto shut down (default = 0, + disabled). + + [default: 0] + --config The path to the configuration file to use diff --git a/docs/vocs/docs/pages/cli/op-reth/node.mdx b/docs/vocs/docs/pages/cli/op-reth/node.mdx index 2a6450d344c..8e0f38c072b 100644 --- a/docs/vocs/docs/pages/cli/op-reth/node.mdx +++ b/docs/vocs/docs/pages/cli/op-reth/node.mdx @@ -71,6 +71,12 @@ Datadir: --datadir.static-files The absolute path to store static files in. + --datadir.min-free-disk + Minimum free disk space in MB, once reached triggers auto shut down (default = 0, + disabled). + + [default: 0] + Networking: -d, --disable-discovery Disable the discovery service diff --git a/docs/vocs/docs/pages/cli/op-reth/p2p/body.mdx b/docs/vocs/docs/pages/cli/op-reth/p2p/body.mdx index e1a224c49f2..20a8a9b821f 100644 --- a/docs/vocs/docs/pages/cli/op-reth/p2p/body.mdx +++ b/docs/vocs/docs/pages/cli/op-reth/p2p/body.mdx @@ -243,6 +243,12 @@ Datadir: --datadir.static-files The absolute path to store static files in. + --datadir.min-free-disk + Minimum free disk space in MB, once reached triggers auto shut down (default = 0, + disabled). + + [default: 0] + --config The path to the configuration file to use. diff --git a/docs/vocs/docs/pages/cli/op-reth/p2p/header.mdx b/docs/vocs/docs/pages/cli/op-reth/p2p/header.mdx index ec6527c2b96..370aaf550ad 100644 --- a/docs/vocs/docs/pages/cli/op-reth/p2p/header.mdx +++ b/docs/vocs/docs/pages/cli/op-reth/p2p/header.mdx @@ -243,6 +243,12 @@ Datadir: --datadir.static-files The absolute path to store static files in. + --datadir.min-free-disk + Minimum free disk space in MB, once reached triggers auto shut down (default = 0, + disabled). + + [default: 0] + --config The path to the configuration file to use. diff --git a/docs/vocs/docs/pages/cli/op-reth/prune.mdx b/docs/vocs/docs/pages/cli/op-reth/prune.mdx index 2c8e27eafb2..07e747676d1 100644 --- a/docs/vocs/docs/pages/cli/op-reth/prune.mdx +++ b/docs/vocs/docs/pages/cli/op-reth/prune.mdx @@ -27,6 +27,12 @@ Datadir: --datadir.static-files The absolute path to store static files in. + --datadir.min-free-disk + Minimum free disk space in MB, once reached triggers auto shut down (default = 0, + disabled). + + [default: 0] + --config The path to the configuration file to use diff --git a/docs/vocs/docs/pages/cli/op-reth/re-execute.mdx b/docs/vocs/docs/pages/cli/op-reth/re-execute.mdx index a38edea8f58..c0546e1e7bb 100644 --- a/docs/vocs/docs/pages/cli/op-reth/re-execute.mdx +++ b/docs/vocs/docs/pages/cli/op-reth/re-execute.mdx @@ -27,6 +27,12 @@ Datadir: --datadir.static-files The absolute path to store static files in. + --datadir.min-free-disk + Minimum free disk space in MB, once reached triggers auto shut down (default = 0, + disabled). + + [default: 0] + --config The path to the configuration file to use diff --git a/docs/vocs/docs/pages/cli/op-reth/stage/drop.mdx b/docs/vocs/docs/pages/cli/op-reth/stage/drop.mdx index 1bda9307ad8..1631dcf76a0 100644 --- a/docs/vocs/docs/pages/cli/op-reth/stage/drop.mdx +++ b/docs/vocs/docs/pages/cli/op-reth/stage/drop.mdx @@ -27,6 +27,12 @@ Datadir: --datadir.static-files The absolute path to store static files in. + --datadir.min-free-disk + Minimum free disk space in MB, once reached triggers auto shut down (default = 0, + disabled). + + [default: 0] + --config The path to the configuration file to use diff --git a/docs/vocs/docs/pages/cli/op-reth/stage/dump.mdx b/docs/vocs/docs/pages/cli/op-reth/stage/dump.mdx index 6987e592241..0a9d54c6771 100644 --- a/docs/vocs/docs/pages/cli/op-reth/stage/dump.mdx +++ b/docs/vocs/docs/pages/cli/op-reth/stage/dump.mdx @@ -34,6 +34,12 @@ Datadir: --datadir.static-files The absolute path to store static files in. + --datadir.min-free-disk + Minimum free disk space in MB, once reached triggers auto shut down (default = 0, + disabled). + + [default: 0] + --config The path to the configuration file to use diff --git a/docs/vocs/docs/pages/cli/op-reth/stage/run.mdx b/docs/vocs/docs/pages/cli/op-reth/stage/run.mdx index 3ebffd4148f..eefc92356c9 100644 --- a/docs/vocs/docs/pages/cli/op-reth/stage/run.mdx +++ b/docs/vocs/docs/pages/cli/op-reth/stage/run.mdx @@ -27,6 +27,12 @@ Datadir: --datadir.static-files The absolute path to store static files in. + --datadir.min-free-disk + Minimum free disk space in MB, once reached triggers auto shut down (default = 0, + disabled). + + [default: 0] + --config The path to the configuration file to use diff --git a/docs/vocs/docs/pages/cli/op-reth/stage/unwind.mdx b/docs/vocs/docs/pages/cli/op-reth/stage/unwind.mdx index c4aac0de477..70176e8b834 100644 --- a/docs/vocs/docs/pages/cli/op-reth/stage/unwind.mdx +++ b/docs/vocs/docs/pages/cli/op-reth/stage/unwind.mdx @@ -32,6 +32,12 @@ Datadir: --datadir.static-files The absolute path to store static files in. + --datadir.min-free-disk + Minimum free disk space in MB, once reached triggers auto shut down (default = 0, + disabled). + + [default: 0] + --config The path to the configuration file to use diff --git a/docs/vocs/docs/pages/cli/reth/db.mdx b/docs/vocs/docs/pages/cli/reth/db.mdx index 90ea9d6881b..7cee694b7b4 100644 --- a/docs/vocs/docs/pages/cli/reth/db.mdx +++ b/docs/vocs/docs/pages/cli/reth/db.mdx @@ -43,6 +43,12 @@ Datadir: --datadir.static-files The absolute path to store static files in. + --datadir.min-free-disk + Minimum free disk space in MB, once reached triggers auto shut down (default = 0, + disabled). + + [default: 0] + --config The path to the configuration file to use diff --git a/docs/vocs/docs/pages/cli/reth/download.mdx b/docs/vocs/docs/pages/cli/reth/download.mdx index 785213182a6..e76096237d4 100644 --- a/docs/vocs/docs/pages/cli/reth/download.mdx +++ b/docs/vocs/docs/pages/cli/reth/download.mdx @@ -27,6 +27,12 @@ Datadir: --datadir.static-files The absolute path to store static files in. + --datadir.min-free-disk + Minimum free disk space in MB, once reached triggers auto shut down (default = 0, + disabled). + + [default: 0] + --config The path to the configuration file to use diff --git a/docs/vocs/docs/pages/cli/reth/export-era.mdx b/docs/vocs/docs/pages/cli/reth/export-era.mdx index 02ac02965d1..b4402c5216e 100644 --- a/docs/vocs/docs/pages/cli/reth/export-era.mdx +++ b/docs/vocs/docs/pages/cli/reth/export-era.mdx @@ -27,6 +27,12 @@ Datadir: --datadir.static-files The absolute path to store static files in. + --datadir.min-free-disk + Minimum free disk space in MB, once reached triggers auto shut down (default = 0, + disabled). + + [default: 0] + --config The path to the configuration file to use diff --git a/docs/vocs/docs/pages/cli/reth/import-era.mdx b/docs/vocs/docs/pages/cli/reth/import-era.mdx index ece330c6420..a96cb04e88d 100644 --- a/docs/vocs/docs/pages/cli/reth/import-era.mdx +++ b/docs/vocs/docs/pages/cli/reth/import-era.mdx @@ -27,6 +27,12 @@ Datadir: --datadir.static-files The absolute path to store static files in. + --datadir.min-free-disk + Minimum free disk space in MB, once reached triggers auto shut down (default = 0, + disabled). + + [default: 0] + --config The path to the configuration file to use diff --git a/docs/vocs/docs/pages/cli/reth/import.mdx b/docs/vocs/docs/pages/cli/reth/import.mdx index 25f96ac32aa..e045fb987af 100644 --- a/docs/vocs/docs/pages/cli/reth/import.mdx +++ b/docs/vocs/docs/pages/cli/reth/import.mdx @@ -27,6 +27,12 @@ Datadir: --datadir.static-files The absolute path to store static files in. + --datadir.min-free-disk + Minimum free disk space in MB, once reached triggers auto shut down (default = 0, + disabled). + + [default: 0] + --config The path to the configuration file to use diff --git a/docs/vocs/docs/pages/cli/reth/init-state.mdx b/docs/vocs/docs/pages/cli/reth/init-state.mdx index 9819039691a..3653121ee06 100644 --- a/docs/vocs/docs/pages/cli/reth/init-state.mdx +++ b/docs/vocs/docs/pages/cli/reth/init-state.mdx @@ -27,6 +27,12 @@ Datadir: --datadir.static-files The absolute path to store static files in. + --datadir.min-free-disk + Minimum free disk space in MB, once reached triggers auto shut down (default = 0, + disabled). + + [default: 0] + --config The path to the configuration file to use diff --git a/docs/vocs/docs/pages/cli/reth/init.mdx b/docs/vocs/docs/pages/cli/reth/init.mdx index d1465158f50..46043b91790 100644 --- a/docs/vocs/docs/pages/cli/reth/init.mdx +++ b/docs/vocs/docs/pages/cli/reth/init.mdx @@ -27,6 +27,12 @@ Datadir: --datadir.static-files The absolute path to store static files in. + --datadir.min-free-disk + Minimum free disk space in MB, once reached triggers auto shut down (default = 0, + disabled). + + [default: 0] + --config The path to the configuration file to use diff --git a/docs/vocs/docs/pages/cli/reth/node.mdx b/docs/vocs/docs/pages/cli/reth/node.mdx index 6542d0c5bf8..7cd218b0394 100644 --- a/docs/vocs/docs/pages/cli/reth/node.mdx +++ b/docs/vocs/docs/pages/cli/reth/node.mdx @@ -71,6 +71,12 @@ Datadir: --datadir.static-files The absolute path to store static files in. + --datadir.min-free-disk + Minimum free disk space in MB, once reached triggers auto shut down (default = 0, + disabled). + + [default: 0] + Networking: -d, --disable-discovery Disable the discovery service diff --git a/docs/vocs/docs/pages/cli/reth/p2p/body.mdx b/docs/vocs/docs/pages/cli/reth/p2p/body.mdx index 04c32973ae5..59152962c94 100644 --- a/docs/vocs/docs/pages/cli/reth/p2p/body.mdx +++ b/docs/vocs/docs/pages/cli/reth/p2p/body.mdx @@ -243,6 +243,12 @@ Datadir: --datadir.static-files The absolute path to store static files in. + --datadir.min-free-disk + Minimum free disk space in MB, once reached triggers auto shut down (default = 0, + disabled). + + [default: 0] + --config The path to the configuration file to use. diff --git a/docs/vocs/docs/pages/cli/reth/p2p/header.mdx b/docs/vocs/docs/pages/cli/reth/p2p/header.mdx index 10c1004fcea..d970a3bb377 100644 --- a/docs/vocs/docs/pages/cli/reth/p2p/header.mdx +++ b/docs/vocs/docs/pages/cli/reth/p2p/header.mdx @@ -243,6 +243,12 @@ Datadir: --datadir.static-files The absolute path to store static files in. + --datadir.min-free-disk + Minimum free disk space in MB, once reached triggers auto shut down (default = 0, + disabled). + + [default: 0] + --config The path to the configuration file to use. diff --git a/docs/vocs/docs/pages/cli/reth/prune.mdx b/docs/vocs/docs/pages/cli/reth/prune.mdx index 92aa365b8fc..1cb99f30fe0 100644 --- a/docs/vocs/docs/pages/cli/reth/prune.mdx +++ b/docs/vocs/docs/pages/cli/reth/prune.mdx @@ -27,6 +27,12 @@ Datadir: --datadir.static-files The absolute path to store static files in. + --datadir.min-free-disk + Minimum free disk space in MB, once reached triggers auto shut down (default = 0, + disabled). + + [default: 0] + --config The path to the configuration file to use diff --git a/docs/vocs/docs/pages/cli/reth/re-execute.mdx b/docs/vocs/docs/pages/cli/reth/re-execute.mdx index 2743f4b4915..fcdf991b912 100644 --- a/docs/vocs/docs/pages/cli/reth/re-execute.mdx +++ b/docs/vocs/docs/pages/cli/reth/re-execute.mdx @@ -27,6 +27,12 @@ Datadir: --datadir.static-files The absolute path to store static files in. + --datadir.min-free-disk + Minimum free disk space in MB, once reached triggers auto shut down (default = 0, + disabled). + + [default: 0] + --config The path to the configuration file to use diff --git a/docs/vocs/docs/pages/cli/reth/stage/drop.mdx b/docs/vocs/docs/pages/cli/reth/stage/drop.mdx index 35a051f8591..f23586cbb98 100644 --- a/docs/vocs/docs/pages/cli/reth/stage/drop.mdx +++ b/docs/vocs/docs/pages/cli/reth/stage/drop.mdx @@ -27,6 +27,12 @@ Datadir: --datadir.static-files The absolute path to store static files in. + --datadir.min-free-disk + Minimum free disk space in MB, once reached triggers auto shut down (default = 0, + disabled). + + [default: 0] + --config The path to the configuration file to use diff --git a/docs/vocs/docs/pages/cli/reth/stage/dump.mdx b/docs/vocs/docs/pages/cli/reth/stage/dump.mdx index 0ab8ab2d33a..fbb59ca2ec4 100644 --- a/docs/vocs/docs/pages/cli/reth/stage/dump.mdx +++ b/docs/vocs/docs/pages/cli/reth/stage/dump.mdx @@ -34,6 +34,12 @@ Datadir: --datadir.static-files The absolute path to store static files in. + --datadir.min-free-disk + Minimum free disk space in MB, once reached triggers auto shut down (default = 0, + disabled). + + [default: 0] + --config The path to the configuration file to use diff --git a/docs/vocs/docs/pages/cli/reth/stage/run.mdx b/docs/vocs/docs/pages/cli/reth/stage/run.mdx index a10aac3c02d..b9d5f4ff687 100644 --- a/docs/vocs/docs/pages/cli/reth/stage/run.mdx +++ b/docs/vocs/docs/pages/cli/reth/stage/run.mdx @@ -27,6 +27,12 @@ Datadir: --datadir.static-files The absolute path to store static files in. + --datadir.min-free-disk + Minimum free disk space in MB, once reached triggers auto shut down (default = 0, + disabled). + + [default: 0] + --config The path to the configuration file to use diff --git a/docs/vocs/docs/pages/cli/reth/stage/unwind.mdx b/docs/vocs/docs/pages/cli/reth/stage/unwind.mdx index 1460b4c81da..bd2ea75e598 100644 --- a/docs/vocs/docs/pages/cli/reth/stage/unwind.mdx +++ b/docs/vocs/docs/pages/cli/reth/stage/unwind.mdx @@ -32,6 +32,12 @@ Datadir: --datadir.static-files The absolute path to store static files in. + --datadir.min-free-disk + Minimum free disk space in MB, once reached triggers auto shut down (default = 0, + disabled). + + [default: 0] + --config The path to the configuration file to use From 56902e0fe60eb3fdfd5c97e3631988a2632ededa Mon Sep 17 00:00:00 2001 From: cuiweixie Date: Sat, 6 Dec 2025 23:43:07 +0800 Subject: [PATCH 3/3] fix: clippy --- crates/node/core/src/utils.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/crates/node/core/src/utils.rs b/crates/node/core/src/utils.rs index 9087704bef8..cb4857fc615 100644 --- a/crates/node/core/src/utils.rs +++ b/crates/node/core/src/utils.rs @@ -105,7 +105,7 @@ pub fn get_available_disk_space_mb(path: &Path) -> Option { let disks = Disks::new_with_refreshed_list(); // Find the disk that contains the given path - for disk in disks.iter() { + for disk in &disks { let mount_point = disk.mount_point(); if path_canonical.starts_with(mount_point) { // Get available space in bytes, convert to MB @@ -168,9 +168,8 @@ mod tests { // We can't easily mock sysinfo, so we just test that it doesn't panic // and returns a boolean value let temp_dir = std::env::temp_dir(); - let result = is_disk_space_low(&temp_dir, 1_000_000_000); // Very large threshold - // Should return either true or false, but not panic - assert!(result == true || result == false); + // Should return either true or false, but not panic + let _result = is_disk_space_low(&temp_dir, 1_000_000_000); // Very large threshold } #[test] @@ -178,9 +177,8 @@ mod tests { // Test with a non-existent path let invalid_path = Path::new("/nonexistent/path/that/does/not/exist"); // Should not panic, but may return false (feature disabled) or handle gracefully - let result = is_disk_space_low(invalid_path, 1000); - // Should not panic, result depends on sysinfo behavior - assert!(result == true || result == false); + // Result depends on sysinfo behavior + let _result = is_disk_space_low(invalid_path, 1000); } #[test] @@ -190,9 +188,9 @@ mod tests { let result = get_available_disk_space_mb(&temp_dir); // Should return Some(u64) if successful, or None if it fails match result { - Some(mb) => { + Some(_mb) => { // If successful, should be a reasonable value (not 0 for temp dir) - assert!(mb > 0 || mb == 0, "Available space should be a valid number"); + // Value is already validated as u64, so no need to check bounds } None => { // It's okay if it fails, sysinfo might not work in all test environments