diff --git a/Cargo.lock b/Cargo.lock index 024cbfff5..c049d8c96 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6416,6 +6416,7 @@ dependencies = [ "reth-ethereum-payload-builder", "reth-evm", "reth-exex", + "reth-fs-util", "reth-interfaces", "reth-network", "reth-network-api", @@ -6660,6 +6661,7 @@ dependencies = [ "proptest-derive", "rand 0.8.5", "reth-codecs", + "reth-fs-util", "reth-interfaces", "reth-libmdbx", "reth-metrics", @@ -7033,6 +7035,14 @@ dependencies = [ "tokio-util", ] +[[package]] +name = "reth-fs-util" +version = "0.2.0-beta.7" +dependencies = [ + "serde_json", + "thiserror", +] + [[package]] name = "reth-interfaces" version = "0.2.0-beta.7" @@ -7044,6 +7054,7 @@ dependencies = [ "rand 0.8.5", "reth-consensus", "reth-eth-wire-types", + "reth-fs-util", "reth-network-api", "reth-network-types", "reth-primitives", @@ -7253,7 +7264,7 @@ dependencies = [ "memmap2 0.7.1", "ph", "rand 0.8.5", - "reth-primitives", + "reth-fs-util", "serde", "sucds", "tempfile", @@ -7351,6 +7362,7 @@ dependencies = [ "reth-engine-primitives", "reth-etl", "reth-evm", + "reth-fs-util", "reth-interfaces", "reth-metrics", "reth-net-nat", @@ -7602,6 +7614,7 @@ dependencies = [ "reth-codecs", "reth-db", "reth-evm", + "reth-fs-util", "reth-interfaces", "reth-metrics", "reth-nippy-jar", @@ -7814,6 +7827,7 @@ dependencies = [ "jsonwebtoken 8.3.0", "pin-project", "rand 0.8.5", + "reth-fs-util", "reth-primitives", "serde", "tempfile", @@ -8006,6 +8020,7 @@ dependencies = [ "proptest", "rand 0.8.5", "reth-eth-wire", + "reth-fs-util", "reth-metrics", "reth-network-types", "reth-primitives", diff --git a/Cargo.toml b/Cargo.toml index 102fffa88..c81b76a7e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -239,6 +239,7 @@ reth-etl = { path = "crates/etl" } reth-evm = { path = "crates/evm" } reth-evm-ethereum = { path = "crates/ethereum/evm" } reth-exex = { path = "crates/exex" } +reth-fs-util = { path = "crates/fs-util" } reth-optimism-payload-builder = { path = "crates/optimism/payload" } reth-interfaces = { path = "crates/interfaces" } reth-ipc = { path = "crates/rpc/ipc" } @@ -280,8 +281,13 @@ reth-node-events = { path = "crates/node/events" } reth-testing-utils = { path = "testing/testing-utils" } # revm -revm = { version = "9.0.0", features = ["std", "secp256k1"], default-features = false } -revm-primitives = { version = "4.0.0", features = ["std"], default-features = false } +revm = { version = "9.0.0", features = [ + "std", + "secp256k1", +], default-features = false } +revm-primitives = { version = "4.0.0", features = [ + "std", +], default-features = false } revm-inspectors = { git = "https://github.com/paradigmxyz/evm-inspectors", rev = "21a2db5" } # eth @@ -381,7 +387,10 @@ secp256k1 = { version = "0.28", default-features = false, features = [ "recovery", ] } # TODO: Remove `k256` feature: https://github.com/sigp/enr/pull/74 -enr = { version = "0.12.0", default-features = false, features = ["k256", "rust-secp256k1"] } +enr = { version = "0.12.0", default-features = false, features = [ + "k256", + "rust-secp256k1", +] } # for eip-4844 c-kzg = "1.0.0" diff --git a/bin/reth/Cargo.toml b/bin/reth/Cargo.toml index c1ed8981a..b1d9b1638 100644 --- a/bin/reth/Cargo.toml +++ b/bin/reth/Cargo.toml @@ -16,6 +16,7 @@ workspace = true # reth reth-config.workspace = true reth-primitives = { workspace = true, features = ["arbitrary", "clap"] } +reth-fs-util.workspace = true reth-db = { workspace = true, features = ["mdbx"] } reth-exex.workspace = true reth-provider = { workspace = true } diff --git a/bin/reth/src/commands/db/stats.rs b/bin/reth/src/commands/db/stats.rs index b47e7980b..a59a904eb 100644 --- a/bin/reth/src/commands/db/stats.rs +++ b/bin/reth/src/commands/db/stats.rs @@ -15,6 +15,7 @@ use reth_db::{ Tables, TransactionBlocks, TransactionHashNumbers, TransactionSenders, Transactions, VersionHistory, }; +use reth_fs_util as fs; use reth_node_core::dirs::{ChainPath, DataDirPath}; use reth_primitives::static_file::{find_fixed_range, SegmentRangeInclusive}; use reth_provider::providers::StaticFileProvider; @@ -203,16 +204,16 @@ impl Command { let columns = jar_provider.columns(); let rows = jar_provider.rows(); - let data_size = reth_primitives::fs::metadata(jar_provider.data_path()) + let data_size = fs::metadata(jar_provider.data_path()) .map(|metadata| metadata.len()) .unwrap_or_default(); - let index_size = reth_primitives::fs::metadata(jar_provider.index_path()) + let index_size = fs::metadata(jar_provider.index_path()) .map(|metadata| metadata.len()) .unwrap_or_default(); - let offsets_size = reth_primitives::fs::metadata(jar_provider.offsets_path()) + let offsets_size = fs::metadata(jar_provider.offsets_path()) .map(|metadata| metadata.len()) .unwrap_or_default(); - let config_size = reth_primitives::fs::metadata(jar_provider.config_path()) + let config_size = fs::metadata(jar_provider.config_path()) .map(|metadata| metadata.len()) .unwrap_or_default(); diff --git a/bin/reth/src/commands/debug_cmd/build_block.rs b/bin/reth/src/commands/debug_cmd/build_block.rs index 72cc9e1fa..31585c2f6 100644 --- a/bin/reth/src/commands/debug_cmd/build_block.rs +++ b/bin/reth/src/commands/debug_cmd/build_block.rs @@ -22,12 +22,12 @@ use reth_cli_runner::CliContext; use reth_consensus::Consensus; use reth_db::{init_db, DatabaseEnv}; use reth_evm::execute::{BlockExecutionOutput, BlockExecutorProvider, Executor}; +use reth_fs_util as fs; use reth_interfaces::RethResult; use reth_node_api::PayloadBuilderAttributes; use reth_payload_builder::database::CachedReads; use reth_primitives::{ constants::eip4844::{LoadKzgSettingsError, MAINNET_KZG_TRUSTED_SETUP}, - fs, revm_primitives::KzgSettings, stage::StageId, Address, BlobTransaction, BlobTransactionSidecar, Bytes, ChainSpec, PooledTransactionsElement, diff --git a/bin/reth/src/commands/debug_cmd/execution.rs b/bin/reth/src/commands/debug_cmd/execution.rs index 8fecc928a..3e6474236 100644 --- a/bin/reth/src/commands/debug_cmd/execution.rs +++ b/bin/reth/src/commands/debug_cmd/execution.rs @@ -22,12 +22,13 @@ use reth_downloaders::{ headers::reverse_headers::ReverseHeadersDownloaderBuilder, }; use reth_exex::ExExManagerHandle; +use reth_fs_util as fs; use reth_interfaces::p2p::{bodies::client::BodiesClient, headers::client::HeadersClient}; use reth_network::{NetworkEvents, NetworkHandle}; use reth_network_api::NetworkInfo; use reth_node_core::init::init_genesis; use reth_primitives::{ - fs, stage::StageId, BlockHashOrNumber, BlockNumber, ChainSpec, PruneModes, B256, + stage::StageId, BlockHashOrNumber, BlockNumber, ChainSpec, PruneModes, B256, }; use reth_provider::{ BlockExecutionWriter, HeaderSyncMode, ProviderFactory, StageCheckpointReader, diff --git a/bin/reth/src/commands/debug_cmd/in_memory_merkle.rs b/bin/reth/src/commands/debug_cmd/in_memory_merkle.rs index f51426015..6f7a580a4 100644 --- a/bin/reth/src/commands/debug_cmd/in_memory_merkle.rs +++ b/bin/reth/src/commands/debug_cmd/in_memory_merkle.rs @@ -16,10 +16,11 @@ use reth_cli_runner::CliContext; use reth_config::Config; use reth_db::{init_db, DatabaseEnv}; use reth_evm::execute::{BlockExecutionOutput, BlockExecutorProvider, Executor}; +use reth_fs_util as fs; use reth_interfaces::executor::BlockValidationError; use reth_network::NetworkHandle; use reth_network_api::NetworkInfo; -use reth_primitives::{fs, stage::StageId, BlockHashOrNumber, ChainSpec, Receipts}; +use reth_primitives::{stage::StageId, BlockHashOrNumber, ChainSpec, Receipts}; use reth_provider::{ AccountExtReader, BundleStateWithReceipts, HashingWriter, HeaderProvider, LatestStateProviderRef, OriginalValuesKnown, ProviderFactory, StageCheckpointReader, diff --git a/bin/reth/src/commands/debug_cmd/merkle.rs b/bin/reth/src/commands/debug_cmd/merkle.rs index f452e2e52..40d79a85d 100644 --- a/bin/reth/src/commands/debug_cmd/merkle.rs +++ b/bin/reth/src/commands/debug_cmd/merkle.rs @@ -18,10 +18,11 @@ use reth_config::Config; use reth_consensus::Consensus; use reth_db::{cursor::DbCursorRO, init_db, tables, transaction::DbTx, DatabaseEnv}; use reth_evm::execute::{BatchBlockExecutionOutput, BatchExecutor, BlockExecutorProvider}; +use reth_fs_util as fs; use reth_interfaces::p2p::full_block::FullBlockClient; use reth_network::NetworkHandle; use reth_network_api::NetworkInfo; -use reth_primitives::{fs, stage::StageCheckpoint, BlockHashOrNumber, ChainSpec, PruneModes}; +use reth_primitives::{stage::StageCheckpoint, BlockHashOrNumber, ChainSpec, PruneModes}; use reth_provider::{ BlockNumReader, BlockWriter, BundleStateWithReceipts, HeaderProvider, LatestStateProviderRef, OriginalValuesKnown, ProviderError, ProviderFactory, StateWriter, diff --git a/bin/reth/src/commands/debug_cmd/replay_engine.rs b/bin/reth/src/commands/debug_cmd/replay_engine.rs index b86e707a8..72031ce1b 100644 --- a/bin/reth/src/commands/debug_cmd/replay_engine.rs +++ b/bin/reth/src/commands/debug_cmd/replay_engine.rs @@ -18,11 +18,12 @@ use reth_cli_runner::CliContext; use reth_config::Config; use reth_consensus::Consensus; use reth_db::{init_db, DatabaseEnv}; +use reth_fs_util as fs; use reth_network::NetworkHandle; use reth_network_api::NetworkInfo; use reth_node_core::engine::engine_store::{EngineMessageStore, StoredEngineApiMessage}; use reth_payload_builder::{PayloadBuilderHandle, PayloadBuilderService}; -use reth_primitives::{fs, ChainSpec, PruneModes}; +use reth_primitives::{ChainSpec, PruneModes}; use reth_provider::{ providers::BlockchainProvider, CanonStateSubscriptions, ProviderFactory, StaticFileProviderFactory, diff --git a/bin/reth/src/commands/stage/drop.rs b/bin/reth/src/commands/stage/drop.rs index 625a3f36b..73ac898c9 100644 --- a/bin/reth/src/commands/stage/drop.rs +++ b/bin/reth/src/commands/stage/drop.rs @@ -11,9 +11,10 @@ use crate::{ use clap::Parser; use itertools::Itertools; use reth_db::{open_db, static_file::iter_static_files, tables, transaction::DbTxMut, DatabaseEnv}; +use reth_fs_util as fs; use reth_node_core::init::{insert_genesis_header, insert_genesis_history, insert_genesis_state}; use reth_primitives::{ - fs, stage::StageId, static_file::find_fixed_range, ChainSpec, StaticFileSegment, + stage::StageId, static_file::find_fixed_range, ChainSpec, StaticFileSegment, }; use reth_provider::{providers::StaticFileWriter, ProviderFactory, StaticFileProviderFactory}; use std::sync::Arc; diff --git a/bin/reth/src/commands/test_vectors/tables.rs b/bin/reth/src/commands/test_vectors/tables.rs index 181ed0e3e..c44739ffb 100644 --- a/bin/reth/src/commands/test_vectors/tables.rs +++ b/bin/reth/src/commands/test_vectors/tables.rs @@ -11,7 +11,7 @@ use reth_db::{ table::{DupSort, Table, TableRow}, tables, }; -use reth_primitives::fs; +use reth_fs_util as fs; use tracing::error; const VECTORS_FOLDER: &str = "testdata/micro/db"; diff --git a/bin/reth/src/utils.rs b/bin/reth/src/utils.rs index 650fc9d70..025b059bc 100644 --- a/bin/reth/src/utils.rs +++ b/bin/reth/src/utils.rs @@ -9,7 +9,8 @@ use reth_db::{ transaction::{DbTx, DbTxMut}, DatabaseError, RawTable, TableRawRow, }; -use reth_primitives::{fs, ChainSpec}; +use reth_fs_util as fs; +use reth_primitives::ChainSpec; use reth_provider::ProviderFactory; use std::{path::Path, rc::Rc, sync::Arc}; use tracing::info; diff --git a/crates/fs-util/Cargo.toml b/crates/fs-util/Cargo.toml new file mode 100644 index 000000000..aa8c322d2 --- /dev/null +++ b/crates/fs-util/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "reth-fs-util" +version.workspace = true +edition.workspace = true +homepage.workspace = true +license.workspace = true +repository.workspace = true +rust-version.workspace = true +description = "Commonly used fs utils in reth." + +[lints] +workspace = true + +[dependencies] + +# misc +serde_json.workspace = true +thiserror.workspace = true diff --git a/crates/primitives/src/fs.rs b/crates/fs-util/src/lib.rs similarity index 95% rename from crates/primitives/src/fs.rs rename to crates/fs-util/src/lib.rs index 1bcb908db..c6c56dd44 100644 --- a/crates/primitives/src/fs.rs +++ b/crates/fs-util/src/lib.rs @@ -1,11 +1,21 @@ //! Wrapper for `std::fs` methods +#![doc( + html_logo_url = "https://raw.githubusercontent.com/paradigmxyz/reth/main/assets/reth-docs.png", + html_favicon_url = "https://avatars0.githubusercontent.com/u/97369466?s=256", + issue_tracker_base_url = "https://github.com/paradigmxyz/reth/issues/" +)] +#![cfg_attr(not(test), warn(unused_crate_dependencies))] + use std::{ fs::{self, ReadDir}, io, path::{Path, PathBuf}, }; +/// Result alias for [FsPathError]. +pub type Result = std::result::Result; + /// Various error variants for `std::fs` operations that serve as an addition to the io::Error which /// does not provide any information about the path. #[derive(Debug, thiserror::Error)] @@ -187,8 +197,6 @@ impl FsPathError { } } -type Result = std::result::Result; - /// Wrapper for `std::fs::read_to_string` pub fn read_to_string(path: impl AsRef) -> Result { let path = path.as_ref(); diff --git a/crates/interfaces/Cargo.toml b/crates/interfaces/Cargo.toml index c2e276a33..27e2d8f39 100644 --- a/crates/interfaces/Cargo.toml +++ b/crates/interfaces/Cargo.toml @@ -12,6 +12,7 @@ workspace = true [dependencies] reth-primitives.workspace = true +reth-fs-util.workspace = true reth-network-api.workspace = true reth-eth-wire-types.workspace = true reth-consensus.workspace = true diff --git a/crates/interfaces/src/error.rs b/crates/interfaces/src/error.rs index 38498c312..ec3da8ad0 100644 --- a/crates/interfaces/src/error.rs +++ b/crates/interfaces/src/error.rs @@ -5,8 +5,8 @@ use crate::{ provider::ProviderError, }; use reth_consensus::ConsensusError; +use reth_fs_util::FsPathError; use reth_network_api::NetworkError; -use reth_primitives::fs::FsPathError; /// Result alias for [`RethError`]. pub type RethResult = Result; diff --git a/crates/interfaces/src/provider.rs b/crates/interfaces/src/provider.rs index 7221c0cdf..6ae7aad8e 100644 --- a/crates/interfaces/src/provider.rs +++ b/crates/interfaces/src/provider.rs @@ -130,8 +130,8 @@ pub enum ProviderError { ConsistentView(Box), } -impl From for ProviderError { - fn from(err: reth_primitives::fs::FsPathError) -> Self { +impl From for ProviderError { + fn from(err: reth_fs_util::FsPathError) -> Self { ProviderError::FsPathError(err.to_string()) } } diff --git a/crates/node-core/Cargo.toml b/crates/node-core/Cargo.toml index 7637b3b2d..b0ed1fae1 100644 --- a/crates/node-core/Cargo.toml +++ b/crates/node-core/Cargo.toml @@ -13,6 +13,7 @@ workspace = true [dependencies] # reth reth-primitives.workspace = true +reth-fs-util.workspace = true reth-db = { workspace = true, features = ["mdbx"] } reth-interfaces = { workspace = true, features = ["clap"] } reth-provider.workspace = true diff --git a/crates/node-core/src/args/secret_key.rs b/crates/node-core/src/args/secret_key.rs index b93d909b4..a8b401bbb 100644 --- a/crates/node-core/src/args/secret_key.rs +++ b/crates/node-core/src/args/secret_key.rs @@ -1,5 +1,6 @@ +use reth_fs_util::{self as fs, FsPathError}; use reth_network::config::rng_secret_key; -use reth_primitives::{fs, fs::FsPathError, hex::encode as hex_encode}; +use reth_primitives::hex::encode as hex_encode; use secp256k1::{Error as SecretKeyBaseError, SecretKey}; use std::{ io, diff --git a/crates/node-core/src/args/utils.rs b/crates/node-core/src/args/utils.rs index cf0bee96c..5e3b0271c 100644 --- a/crates/node-core/src/args/utils.rs +++ b/crates/node-core/src/args/utils.rs @@ -1,6 +1,7 @@ //! Clap parser utilities -use reth_primitives::{fs, AllGenesisFormats, BlockHashOrNumber, ChainSpec, B256}; +use reth_fs_util as fs; +use reth_primitives::{AllGenesisFormats, BlockHashOrNumber, ChainSpec, B256}; use std::{ net::{IpAddr, Ipv4Addr, SocketAddr, ToSocketAddrs}, path::PathBuf, diff --git a/crates/node-core/src/engine/engine_store.rs b/crates/node-core/src/engine/engine_store.rs index 524e2c89b..2a1ffc3b0 100644 --- a/crates/node-core/src/engine/engine_store.rs +++ b/crates/node-core/src/engine/engine_store.rs @@ -3,7 +3,7 @@ use futures::{Stream, StreamExt}; use reth_beacon_consensus::BeaconEngineMessage; use reth_engine_primitives::EngineTypes; -use reth_primitives::fs; +use reth_fs_util as fs; use reth_rpc_types::{ engine::{CancunPayloadFields, ForkchoiceState}, ExecutionPayload, diff --git a/crates/node-core/src/utils.rs b/crates/node-core/src/utils.rs index 32dc509fa..84a3bef7b 100644 --- a/crates/node-core/src/utils.rs +++ b/crates/node-core/src/utils.rs @@ -3,15 +3,14 @@ use eyre::Result; use reth_consensus_common::validation::validate_block_standalone; +use reth_fs_util as fs; use reth_interfaces::p2p::{ bodies::client::BodiesClient, headers::client::{HeadersClient, HeadersRequest}, priority::Priority, }; use reth_network::NetworkManager; -use reth_primitives::{ - fs, BlockHashOrNumber, ChainSpec, HeadersDirection, SealedBlock, SealedHeader, -}; +use reth_primitives::{BlockHashOrNumber, ChainSpec, HeadersDirection, SealedBlock, SealedHeader}; use reth_provider::BlockReader; use reth_rpc_layer::{JwtError, JwtSecret}; use std::{ diff --git a/crates/primitives/Cargo.toml b/crates/primitives/Cargo.toml index d9d6c592e..34100b24b 100644 --- a/crates/primitives/Cargo.toml +++ b/crates/primitives/Cargo.toml @@ -30,7 +30,11 @@ alloy-eips = { workspace = true, features = ["serde"] } nybbles = { workspace = true, features = ["serde", "rlp"] } # crypto -secp256k1 = { workspace = true, features = ["global-context", "recovery", "rand"] } +secp256k1 = { workspace = true, features = [ + "global-context", + "recovery", + "rand", +] } # for eip-4844 c-kzg = { workspace = true, features = ["serde"], optional = true } @@ -83,7 +87,11 @@ plain_hasher = "0.2" sucds = "0.8.1" criterion.workspace = true -pprof = { workspace = true, features = ["flamegraph", "frame-pointer", "criterion"] } +pprof = { workspace = true, features = [ + "flamegraph", + "frame-pointer", + "criterion", +] } [features] default = ["c-kzg", "zstd-codec"] @@ -100,7 +108,13 @@ arbitrary = [ "dep:proptest-derive", "zstd-codec", ] -c-kzg = ["dep:c-kzg", "revm/c-kzg", "revm-primitives/c-kzg", "dep:tempfile", "alloy-eips/kzg"] +c-kzg = [ + "dep:c-kzg", + "revm/c-kzg", + "revm-primitives/c-kzg", + "dep:tempfile", + "alloy-eips/kzg", +] zstd-codec = ["dep:zstd"] clap = ["dep:clap"] optimism = [ diff --git a/crates/primitives/src/lib.rs b/crates/primitives/src/lib.rs index d7317951e..1dd2562e9 100644 --- a/crates/primitives/src/lib.rs +++ b/crates/primitives/src/lib.rs @@ -30,7 +30,6 @@ pub mod constants; pub mod eip4844; mod error; mod exex; -pub mod fs; pub mod genesis; mod header; mod integer_list; diff --git a/crates/rpc/rpc-layer/Cargo.toml b/crates/rpc/rpc-layer/Cargo.toml index dc4614b17..546770f94 100644 --- a/crates/rpc/rpc-layer/Cargo.toml +++ b/crates/rpc/rpc-layer/Cargo.toml @@ -12,6 +12,7 @@ workspace = true [dependencies] reth-primitives.workspace = true +reth-fs-util.workspace = true http.workspace = true hyper.workspace = true diff --git a/crates/rpc/rpc-layer/src/jwt_secret.rs b/crates/rpc/rpc-layer/src/jwt_secret.rs index b31cd27c6..b3d536078 100644 --- a/crates/rpc/rpc-layer/src/jwt_secret.rs +++ b/crates/rpc/rpc-layer/src/jwt_secret.rs @@ -1,10 +1,7 @@ use jsonwebtoken::{decode, errors::ErrorKind, Algorithm, DecodingKey, Validation}; use rand::Rng; -use reth_primitives::{ - fs, - fs::FsPathError, - hex::{self, encode as hex_encode}, -}; +use reth_fs_util::{self as fs, FsPathError}; +use reth_primitives::hex::{self, encode as hex_encode}; use serde::{Deserialize, Serialize}; use std::{ path::Path, diff --git a/crates/stages/benches/setup/account_hashing.rs b/crates/stages/benches/setup/account_hashing.rs index d30026535..a1df1757b 100644 --- a/crates/stages/benches/setup/account_hashing.rs +++ b/crates/stages/benches/setup/account_hashing.rs @@ -4,12 +4,12 @@ use super::constants; use reth_db::{ cursor::DbCursorRO, database::Database, tables, transaction::DbTx, DatabaseError as DbError, }; -use reth_primitives::{fs, stage::StageCheckpoint, BlockNumber}; +use reth_primitives::{stage::StageCheckpoint, BlockNumber}; use reth_stages::{ stages::{AccountHashingStage, SeedOpts}, test_utils::TestStageDB, }; -use std::{ops::RangeInclusive, path::Path}; +use std::{fs, ops::RangeInclusive, path::Path}; /// Prepares a database for [`AccountHashingStage`] /// If the environment variable [`constants::ACCOUNT_HASHING_DB`] is set, it will use that one and diff --git a/crates/stages/benches/setup/mod.rs b/crates/stages/benches/setup/mod.rs index 2151f26c8..06e15192b 100644 --- a/crates/stages/benches/setup/mod.rs +++ b/crates/stages/benches/setup/mod.rs @@ -14,13 +14,13 @@ use reth_interfaces::test_utils::{ random_eoa_accounts, }, }; -use reth_primitives::{fs, Account, Address, SealedBlock, B256, U256}; +use reth_primitives::{Account, Address, SealedBlock, B256, U256}; use reth_stages::{ stages::{AccountHashingStage, StorageHashingStage}, test_utils::{StorageKind, TestStageDB}, }; use reth_trie::StateRoot; -use std::{collections::BTreeMap, path::Path, sync::Arc}; +use std::{collections::BTreeMap, fs, path::Path, sync::Arc}; use tokio::runtime::Handle; mod constants; diff --git a/crates/storage/db/Cargo.toml b/crates/storage/db/Cargo.toml index 97b556346..a764f270d 100644 --- a/crates/storage/db/Cargo.toml +++ b/crates/storage/db/Cargo.toml @@ -14,6 +14,7 @@ workspace = true [dependencies] # reth reth-primitives.workspace = true +reth-fs-util.workspace = true reth-interfaces.workspace = true reth-codecs.workspace = true reth-libmdbx = { workspace = true, optional = true, features = [ diff --git a/crates/storage/db/benches/utils.rs b/crates/storage/db/benches/utils.rs index 0e9045584..a5f7d4bbd 100644 --- a/crates/storage/db/benches/utils.rs +++ b/crates/storage/db/benches/utils.rs @@ -5,7 +5,8 @@ use reth_db::{ transaction::DbTxMut, DatabaseEnv, }; -use reth_primitives::{fs, Bytes}; +use reth_fs_util as fs; +use reth_primitives::Bytes; use std::{path::Path, sync::Arc}; /// Path where the DB is initialized for benchmarks. diff --git a/crates/storage/db/src/lib.rs b/crates/storage/db/src/lib.rs index 5425c8074..6b6a22319 100644 --- a/crates/storage/db/src/lib.rs +++ b/crates/storage/db/src/lib.rs @@ -99,7 +99,7 @@ pub fn create_db>(path: P, args: DatabaseArguments) -> eyre::Resu let rpath = path.as_ref(); if is_database_empty(rpath) { - reth_primitives::fs::create_dir_all(rpath) + reth_fs_util::create_dir_all(rpath) .wrap_err_with(|| format!("Could not create database directory {}", rpath.display()))?; create_db_version_file(rpath)?; } else { @@ -175,8 +175,8 @@ pub mod test_utils { database_metrics::{DatabaseMetadata, DatabaseMetadataValue, DatabaseMetrics}, models::client_version::ClientVersion, }; + use reth_fs_util; use reth_libmdbx::MaxReadTransactionDuration; - use reth_primitives::fs; use std::{path::PathBuf, sync::Arc}; use tempfile::TempDir; @@ -202,7 +202,7 @@ pub mod test_utils { fn drop(&mut self) { if let Some(db) = self.db.take() { drop(db); - let _ = fs::remove_dir_all(&self.path); + let _ = reth_fs_util::remove_dir_all(&self.path); } } } @@ -318,7 +318,6 @@ mod tests { }; use assert_matches::assert_matches; use reth_libmdbx::MaxReadTransactionDuration; - use reth_primitives::fs; use tempfile::tempdir; #[test] @@ -342,7 +341,8 @@ mod tests { // Database is not empty, version file is malformed { - fs::write(path.path().join(db_version_file_path(&path)), "invalid-version").unwrap(); + reth_fs_util::write(path.path().join(db_version_file_path(&path)), "invalid-version") + .unwrap(); let db = init_db(&path, args.clone()); assert!(db.is_err()); assert_matches!( @@ -353,7 +353,7 @@ mod tests { // Database is not empty, version file contains not matching version { - fs::write(path.path().join(db_version_file_path(&path)), "0").unwrap(); + reth_fs_util::write(path.path().join(db_version_file_path(&path)), "0").unwrap(); let db = init_db(&path, args); assert!(db.is_err()); assert_matches!( diff --git a/crates/storage/db/src/static_file/mod.rs b/crates/storage/db/src/static_file/mod.rs index eed27e0de..17736b565 100644 --- a/crates/storage/db/src/static_file/mod.rs +++ b/crates/storage/db/src/static_file/mod.rs @@ -31,12 +31,11 @@ type SortedStaticFiles = pub fn iter_static_files(path: impl AsRef) -> Result { let path = path.as_ref(); if !path.exists() { - reth_primitives::fs::create_dir_all(path) - .map_err(|err| NippyJarError::Custom(err.to_string()))?; + reth_fs_util::create_dir_all(path).map_err(|err| NippyJarError::Custom(err.to_string()))?; } let mut static_files = SortedStaticFiles::default(); - let entries = reth_primitives::fs::read_dir(path) + let entries = reth_fs_util::read_dir(path) .map_err(|err| NippyJarError::Custom(err.to_string()))? .filter_map(Result::ok) .collect::>(); diff --git a/crates/storage/nippy-jar/Cargo.toml b/crates/storage/nippy-jar/Cargo.toml index d979759b4..fb485e32a 100644 --- a/crates/storage/nippy-jar/Cargo.toml +++ b/crates/storage/nippy-jar/Cargo.toml @@ -16,7 +16,7 @@ name = "reth_nippy_jar" [dependencies] # reth -reth-primitives.workspace = true +reth-fs-util.workspace = true # filter ph = "0.8.0" diff --git a/crates/storage/nippy-jar/src/error.rs b/crates/storage/nippy-jar/src/error.rs index d44777058..2f7bcf804 100644 --- a/crates/storage/nippy-jar/src/error.rs +++ b/crates/storage/nippy-jar/src/error.rs @@ -8,7 +8,7 @@ pub enum NippyJarError { #[error(transparent)] Disconnect(#[from] std::io::Error), #[error(transparent)] - FileSystem(#[from] reth_primitives::fs::FsPathError), + FileSystem(#[from] reth_fs_util::FsPathError), #[error("{0}")] Custom(String), #[error(transparent)] diff --git a/crates/storage/nippy-jar/src/lib.rs b/crates/storage/nippy-jar/src/lib.rs index 1abbfba75..435e91e87 100644 --- a/crates/storage/nippy-jar/src/lib.rs +++ b/crates/storage/nippy-jar/src/lib.rs @@ -245,7 +245,7 @@ impl NippyJar { // Read [`Self`] located at the data file. let config_path = path.with_extension(CONFIG_FILE_EXTENSION); let config_file = File::open(&config_path) - .map_err(|err| reth_primitives::fs::FsPathError::open(err, config_path))?; + .map_err(|err| reth_fs_util::FsPathError::open(err, config_path))?; let mut obj: Self = bincode::deserialize_from(&config_file)?; obj.path = path.to_path_buf(); @@ -290,7 +290,7 @@ impl NippyJar { [self.data_path().into(), self.index_path(), self.offsets_path(), self.config_path()] { if path.exists() { - reth_primitives::fs::remove_file(path)?; + reth_fs_util::remove_file(path)?; } } diff --git a/crates/storage/provider/Cargo.toml b/crates/storage/provider/Cargo.toml index 1272a824c..4fe4ffbb9 100644 --- a/crates/storage/provider/Cargo.toml +++ b/crates/storage/provider/Cargo.toml @@ -14,6 +14,7 @@ workspace = true [dependencies] # reth reth-primitives.workspace = true +reth-fs-util.workspace = true reth-interfaces.workspace = true reth-db.workspace = true reth-trie = { workspace = true, features = ["metrics"] } diff --git a/crates/storage/provider/src/providers/static_file/manager.rs b/crates/storage/provider/src/providers/static_file/manager.rs index 7814a7097..610021d70 100644 --- a/crates/storage/provider/src/providers/static_file/manager.rs +++ b/crates/storage/provider/src/providers/static_file/manager.rs @@ -132,16 +132,16 @@ impl StaticFileProvider { entries += jar_provider.rows(); - let data_size = reth_primitives::fs::metadata(jar_provider.data_path()) + let data_size = reth_fs_util::metadata(jar_provider.data_path()) .map(|metadata| metadata.len()) .unwrap_or_default(); - let index_size = reth_primitives::fs::metadata(jar_provider.index_path()) + let index_size = reth_fs_util::metadata(jar_provider.index_path()) .map(|metadata| metadata.len()) .unwrap_or_default(); - let offsets_size = reth_primitives::fs::metadata(jar_provider.offsets_path()) + let offsets_size = reth_fs_util::metadata(jar_provider.offsets_path()) .map(|metadata| metadata.len()) .unwrap_or_default(); - let config_size = reth_primitives::fs::metadata(jar_provider.config_path()) + let config_size = reth_fs_util::metadata(jar_provider.config_path()) .map(|metadata| metadata.len()) .unwrap_or_default(); diff --git a/crates/transaction-pool/Cargo.toml b/crates/transaction-pool/Cargo.toml index ebb6e497f..82020e172 100644 --- a/crates/transaction-pool/Cargo.toml +++ b/crates/transaction-pool/Cargo.toml @@ -15,6 +15,7 @@ workspace = true # reth reth-eth-wire.workspace = true reth-primitives.workspace = true +reth-fs-util.workspace = true reth-provider.workspace = true reth-tasks.workspace = true revm.workspace = true diff --git a/crates/transaction-pool/src/maintain.rs b/crates/transaction-pool/src/maintain.rs index 52f39cd36..923683d8a 100644 --- a/crates/transaction-pool/src/maintain.rs +++ b/crates/transaction-pool/src/maintain.rs @@ -11,10 +11,11 @@ use futures_util::{ future::{BoxFuture, Fuse, FusedFuture}, FutureExt, Stream, StreamExt, }; +use reth_fs_util::FsPathError; use reth_primitives::{ - fs::FsPathError, Address, BlockHash, BlockNumber, BlockNumberOrTag, - FromRecoveredPooledTransaction, IntoRecoveredTransaction, PooledTransactionsElementEcRecovered, - TransactionSigned, TryFromRecoveredTransaction, + Address, BlockHash, BlockNumber, BlockNumberOrTag, FromRecoveredPooledTransaction, + IntoRecoveredTransaction, PooledTransactionsElementEcRecovered, TransactionSigned, + TryFromRecoveredTransaction, }; use reth_provider::{ BlockReaderIdExt, BundleStateWithReceipts, CanonStateNotification, ChainSpecProvider, @@ -578,7 +579,7 @@ where } debug!(target: "txpool", txs_file =?file_path, "Check local persistent storage for saved transactions"); - let data = reth_primitives::fs::read(file_path)?; + let data = reth_fs_util::read(file_path)?; if data.is_empty() { return Ok(()) @@ -598,7 +599,7 @@ where let outcome = pool.add_transactions(crate::TransactionOrigin::Local, pool_transactions).await; info!(target: "txpool", txs_file =?file_path, num_txs=%outcome.len(), "Successfully reinserted local transactions from file"); - reth_primitives::fs::remove_file(file_path)?; + reth_fs_util::remove_file(file_path)?; Ok(()) } @@ -623,7 +624,7 @@ where info!(target: "txpool", txs_file =?file_path, num_txs=%num_txs, "Saving current local transactions"); let parent_dir = file_path.parent().map(std::fs::create_dir_all).transpose(); - match parent_dir.map(|_| reth_primitives::fs::write(file_path, buf)) { + match parent_dir.map(|_| reth_fs_util::write(file_path, buf)) { Ok(_) => { info!(target: "txpool", txs_file=?file_path, "Wrote local transactions to file"); } @@ -680,7 +681,8 @@ mod tests { blobstore::InMemoryBlobStore, validate::EthTransactionValidatorBuilder, CoinbaseTipOrdering, EthPooledTransaction, Pool, PoolTransaction, TransactionOrigin, }; - use reth_primitives::{fs, hex, PooledTransactionsElement, MAINNET, U256}; + use reth_fs_util as fs; + use reth_primitives::{hex, PooledTransactionsElement, MAINNET, U256}; use reth_provider::test_utils::{ExtendedAccount, MockEthProvider}; use reth_tasks::TaskManager;