mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-04-08 03:01:12 -04:00
refactor: remove static_files.to_settings() and add edge feature to RocksDB flags (#21225)
This commit is contained in:
committed by
GitHub
parent
ff8ac97e33
commit
dd72cfe23e
@@ -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
|
||||
@@ -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"] }
|
||||
|
||||
@@ -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.
|
||||
@@ -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"));
|
||||
}
|
||||
}
|
||||
@@ -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]
|
||||
@@ -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")));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
///
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user