Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.lock

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

21 changes: 18 additions & 3 deletions crates/cli/commands/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ use reth_node_builder::{
Node, NodeComponents, NodeComponentsBuilder, NodeTypes, NodeTypesWithDBAdapter,
};
use reth_node_core::{
args::{DatabaseArgs, DatadirArgs, StaticFilesArgs},
args::{DatabaseArgs, DatadirArgs, RocksDbArgs, StaticFilesArgs},
dirs::{ChainPath, DataDirPath},
};
use reth_provider::{
providers::{
BlockchainProvider, NodeTypesForProvider, RocksDBProvider, StaticFileProvider,
StaticFileProviderBuilder,
},
ProviderFactory, StaticFileProviderFactory,
ProviderFactory, StaticFileProviderFactory, StorageSettings,
};
use reth_stages::{sets::DefaultStages, Pipeline, PipelineTarget};
use reth_static_file::StaticFileProducer;
Expand Down Expand Up @@ -66,9 +66,24 @@ pub struct EnvironmentArgs<C: ChainSpecParser> {
/// All static files related arguments
#[command(flatten)]
pub static_files: StaticFilesArgs,

/// All `RocksDB` related arguments
#[command(flatten)]
pub rocksdb: RocksDbArgs,
}

impl<C: ChainSpecParser> EnvironmentArgs<C> {
/// Returns the effective storage settings derived from static-file and `RocksDB` CLI args.
pub fn storage_settings(&self) -> StorageSettings {
StorageSettings::base()
.with_receipts_in_static_files(self.static_files.receipts)
.with_transaction_senders_in_static_files(self.static_files.transaction_senders)
.with_account_changesets_in_static_files(self.static_files.account_changesets)
.with_transaction_hash_numbers_in_rocksdb(self.rocksdb.all || self.rocksdb.tx_hash)
.with_storages_history_in_rocksdb(self.rocksdb.all || self.rocksdb.storages_history)
.with_account_history_in_rocksdb(self.rocksdb.all || self.rocksdb.account_history)
}

/// Initializes environment according to [`AccessRights`] and returns an instance of
/// [`Environment`].
pub fn init<N: CliNodeTypes>(&self, access: AccessRights) -> eyre::Result<Environment<N>>
Expand Down Expand Up @@ -131,7 +146,7 @@ impl<C: ChainSpecParser> EnvironmentArgs<C> {
self.create_provider_factory(&config, db, sfp, rocksdb_provider, access)?;
if access.is_read_write() {
debug!(target: "reth::cli", chain=%self.chain.chain(), genesis=?self.chain.genesis_hash(), "Initializing genesis");
init_genesis_with_settings(&provider_factory, self.static_files.to_settings())?;
init_genesis_with_settings(&provider_factory, self.storage_settings())?;
}

Ok(Environment { config, provider_factory, data_dir })
Expand Down
10 changes: 2 additions & 8 deletions crates/node/builder/src/launch/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -676,19 +676,13 @@ where

/// Convenience function to [`Self::init_genesis`]
pub fn with_genesis(self) -> Result<Self, InitStorageError> {
init_genesis_with_settings(
self.provider_factory(),
self.node_config().static_files.to_settings(),
)?;
init_genesis_with_settings(self.provider_factory(), self.node_config().storage_settings())?;
Ok(self)
}

/// Write the genesis block and state if it has not already been written
pub fn init_genesis(&self) -> Result<B256, InitStorageError> {
init_genesis_with_settings(
self.provider_factory(),
self.node_config().static_files.to_settings(),
)
init_genesis_with_settings(self.provider_factory(), self.node_config().storage_settings())
}

/// Creates a new `WithMeteredProvider` container and attaches it to the
Expand Down
3 changes: 1 addition & 2 deletions crates/node/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ reth-cli-util.workspace = true
reth-db = { workspace = true, features = ["mdbx"] }
reth-storage-errors.workspace = true
reth-storage-api = { workspace = true, features = ["std", "db-api"] }
reth-provider.workspace = true
reth-network = { workspace = true, features = ["serde"] }
reth-network-p2p.workspace = true
reth-rpc-eth-types.workspace = true
Expand Down Expand Up @@ -92,7 +91,7 @@ min-debug-logs = ["tracing/release_max_level_debug"]
min-trace-logs = ["tracing/release_max_level_trace"]

# Marker feature for edge/unstable builds - captured by vergen in build.rs
edge = ["reth-provider/edge"]
edge = ["reth-storage-api/edge"]

[build-dependencies]
vergen = { workspace = true, features = ["build", "cargo", "emit_and_set"] }
Expand Down
88 changes: 63 additions & 25 deletions crates/node/core/src/args/rocksdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@

use clap::{ArgAction, Args};

/// Default value for `RocksDB` routing flags.
///
/// When the `edge` feature is enabled, defaults to `true` to enable edge storage features.
/// Otherwise defaults to `false` for legacy behavior.
const fn default_rocksdb_flag() -> bool {
cfg!(feature = "edge")
}

/// Parameters for `RocksDB` table routing configuration.
///
/// These flags control which database tables are stored in `RocksDB` instead of MDBX.
/// All flags are genesis-initialization-only: changing them after genesis requires a re-sync.
#[derive(Debug, Args, PartialEq, Eq, Default, Clone, Copy)]
#[derive(Debug, Args, PartialEq, Eq, Clone, Copy)]
#[command(next_help_heading = "RocksDB")]
pub struct RocksDbArgs {
/// Route all supported tables to `RocksDB` instead of MDBX.
Expand All @@ -17,31 +25,51 @@ pub struct RocksDbArgs {
pub all: bool,

/// Route tx hash -> number table to `RocksDB` instead of MDBX.
#[arg(long = "rocksdb.tx-hash", action = ArgAction::Set)]
pub tx_hash: Option<bool>,
///
/// This is a genesis-initialization-only flag: changing it after genesis requires a re-sync.
/// Defaults to `true` when the `edge` feature is enabled, `false` otherwise.
#[arg(long = "rocksdb.tx-hash", default_value_t = default_rocksdb_flag(), action = ArgAction::Set)]
pub tx_hash: bool,

/// Route storages history tables to `RocksDB` instead of MDBX.
#[arg(long = "rocksdb.storages-history", action = ArgAction::Set)]
pub storages_history: Option<bool>,
///
/// This is a genesis-initialization-only flag: changing it after genesis requires a re-sync.
/// Defaults to `true` when the `edge` feature is enabled, `false` otherwise.
#[arg(long = "rocksdb.storages-history", default_value_t = default_rocksdb_flag(), action = ArgAction::Set)]
pub storages_history: bool,

/// Route account history tables to `RocksDB` instead of MDBX.
#[arg(long = "rocksdb.account-history", action = ArgAction::Set)]
pub account_history: Option<bool>,
///
/// This is a genesis-initialization-only flag: changing it after genesis requires a re-sync.
/// Defaults to `true` when the `edge` feature is enabled, `false` otherwise.
#[arg(long = "rocksdb.account-history", default_value_t = default_rocksdb_flag(), action = ArgAction::Set)]
pub account_history: bool,
}

impl Default for RocksDbArgs {
fn default() -> Self {
Self {
all: false,
tx_hash: default_rocksdb_flag(),
storages_history: default_rocksdb_flag(),
account_history: default_rocksdb_flag(),
}
}
}

impl RocksDbArgs {
/// Validates the `RocksDB` arguments.
///
/// Returns an error if `--rocksdb.all` is used with any individual flag set to `false`.
pub fn validate(&self) -> Result<(), RocksDbArgsError> {
pub const fn validate(&self) -> Result<(), RocksDbArgsError> {
if self.all {
if self.tx_hash == Some(false) {
if !self.tx_hash {
return Err(RocksDbArgsError::ConflictingFlags("tx-hash"));
}
if self.storages_history == Some(false) {
if !self.storages_history {
return Err(RocksDbArgsError::ConflictingFlags("storages-history"));
}
if self.account_history == Some(false) {
if !self.account_history {
return Err(RocksDbArgsError::ConflictingFlags("account-history"));
}
}
Expand Down Expand Up @@ -78,7 +106,7 @@ mod tests {
fn test_parse_all_flag() {
let args = CommandParser::<RocksDbArgs>::parse_from(["reth", "--rocksdb.all"]).args;
assert!(args.all);
assert_eq!(args.tx_hash, None);
assert_eq!(args.tx_hash, default_rocksdb_flag());
}

#[test]
Expand All @@ -91,32 +119,42 @@ mod tests {
])
.args;
assert!(!args.all);
assert_eq!(args.tx_hash, Some(true));
assert_eq!(args.storages_history, Some(false));
assert_eq!(args.account_history, Some(true));
}

#[test]
fn test_validate_all_alone_ok() {
let args = RocksDbArgs { all: true, ..Default::default() };
assert!(args.validate().is_ok());
assert!(args.tx_hash);
assert!(!args.storages_history);
assert!(args.account_history);
}

#[test]
fn test_validate_all_with_true_ok() {
let args = RocksDbArgs { all: true, tx_hash: Some(true), ..Default::default() };
let args =
RocksDbArgs { all: true, tx_hash: true, storages_history: true, account_history: true };
assert!(args.validate().is_ok());
}

#[test]
fn test_validate_all_with_false_errors() {
let args = RocksDbArgs { all: true, tx_hash: Some(false), ..Default::default() };
let args = RocksDbArgs {
all: true,
tx_hash: false,
storages_history: true,
account_history: true,
};
assert_eq!(args.validate(), Err(RocksDbArgsError::ConflictingFlags("tx-hash")));

let args = RocksDbArgs { all: true, storages_history: Some(false), ..Default::default() };
let args = RocksDbArgs {
all: true,
tx_hash: true,
storages_history: false,
account_history: true,
};
assert_eq!(args.validate(), Err(RocksDbArgsError::ConflictingFlags("storages-history")));

let args = RocksDbArgs { all: true, account_history: Some(false), ..Default::default() };
let args = RocksDbArgs {
all: true,
tx_hash: true,
storages_history: true,
account_history: false,
};
assert_eq!(args.validate(), Err(RocksDbArgsError::ConflictingFlags("account-history")));
}
}
13 changes: 0 additions & 13 deletions crates/node/core/src/args/static_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use clap::Args;
use reth_config::config::{BlocksPerFileConfig, StaticFilesConfig};
use reth_provider::StorageSettings;

/// Blocks per static file when running in `--minimal` node.
///
Expand Down Expand Up @@ -102,18 +101,6 @@ impl StaticFilesArgs {
},
}
}

/// Converts the static files arguments into [`StorageSettings`].
pub const fn to_settings(&self) -> StorageSettings {
#[cfg(feature = "edge")]
let base = StorageSettings::edge();
#[cfg(not(feature = "edge"))]
let base = StorageSettings::legacy();

base.with_receipts_in_static_files(self.receipts)
.with_transaction_senders_in_static_files(self.transaction_senders)
.with_account_changesets_in_static_files(self.account_changesets)
}
}

impl Default for StaticFilesArgs {
Expand Down
21 changes: 8 additions & 13 deletions crates/node/core/src/node_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,19 +358,14 @@ impl<ChainSpec> NodeConfig<ChainSpec> {
}

/// Returns the effective storage settings derived from static-file and `RocksDB` CLI args.
pub fn storage_settings(&self) -> StorageSettings {
let tx_hash = self.rocksdb.all || self.rocksdb.tx_hash.unwrap_or(false);
let storages_history = self.rocksdb.all || self.rocksdb.storages_history.unwrap_or(false);
let account_history = self.rocksdb.all || self.rocksdb.account_history.unwrap_or(false);

StorageSettings {
receipts_in_static_files: self.static_files.receipts,
transaction_senders_in_static_files: self.static_files.transaction_senders,
account_changesets_in_static_files: self.static_files.account_changesets,
transaction_hash_numbers_in_rocksdb: tx_hash,
storages_history_in_rocksdb: storages_history,
account_history_in_rocksdb: account_history,
}
pub const fn storage_settings(&self) -> StorageSettings {
StorageSettings::base()
.with_receipts_in_static_files(self.static_files.receipts)
.with_transaction_senders_in_static_files(self.static_files.transaction_senders)
.with_account_changesets_in_static_files(self.static_files.account_changesets)
.with_transaction_hash_numbers_in_rocksdb(self.rocksdb.all || self.rocksdb.tx_hash)
.with_storages_history_in_rocksdb(self.rocksdb.all || self.rocksdb.storages_history)
.with_account_history_in_rocksdb(self.rocksdb.all || self.rocksdb.account_history)
}

/// Returns the max block that the node should run to, looking it up from the network if
Expand Down
15 changes: 15 additions & 0 deletions crates/storage/db-api/src/models/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@ pub struct StorageSettings {
}

impl StorageSettings {
/// Returns the default base `StorageSettings` for this build.
///
/// When the `edge` feature is enabled, returns [`Self::edge()`].
/// Otherwise, returns [`Self::legacy()`].
pub const fn base() -> Self {
#[cfg(feature = "edge")]
{
Self::edge()
}
#[cfg(not(feature = "edge"))]
{
Self::legacy()
}
}

/// Creates `StorageSettings` for edge nodes with all storage features enabled:
/// - Receipts and transaction senders in static files
/// - History indices in `RocksDB` (storages, accounts, transaction hashes)
Expand Down
30 changes: 30 additions & 0 deletions docs/vocs/docs/pages/cli/op-reth/db.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,36 @@ Static Files:
[default: false]
[possible values: true, false]

RocksDB:
--rocksdb.all
Route all supported tables to `RocksDB` instead of MDBX.

This enables `RocksDB` for `tx-hash`, `storages-history`, and `account-history` tables. Cannot be combined with individual flags set to false.

--rocksdb.tx-hash <TX_HASH>
Route tx hash -> number table to `RocksDB` instead of MDBX.

This is a genesis-initialization-only flag: changing it after genesis requires a re-sync. Defaults to `true` when the `edge` feature is enabled, `false` otherwise.

[default: false]
[possible values: true, false]

--rocksdb.storages-history <STORAGES_HISTORY>
Route storages history tables to `RocksDB` instead of MDBX.

This is a genesis-initialization-only flag: changing it after genesis requires a re-sync. Defaults to `true` when the `edge` feature is enabled, `false` otherwise.

[default: false]
[possible values: true, false]

--rocksdb.account-history <ACCOUNT_HISTORY>
Route account history tables to `RocksDB` instead of MDBX.

This is a genesis-initialization-only flag: changing it after genesis requires a re-sync. Defaults to `true` when the `edge` feature is enabled, `false` otherwise.

[default: false]
[possible values: true, false]

Logging:
--log.stdout.format <FORMAT>
The format to use for logs written to stdout
Expand Down
30 changes: 30 additions & 0 deletions docs/vocs/docs/pages/cli/op-reth/import-op.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,36 @@ Static Files:
[default: false]
[possible values: true, false]

RocksDB:
--rocksdb.all
Route all supported tables to `RocksDB` instead of MDBX.

This enables `RocksDB` for `tx-hash`, `storages-history`, and `account-history` tables. Cannot be combined with individual flags set to false.

--rocksdb.tx-hash <TX_HASH>
Route tx hash -> number table to `RocksDB` instead of MDBX.

This is a genesis-initialization-only flag: changing it after genesis requires a re-sync. Defaults to `true` when the `edge` feature is enabled, `false` otherwise.

[default: false]
[possible values: true, false]

--rocksdb.storages-history <STORAGES_HISTORY>
Route storages history tables to `RocksDB` instead of MDBX.

This is a genesis-initialization-only flag: changing it after genesis requires a re-sync. Defaults to `true` when the `edge` feature is enabled, `false` otherwise.

[default: false]
[possible values: true, false]

--rocksdb.account-history <ACCOUNT_HISTORY>
Route account history tables to `RocksDB` instead of MDBX.

This is a genesis-initialization-only flag: changing it after genesis requires a re-sync. Defaults to `true` when the `edge` feature is enabled, `false` otherwise.

[default: false]
[possible values: true, false]

--chunk-len <CHUNK_LEN>
Chunk byte length to read from file.

Expand Down
Loading
Loading