Skip to content

Commit

Permalink
Move reth-primitives::fs module to fs-utils crate (paradigmxyz#8286)
Browse files Browse the repository at this point in the history
Co-authored-by: Matthias Seitz <[email protected]>
  • Loading branch information
sergerad and mattsse authored May 17, 2024
1 parent b177c29 commit 9441d98
Show file tree
Hide file tree
Showing 39 changed files with 142 additions and 65 deletions.
17 changes: 16 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 12 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions bin/reth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
9 changes: 5 additions & 4 deletions bin/reth/src/commands/db/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion bin/reth/src/commands/debug_cmd/build_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion bin/reth/src/commands/debug_cmd/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion bin/reth/src/commands/debug_cmd/in_memory_merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion bin/reth/src/commands/debug_cmd/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion bin/reth/src/commands/debug_cmd/replay_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion bin/reth/src/commands/stage/drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion bin/reth/src/commands/test_vectors/tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
3 changes: 2 additions & 1 deletion bin/reth/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 18 additions & 0 deletions crates/fs-util/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 10 additions & 2 deletions crates/primitives/src/fs.rs → crates/fs-util/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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<T> = std::result::Result<T, FsPathError>;

/// 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)]
Expand Down Expand Up @@ -187,8 +197,6 @@ impl FsPathError {
}
}

type Result<T> = std::result::Result<T, FsPathError>;

/// Wrapper for `std::fs::read_to_string`
pub fn read_to_string(path: impl AsRef<Path>) -> Result<String> {
let path = path.as_ref();
Expand Down
1 change: 1 addition & 0 deletions crates/interfaces/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion crates/interfaces/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> = Result<T, RethError>;
Expand Down
4 changes: 2 additions & 2 deletions crates/interfaces/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ pub enum ProviderError {
ConsistentView(Box<ConsistentViewError>),
}

impl From<reth_primitives::fs::FsPathError> for ProviderError {
fn from(err: reth_primitives::fs::FsPathError) -> Self {
impl From<reth_fs_util::FsPathError> for ProviderError {
fn from(err: reth_fs_util::FsPathError) -> Self {
ProviderError::FsPathError(err.to_string())
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/node-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion crates/node-core/src/args/secret_key.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
3 changes: 2 additions & 1 deletion crates/node-core/src/args/utils.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion crates/node-core/src/engine/engine_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 2 additions & 3 deletions crates/node-core/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down
Loading

0 comments on commit 9441d98

Please sign in to comment.