chore(cli): remove --db options from cli commands (#2575)

This commit is contained in:
Léo Vincent
2023-05-05 22:09:44 +02:00
committed by GitHub
parent 63d2d700aa
commit 78d6fd27fa
9 changed files with 19 additions and 62 deletions

View File

@@ -5,7 +5,7 @@ use reth_staged_sync::utils::{
chainspec::genesis_value_parser,
init::{init_db, init_genesis},
};
use std::{path::PathBuf, sync::Arc};
use std::sync::Arc;
use tracing::info;
/// Initializes the database with the genesis block.
@@ -21,11 +21,6 @@ pub struct InitCommand {
#[arg(long, value_name = "DATA_DIR", verbatim_doc_comment, default_value_t)]
datadir: MaybePlatformPath<DataDirPath>,
/// The path to the database folder. If not specified, it will be set in the data dir for the
/// chain being used.
#[arg(long, value_name = "PATH", verbatim_doc_comment)]
db: Option<PathBuf>,
/// The chain this node is running.
///
/// Possible values are either a built-in chain or the path to a chain specification file.
@@ -51,10 +46,7 @@ impl InitCommand {
// add network name to data dir
let data_dir = self.datadir.unwrap_or_chain_default(self.chain.chain);
// use the overridden db path if specified
let db_path = self.db.clone().unwrap_or(data_dir.db_path());
let db_path = data_dir.db_path();
info!(target: "reth::cli", path = ?db_path, "Opening database");
let db = Arc::new(init_db(&db_path)?);
info!(target: "reth::cli", "Database opened");

View File

@@ -205,7 +205,11 @@ mod tests {
fn test_parse_help_all_subcommands() {
let reth = Cli::command();
for sub_command in reth.get_subcommands() {
let err = Cli::try_parse_from(["reth", sub_command.get_name(), "--help"]).err().unwrap_or_else(|| panic!("Failed to parse help message {}", sub_command.get_name()));
let err = Cli::try_parse_from(["reth", sub_command.get_name(), "--help"])
.err()
.unwrap_or_else(|| {
panic!("Failed to parse help message {}", sub_command.get_name())
});
// --help is treated as error, but
// > Not a true "error" as it means --help or similar was used. The help message will be sent to stdout.

View File

@@ -10,7 +10,7 @@ use human_bytes::human_bytes;
use reth_db::{database::Database, tables};
use reth_primitives::ChainSpec;
use reth_staged_sync::utils::chainspec::genesis_value_parser;
use std::{path::PathBuf, sync::Arc};
use std::sync::Arc;
use tracing::error;
/// DB List TUI
@@ -29,11 +29,6 @@ pub struct Command {
#[arg(long, value_name = "DATA_DIR", verbatim_doc_comment, default_value_t)]
datadir: MaybePlatformPath<DataDirPath>,
/// The path to the database folder. If not specified, it will be set in the data dir for the
/// chain being used.
#[arg(long, value_name = "PATH", verbatim_doc_comment)]
db: Option<PathBuf>,
/// The chain this node is running.
///
/// Possible values are either a built-in chain or the path to a chain specification file.
@@ -95,10 +90,7 @@ impl Command {
pub async fn execute(self) -> eyre::Result<()> {
// add network name to data dir
let data_dir = self.datadir.unwrap_or_chain_default(self.chain.chain);
// use the overridden db path if specified
let db_path = self.db.clone().unwrap_or(data_dir.db_path());
let db_path = data_dir.db_path();
std::fs::create_dir_all(&db_path)?;
// TODO: Auto-impl for Database trait

View File

@@ -17,7 +17,7 @@ use reth_stages::stages::{
ACCOUNT_HASHING, EXECUTION, INDEX_ACCOUNT_HISTORY, INDEX_STORAGE_HISTORY, MERKLE_EXECUTION,
MERKLE_UNWIND, STORAGE_HASHING,
};
use std::{path::PathBuf, sync::Arc};
use std::sync::Arc;
use tracing::info;
/// `reth drop-stage` command
@@ -33,11 +33,6 @@ pub struct Command {
#[arg(long, value_name = "DATA_DIR", verbatim_doc_comment, default_value_t)]
datadir: MaybePlatformPath<DataDirPath>,
/// The path to the database folder. If not specified, it will be set in the data dir for the
/// chain being used.
#[arg(long, value_name = "PATH", verbatim_doc_comment)]
db: Option<PathBuf>,
/// The chain this node is running.
///
/// Possible values are either a built-in chain or the path to a chain specification file.
@@ -63,10 +58,7 @@ impl Command {
pub async fn execute(self) -> eyre::Result<()> {
// add network name to data dir
let data_dir = self.datadir.unwrap_or_chain_default(self.chain.chain);
// use the overridden db path if specified
let db_path = self.db.clone().unwrap_or(data_dir.db_path());
let db_path = data_dir.db_path();
std::fs::create_dir_all(&db_path)?;
let db = Env::<WriteMap>::open(db_path.as_ref(), reth_db::mdbx::EnvKind::RW)?;

View File

@@ -37,11 +37,6 @@ pub struct Command {
#[arg(long, value_name = "DATA_DIR", verbatim_doc_comment, default_value_t)]
datadir: MaybePlatformPath<DataDirPath>,
/// The path to the database folder. If not specified, it will be set in the data dir for the
/// chain being used.
#[arg(long, value_name = "PATH", verbatim_doc_comment)]
db: Option<PathBuf>,
/// The chain this node is running.
///
/// Possible values are either a built-in chain or the path to a chain specification file.
@@ -100,10 +95,7 @@ impl Command {
pub async fn execute(self) -> eyre::Result<()> {
// add network name to data dir
let data_dir = self.datadir.unwrap_or_chain_default(self.chain.chain);
// use the overridden db path if specified
let db_path = self.db.clone().unwrap_or(data_dir.db_path());
let db_path = data_dir.db_path();
info!(target: "reth::cli", path = ?db_path, "Opening database");
std::fs::create_dir_all(&db_path)?;

View File

@@ -13,7 +13,7 @@ use reth_stages::{
},
ExecInput, Stage,
};
use std::{ops::Deref, path::PathBuf, sync::Arc};
use std::{ops::Deref, sync::Arc};
/// `reth merkle-debug` command
#[derive(Debug, Parser)]
@@ -28,11 +28,6 @@ pub struct Command {
#[arg(long, value_name = "DATA_DIR", verbatim_doc_comment, default_value_t)]
datadir: MaybePlatformPath<DataDirPath>,
/// The path to the database folder. If not specified, it will be set in the data dir for the
/// chain being used.
#[arg(long, value_name = "PATH", verbatim_doc_comment)]
db: Option<PathBuf>,
/// The chain this node is running.
///
/// Possible values are either a built-in chain or the path to a chain specification file.
@@ -64,10 +59,7 @@ impl Command {
pub async fn execute(self) -> eyre::Result<()> {
// add network name to data dir
let data_dir = self.datadir.unwrap_or_chain_default(self.chain.chain);
// use the overridden db path if specified
let db_path = self.db.clone().unwrap_or(data_dir.db_path());
let db_path = data_dir.db_path();
std::fs::create_dir_all(&db_path)?;
let db = Arc::new(init_db(db_path)?);

View File

@@ -95,11 +95,6 @@ pub struct Command {
#[arg(long, value_name = "FILE", verbatim_doc_comment)]
config: Option<PathBuf>,
/// The path to the database folder. If not specified, it will be set in the data dir for the
/// chain being used.
#[arg(long, value_name = "PATH", verbatim_doc_comment)]
db: Option<PathBuf>,
/// The chain this node is running.
///
/// Possible values are either a built-in chain or the path to a chain specification file.
@@ -155,9 +150,7 @@ impl Command {
// always store reth.toml in the data dir, not the chain specific data dir
info!(target: "reth::cli", path = ?config_path, "Configuration loaded");
// use the overridden db path if specified
let db_path = self.db.clone().unwrap_or(data_dir.db_path());
let db_path = data_dir.db_path();
info!(target: "reth::cli", path = ?db_path, "Opening database");
let db = Arc::new(init_db(&db_path)?);
info!(target: "reth::cli", "Database opened");
@@ -807,12 +800,12 @@ mod tests {
fn parse_db_path() {
let cmd = Command::try_parse_from(["reth", "--db", "my/path/to/db"]).unwrap();
let data_dir = cmd.datadir.unwrap_or_chain_default(cmd.chain.chain);
let db_path = cmd.db.unwrap_or(data_dir.db_path());
let db_path = data_dir.db_path();
assert_eq!(db_path, Path::new("my/path/to/db"));
let cmd = Command::try_parse_from(["reth"]).unwrap();
let data_dir = cmd.datadir.unwrap_or_chain_default(cmd.chain.chain);
let db_path = cmd.db.unwrap_or(data_dir.db_path());
let db_path = data_dir.db_path();
assert!(db_path.ends_with("reth/mainnet/db"), "{:?}", cmd.config);
}
}

View File

@@ -17,7 +17,7 @@ pub(crate) fn impl_decodable(ast: &syn::DeriveInput) -> Result<TokenStream> {
let is_opt = is_optional(field);
if is_opt {
if !supports_trailing_opt {
return Err(Error::new_spanned(field, "Optional fields are disabled. Add `#[rlp(trailing)]` attribute to the struct in order to enable"))
return Err(Error::new_spanned(field, "Optional fields are disabled. Add `#[rlp(trailing)]` attribute to the struct in order to enable"));
}
encountered_opt_item = true;
} else if encountered_opt_item && !attributes_include(&field.attrs, "default") {

View File

@@ -26,7 +26,7 @@ pub(crate) fn impl_encodable(ast: &syn::DeriveInput) -> Result<TokenStream> {
let is_opt = is_optional(field);
if is_opt {
if !supports_trailing_opt {
return Err(Error::new_spanned(field, "Optional fields are disabled. Add `#[rlp(trailing)]` attribute to the struct in order to enable"))
return Err(Error::new_spanned(field, "Optional fields are disabled. Add `#[rlp(trailing)]` attribute to the struct in order to enable"));
}
encountered_opt_item = true;
} else if encountered_opt_item {