feat: config (#496)

* feat: default reth dirs

* docs: clarify txpool config docs

* feat: `serde` feature for `reth-consensus`

* feat: add missing hardforks

* feat: full chain specification

* feat: `DbPath` type

* feat: custom chain specs

* feat: `--debug.tip` option

* feat: basic stage config

* fix: resize db geometry

* refactor: don't commit in headers stage

* chore: remove headers dl timeout

* feat: loading of config

* refactor(config): `stage` -> `stages`
This commit is contained in:
Bjerg
2022-12-19 21:27:26 +01:00
committed by GitHub
parent 516d744bdd
commit 13bb41517d
21 changed files with 1356 additions and 140 deletions

95
bin/reth/src/dirs.rs Normal file
View File

@ -0,0 +1,95 @@
//! reth data directories.
use crate::util::parse_path;
use std::{
env::VarError,
fmt::{Debug, Display, Formatter},
path::{Path, PathBuf},
str::FromStr,
};
/// Returns the path to the reth data directory.
///
/// Refer to [dirs_next::data_dir] for cross-platform behavior.
pub fn data_dir() -> Option<PathBuf> {
dirs_next::data_dir().map(|root| root.join("reth"))
}
/// Returns the path to the reth database.
///
/// Refer to [dirs_next::data_dir] for cross-platform behavior.
pub fn database_path() -> Option<PathBuf> {
data_dir().map(|root| root.join("db"))
}
/// Returns the path to the reth configuration directory.
///
/// Refer to [dirs_next::config_dir] for cross-platform behavior.
pub fn config_dir() -> Option<PathBuf> {
dirs_next::config_dir().map(|root| root.join("reth"))
}
/// A wrapper type that either parses a user-given path for the reth database or defaults to an
/// OS-specific path.
#[derive(Clone, Debug)]
pub struct DbPath(PathBuf);
impl Display for DbPath {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0.display())
}
}
impl Default for DbPath {
fn default() -> Self {
Self(database_path().expect("Could not determine default database path. Set one manually."))
}
}
impl FromStr for DbPath {
type Err = shellexpand::LookupError<VarError>;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(Self(parse_path(s)?))
}
}
impl AsRef<Path> for DbPath {
fn as_ref(&self) -> &Path {
self.0.as_path()
}
}
/// A wrapper type that either parses a user-given path for the reth config or defaults to an
/// OS-specific path.
#[derive(Clone, Debug)]
pub struct ConfigPath(PathBuf);
impl Display for ConfigPath {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0.display())
}
}
impl Default for ConfigPath {
fn default() -> Self {
Self(
config_dir()
.expect("Could not determine default database path. Set one manually.")
.join("reth.toml"),
)
}
}
impl FromStr for ConfigPath {
type Err = shellexpand::LookupError<VarError>;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(Self(parse_path(s)?))
}
}
impl AsRef<Path> for ConfigPath {
fn as_ref(&self) -> &Path {
self.0.as_path()
}
}