mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-07 00:42:42 +00:00
Change DB Manager Clap usage to derive (#5898)
* implement clap derive for the db manager * tweak some clap configs * make cli local * add global to help flag * fmt * Merge branch 'unstable' of https://github.com/sigp/lighthouse into HEAD * merge * add enum constraints to flag
This commit is contained in:
14
Cargo.lock
generated
14
Cargo.lock
generated
@@ -1340,6 +1340,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0"
|
checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap_builder",
|
"clap_builder",
|
||||||
|
"clap_derive",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1355,6 +1356,18 @@ dependencies = [
|
|||||||
"terminal_size",
|
"terminal_size",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap_derive"
|
||||||
|
version = "4.5.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "528131438037fd55894f62d6e9f068b8f45ac57ffa77517819645d10aed04f64"
|
||||||
|
dependencies = [
|
||||||
|
"heck 0.5.0",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.66",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap_lex"
|
name = "clap_lex"
|
||||||
version = "0.7.0"
|
version = "0.7.0"
|
||||||
@@ -1824,6 +1837,7 @@ dependencies = [
|
|||||||
"clap_utils",
|
"clap_utils",
|
||||||
"environment",
|
"environment",
|
||||||
"hex",
|
"hex",
|
||||||
|
"serde",
|
||||||
"slog",
|
"slog",
|
||||||
"store",
|
"store",
|
||||||
"strum",
|
"strum",
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ bincode = "1"
|
|||||||
bitvec = "1"
|
bitvec = "1"
|
||||||
byteorder = "1"
|
byteorder = "1"
|
||||||
bytes = "1"
|
bytes = "1"
|
||||||
clap = { version = "4.5.4", features = ["cargo", "wrap_help"] }
|
clap = { version = "4.5.4", features = ["derive", "cargo", "wrap_help"] }
|
||||||
# Turn off c-kzg's default features which include `blst/portable`. We can turn on blst's portable
|
# Turn off c-kzg's default features which include `blst/portable`. We can turn on blst's portable
|
||||||
# feature ourselves when desired.
|
# feature ourselves when desired.
|
||||||
c-kzg = { version = "1", default-features = false }
|
c-kzg = { version = "1", default-features = false }
|
||||||
|
|||||||
@@ -402,7 +402,10 @@ pub fn get_config<E: EthSpec>(
|
|||||||
client_config.blobs_db_path = Some(PathBuf::from(blobs_db_dir));
|
client_config.blobs_db_path = Some(PathBuf::from(blobs_db_dir));
|
||||||
}
|
}
|
||||||
|
|
||||||
let (sprp, sprp_explicit) = get_slots_per_restore_point::<E>(cli_args)?;
|
let (sprp, sprp_explicit) = get_slots_per_restore_point::<E>(clap_utils::parse_optional(
|
||||||
|
cli_args,
|
||||||
|
"slots-per-restore-point",
|
||||||
|
)?)?;
|
||||||
client_config.store.slots_per_restore_point = sprp;
|
client_config.store.slots_per_restore_point = sprp;
|
||||||
client_config.store.slots_per_restore_point_set_explicitly = sprp_explicit;
|
client_config.store.slots_per_restore_point_set_explicitly = sprp_explicit;
|
||||||
|
|
||||||
@@ -1476,11 +1479,9 @@ pub fn get_data_dir(cli_args: &ArgMatches) -> PathBuf {
|
|||||||
///
|
///
|
||||||
/// Return `(sprp, set_explicitly)` where `set_explicitly` is `true` if the user provided the value.
|
/// Return `(sprp, set_explicitly)` where `set_explicitly` is `true` if the user provided the value.
|
||||||
pub fn get_slots_per_restore_point<E: EthSpec>(
|
pub fn get_slots_per_restore_point<E: EthSpec>(
|
||||||
cli_args: &ArgMatches,
|
slots_per_restore_point: Option<u64>,
|
||||||
) -> Result<(u64, bool), String> {
|
) -> Result<(u64, bool), String> {
|
||||||
if let Some(slots_per_restore_point) =
|
if let Some(slots_per_restore_point) = slots_per_restore_point {
|
||||||
clap_utils::parse_optional(cli_args, "slots-per-restore-point")?
|
|
||||||
{
|
|
||||||
Ok((slots_per_restore_point, true))
|
Ok((slots_per_restore_point, true))
|
||||||
} else {
|
} else {
|
||||||
let default = std::cmp::min(
|
let default = std::cmp::min(
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ Commands:
|
|||||||
is the recommended way to provide a network boot-node since it has a
|
is the recommended way to provide a network boot-node since it has a
|
||||||
reduced attack surface compared to a full beacon node.
|
reduced attack surface compared to a full beacon node.
|
||||||
database_manager
|
database_manager
|
||||||
Manage a beacon node database [aliases: db]
|
Manage a beacon node database. [aliases: db]
|
||||||
validator_client
|
validator_client
|
||||||
When connected to a beacon node, performs the duties of a staked
|
When connected to a beacon node, performs the duties of a staked
|
||||||
validator (e.g., proposing blocks and attestations). [aliases: v, vc,
|
validator (e.g., proposing blocks and attestations). [aliases: v, vc,
|
||||||
|
|||||||
@@ -14,3 +14,4 @@ store = { workspace = true }
|
|||||||
types = { workspace = true }
|
types = { workspace = true }
|
||||||
slog = { workspace = true }
|
slog = { workspace = true }
|
||||||
strum = { workspace = true }
|
strum = { workspace = true }
|
||||||
|
serde = { workspace = true }
|
||||||
|
|||||||
229
database_manager/src/cli.rs
Normal file
229
database_manager/src/cli.rs
Normal file
@@ -0,0 +1,229 @@
|
|||||||
|
pub use clap::{Arg, ArgAction, Args, Command, FromArgMatches, Parser};
|
||||||
|
use clap_utils::get_color_style;
|
||||||
|
use clap_utils::FLAG_HEADER;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
use crate::InspectTarget;
|
||||||
|
|
||||||
|
#[derive(Parser, Clone, Deserialize, Serialize, Debug)]
|
||||||
|
#[clap(
|
||||||
|
name = "database_manager",
|
||||||
|
visible_alias = "db",
|
||||||
|
about = "Manage a beacon node database.",
|
||||||
|
styles = get_color_style(),
|
||||||
|
next_line_help = true,
|
||||||
|
term_width = 80,
|
||||||
|
disable_help_flag = true,
|
||||||
|
disable_help_subcommand = true,
|
||||||
|
display_order = 0,
|
||||||
|
)]
|
||||||
|
pub struct DatabaseManager {
|
||||||
|
#[clap(
|
||||||
|
long,
|
||||||
|
value_name = "SLOT_COUNT",
|
||||||
|
help = "Specifies how often a freezer DB restore point should be stored. \
|
||||||
|
Cannot be changed after initialization. \
|
||||||
|
[default: 2048 (mainnet) or 64 (minimal)]",
|
||||||
|
display_order = 0
|
||||||
|
)]
|
||||||
|
pub slots_per_restore_point: Option<u64>,
|
||||||
|
|
||||||
|
#[clap(
|
||||||
|
long,
|
||||||
|
value_name = "DIR",
|
||||||
|
help = "Data directory for the freezer database.",
|
||||||
|
display_order = 0
|
||||||
|
)]
|
||||||
|
pub freezer_dir: Option<PathBuf>,
|
||||||
|
|
||||||
|
#[clap(
|
||||||
|
long,
|
||||||
|
value_name = "EPOCHS",
|
||||||
|
default_value_t = 0,
|
||||||
|
help = "The margin for blob pruning in epochs. The oldest blobs are pruned \
|
||||||
|
up until data_availability_boundary - blob_prune_margin_epochs.",
|
||||||
|
display_order = 0
|
||||||
|
)]
|
||||||
|
pub blob_prune_margin_epochs: u64,
|
||||||
|
|
||||||
|
#[clap(
|
||||||
|
long,
|
||||||
|
value_name = "DIR",
|
||||||
|
help = "Data directory for the blobs database.",
|
||||||
|
display_order = 0
|
||||||
|
)]
|
||||||
|
pub blobs_dir: Option<PathBuf>,
|
||||||
|
|
||||||
|
#[clap(
|
||||||
|
long,
|
||||||
|
global = true,
|
||||||
|
help = "Prints help information",
|
||||||
|
action = clap::ArgAction::HelpLong,
|
||||||
|
display_order = 0,
|
||||||
|
help_heading = FLAG_HEADER
|
||||||
|
)]
|
||||||
|
help: Option<bool>,
|
||||||
|
|
||||||
|
#[clap(subcommand)]
|
||||||
|
pub subcommand: DatabaseManagerSubcommand,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Parser, Clone, Deserialize, Serialize, Debug)]
|
||||||
|
#[clap(rename_all = "kebab-case")]
|
||||||
|
pub enum DatabaseManagerSubcommand {
|
||||||
|
Migrate(Migrate),
|
||||||
|
Inspect(Inspect),
|
||||||
|
Version(Version),
|
||||||
|
PrunePayloads(PrunePayloads),
|
||||||
|
PruneBlobs(PruneBlobs),
|
||||||
|
PruneStates(PruneStates),
|
||||||
|
Compact(Compact),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Parser, Clone, Deserialize, Serialize, Debug)]
|
||||||
|
#[clap(about = "Migrate the database to a specific schema version.")]
|
||||||
|
pub struct Migrate {
|
||||||
|
#[clap(
|
||||||
|
long,
|
||||||
|
value_name = "VERSION",
|
||||||
|
help = "Schema version to migrate to",
|
||||||
|
display_order = 0
|
||||||
|
)]
|
||||||
|
pub to: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Parser, Clone, Deserialize, Serialize, Debug)]
|
||||||
|
#[clap(about = "Inspect raw database values.")]
|
||||||
|
pub struct Inspect {
|
||||||
|
#[clap(
|
||||||
|
long,
|
||||||
|
value_name = "TAG",
|
||||||
|
help = "3-byte column ID (see `DBColumn`)",
|
||||||
|
display_order = 0
|
||||||
|
)]
|
||||||
|
pub column: String,
|
||||||
|
|
||||||
|
#[clap(
|
||||||
|
long,
|
||||||
|
value_enum,
|
||||||
|
value_name = "TARGET",
|
||||||
|
default_value_t = InspectTarget::ValueSizes,
|
||||||
|
help = "Select the type of output to show",
|
||||||
|
display_order = 0,
|
||||||
|
)]
|
||||||
|
pub output: InspectTarget,
|
||||||
|
|
||||||
|
#[clap(
|
||||||
|
long,
|
||||||
|
value_name = "N",
|
||||||
|
help = "Skip over the first N keys",
|
||||||
|
display_order = 0
|
||||||
|
)]
|
||||||
|
pub skip: Option<usize>,
|
||||||
|
|
||||||
|
#[clap(
|
||||||
|
long,
|
||||||
|
value_name = "N",
|
||||||
|
help = "Output at most N keys",
|
||||||
|
display_order = 0
|
||||||
|
)]
|
||||||
|
pub limit: Option<usize>,
|
||||||
|
|
||||||
|
#[clap(
|
||||||
|
long,
|
||||||
|
conflicts_with = "blobs_db",
|
||||||
|
help = "Inspect the freezer DB rather than the hot DB",
|
||||||
|
display_order = 0,
|
||||||
|
help_heading = FLAG_HEADER
|
||||||
|
)]
|
||||||
|
pub freezer: bool,
|
||||||
|
|
||||||
|
#[clap(
|
||||||
|
long,
|
||||||
|
conflicts_with = "freezer",
|
||||||
|
help = "Inspect the blobs DB rather than the hot DB",
|
||||||
|
display_order = 0,
|
||||||
|
help_heading = FLAG_HEADER
|
||||||
|
)]
|
||||||
|
pub blobs_db: bool,
|
||||||
|
|
||||||
|
#[clap(
|
||||||
|
long,
|
||||||
|
value_name = "DIR",
|
||||||
|
help = "Base directory for the output files. Defaults to the current directory",
|
||||||
|
display_order = 0
|
||||||
|
)]
|
||||||
|
pub output_dir: Option<PathBuf>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Parser, Clone, Deserialize, Serialize, Debug)]
|
||||||
|
#[clap(about = "Display database schema version.", visible_aliases = &["v"])]
|
||||||
|
pub struct Version {}
|
||||||
|
|
||||||
|
#[derive(Parser, Clone, Deserialize, Serialize, Debug)]
|
||||||
|
#[clap(
|
||||||
|
about = "Prune finalized execution payloads.",
|
||||||
|
alias = "prune_payloads"
|
||||||
|
)]
|
||||||
|
pub struct PrunePayloads {}
|
||||||
|
|
||||||
|
#[derive(Parser, Clone, Deserialize, Serialize, Debug)]
|
||||||
|
#[clap(
|
||||||
|
about = "Prune blobs older than data availability boundary.",
|
||||||
|
alias = "prune_blobs"
|
||||||
|
)]
|
||||||
|
pub struct PruneBlobs {}
|
||||||
|
|
||||||
|
#[derive(Parser, Clone, Deserialize, Serialize, Debug)]
|
||||||
|
#[clap(
|
||||||
|
about = "Prune all beacon states from the freezer database.",
|
||||||
|
alias = "prune_states"
|
||||||
|
)]
|
||||||
|
pub struct PruneStates {
|
||||||
|
#[clap(
|
||||||
|
long,
|
||||||
|
help = "Commit to pruning states irreversably. Without this flag the command will \
|
||||||
|
just check that the database is capable of being pruned.",
|
||||||
|
help_heading = FLAG_HEADER,
|
||||||
|
)]
|
||||||
|
pub confirm: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Parser, Clone, Deserialize, Serialize, Debug)]
|
||||||
|
#[clap(about = "Compact database manually.")]
|
||||||
|
pub struct Compact {
|
||||||
|
#[clap(
|
||||||
|
long,
|
||||||
|
value_name = "TAG",
|
||||||
|
help = "3-byte column ID (see `DBColumn`)",
|
||||||
|
display_order = 0
|
||||||
|
)]
|
||||||
|
pub column: String,
|
||||||
|
|
||||||
|
#[clap(
|
||||||
|
long,
|
||||||
|
conflicts_with = "blobs_db",
|
||||||
|
help = "Inspect the freezer DB rather than the hot DB",
|
||||||
|
display_order = 0,
|
||||||
|
help_heading = FLAG_HEADER
|
||||||
|
)]
|
||||||
|
pub freezer: bool,
|
||||||
|
|
||||||
|
#[clap(
|
||||||
|
long,
|
||||||
|
conflicts_with = "freezer",
|
||||||
|
help = "Inspect the blobs DB rather than the hot DB",
|
||||||
|
display_order = 0,
|
||||||
|
help_heading = FLAG_HEADER
|
||||||
|
)]
|
||||||
|
pub blobs_db: bool,
|
||||||
|
|
||||||
|
#[clap(
|
||||||
|
long,
|
||||||
|
value_name = "DIR",
|
||||||
|
help = "Base directory for the output files. Defaults to the current directory",
|
||||||
|
display_order = 0
|
||||||
|
)]
|
||||||
|
pub output_dir: Option<PathBuf>,
|
||||||
|
}
|
||||||
@@ -1,11 +1,17 @@
|
|||||||
|
pub mod cli;
|
||||||
|
use crate::cli::DatabaseManager;
|
||||||
|
use crate::cli::Migrate;
|
||||||
|
use crate::cli::PruneStates;
|
||||||
use beacon_chain::{
|
use beacon_chain::{
|
||||||
builder::Witness, eth1_chain::CachingEth1Backend, schema_change::migrate_schema,
|
builder::Witness, eth1_chain::CachingEth1Backend, schema_change::migrate_schema,
|
||||||
slot_clock::SystemTimeSlotClock,
|
slot_clock::SystemTimeSlotClock,
|
||||||
};
|
};
|
||||||
use beacon_node::{get_data_dir, get_slots_per_restore_point, ClientConfig};
|
use beacon_node::{get_data_dir, get_slots_per_restore_point, ClientConfig};
|
||||||
use clap::{Arg, ArgAction, ArgMatches, Command};
|
use clap::ArgMatches;
|
||||||
use clap_utils::{get_color_style, FLAG_HEADER};
|
use clap::ValueEnum;
|
||||||
|
use cli::{Compact, Inspect};
|
||||||
use environment::{Environment, RuntimeContext};
|
use environment::{Environment, RuntimeContext};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
use slog::{info, warn, Logger};
|
use slog::{info, warn, Logger};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
@@ -16,250 +22,30 @@ use store::{
|
|||||||
metadata::{SchemaVersion, CURRENT_SCHEMA_VERSION},
|
metadata::{SchemaVersion, CURRENT_SCHEMA_VERSION},
|
||||||
DBColumn, HotColdDB, KeyValueStore, LevelDB,
|
DBColumn, HotColdDB, KeyValueStore, LevelDB,
|
||||||
};
|
};
|
||||||
use strum::{EnumString, EnumVariantNames, VariantNames};
|
use strum::{EnumString, EnumVariantNames};
|
||||||
use types::{BeaconState, EthSpec, Slot};
|
use types::{BeaconState, EthSpec, Slot};
|
||||||
|
|
||||||
pub const CMD: &str = "database_manager";
|
|
||||||
|
|
||||||
pub fn version_cli_app() -> Command {
|
|
||||||
Command::new("version")
|
|
||||||
.visible_aliases(["v"])
|
|
||||||
.styles(get_color_style())
|
|
||||||
.about("Display database schema version")
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn migrate_cli_app() -> Command {
|
|
||||||
Command::new("migrate")
|
|
||||||
.styles(get_color_style())
|
|
||||||
.about("Migrate the database to a specific schema version")
|
|
||||||
.arg(
|
|
||||||
Arg::new("to")
|
|
||||||
.long("to")
|
|
||||||
.value_name("VERSION")
|
|
||||||
.help("Schema version to migrate to")
|
|
||||||
.action(ArgAction::Set)
|
|
||||||
.required(true),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn inspect_cli_app() -> Command {
|
|
||||||
Command::new("inspect")
|
|
||||||
.styles(get_color_style())
|
|
||||||
.about("Inspect raw database values")
|
|
||||||
.arg(
|
|
||||||
Arg::new("column")
|
|
||||||
.long("column")
|
|
||||||
.value_name("TAG")
|
|
||||||
.help("3-byte column ID (see `DBColumn`)")
|
|
||||||
.action(ArgAction::Set)
|
|
||||||
.required(true)
|
|
||||||
.display_order(0),
|
|
||||||
)
|
|
||||||
.arg(
|
|
||||||
Arg::new("output")
|
|
||||||
.long("output")
|
|
||||||
.value_name("TARGET")
|
|
||||||
.help("Select the type of output to show")
|
|
||||||
.default_value("sizes")
|
|
||||||
.value_parser(InspectTarget::VARIANTS.to_vec())
|
|
||||||
.display_order(0),
|
|
||||||
)
|
|
||||||
.arg(
|
|
||||||
Arg::new("skip")
|
|
||||||
.long("skip")
|
|
||||||
.value_name("N")
|
|
||||||
.help("Skip over the first N keys")
|
|
||||||
.display_order(0),
|
|
||||||
)
|
|
||||||
.arg(
|
|
||||||
Arg::new("limit")
|
|
||||||
.long("limit")
|
|
||||||
.value_name("N")
|
|
||||||
.help("Output at most N keys")
|
|
||||||
.display_order(0),
|
|
||||||
)
|
|
||||||
.arg(
|
|
||||||
Arg::new("freezer")
|
|
||||||
.long("freezer")
|
|
||||||
.help("Inspect the freezer DB rather than the hot DB")
|
|
||||||
.action(ArgAction::SetTrue)
|
|
||||||
.help_heading(FLAG_HEADER)
|
|
||||||
.conflicts_with("blobs-db")
|
|
||||||
.display_order(0),
|
|
||||||
)
|
|
||||||
.arg(
|
|
||||||
Arg::new("blobs-db")
|
|
||||||
.long("blobs-db")
|
|
||||||
.help("Inspect the blobs DB rather than the hot DB")
|
|
||||||
.action(ArgAction::SetTrue)
|
|
||||||
.help_heading(FLAG_HEADER)
|
|
||||||
.conflicts_with("freezer")
|
|
||||||
.display_order(0),
|
|
||||||
)
|
|
||||||
.arg(
|
|
||||||
Arg::new("output-dir")
|
|
||||||
.long("output-dir")
|
|
||||||
.value_name("DIR")
|
|
||||||
.help("Base directory for the output files. Defaults to the current directory")
|
|
||||||
.action(ArgAction::Set)
|
|
||||||
.display_order(0),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn compact_cli_app() -> Command {
|
|
||||||
Command::new("compact")
|
|
||||||
.styles(get_color_style())
|
|
||||||
.about("Compact database manually")
|
|
||||||
.arg(
|
|
||||||
Arg::new("column")
|
|
||||||
.long("column")
|
|
||||||
.value_name("TAG")
|
|
||||||
.help("3-byte column ID (see `DBColumn`)")
|
|
||||||
.action(ArgAction::Set)
|
|
||||||
.required(true)
|
|
||||||
.display_order(0),
|
|
||||||
)
|
|
||||||
.arg(
|
|
||||||
Arg::new("freezer")
|
|
||||||
.long("freezer")
|
|
||||||
.help("Inspect the freezer DB rather than the hot DB")
|
|
||||||
.action(ArgAction::SetTrue)
|
|
||||||
.help_heading(FLAG_HEADER)
|
|
||||||
.conflicts_with("blobs-db")
|
|
||||||
.display_order(0),
|
|
||||||
)
|
|
||||||
.arg(
|
|
||||||
Arg::new("blobs-db")
|
|
||||||
.long("blobs-db")
|
|
||||||
.help("Inspect the blobs DB rather than the hot DB")
|
|
||||||
.action(ArgAction::SetTrue)
|
|
||||||
.help_heading(FLAG_HEADER)
|
|
||||||
.conflicts_with("freezer")
|
|
||||||
.display_order(0),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn prune_payloads_app() -> Command {
|
|
||||||
Command::new("prune-payloads")
|
|
||||||
.alias("prune_payloads")
|
|
||||||
.styles(get_color_style())
|
|
||||||
.about("Prune finalized execution payloads")
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn prune_blobs_app() -> Command {
|
|
||||||
Command::new("prune-blobs")
|
|
||||||
.alias("prune_blobs")
|
|
||||||
.styles(get_color_style())
|
|
||||||
.about("Prune blobs older than data availability boundary")
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn prune_states_app() -> Command {
|
|
||||||
Command::new("prune-states")
|
|
||||||
.alias("prune_states")
|
|
||||||
.arg(
|
|
||||||
Arg::new("confirm")
|
|
||||||
.long("confirm")
|
|
||||||
.help(
|
|
||||||
"Commit to pruning states irreversably. Without this flag the command will \
|
|
||||||
just check that the database is capable of being pruned.",
|
|
||||||
)
|
|
||||||
.action(ArgAction::SetTrue)
|
|
||||||
.help_heading(FLAG_HEADER)
|
|
||||||
.display_order(0),
|
|
||||||
)
|
|
||||||
.styles(get_color_style())
|
|
||||||
.about("Prune all beacon states from the freezer database")
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn cli_app() -> Command {
|
|
||||||
Command::new(CMD)
|
|
||||||
.display_order(0)
|
|
||||||
.visible_aliases(["db"])
|
|
||||||
.styles(get_color_style())
|
|
||||||
.about("Manage a beacon node database")
|
|
||||||
.arg(
|
|
||||||
Arg::new("help")
|
|
||||||
.long("help")
|
|
||||||
.short('h')
|
|
||||||
.help("Prints help information")
|
|
||||||
.action(ArgAction::HelpLong)
|
|
||||||
.display_order(0)
|
|
||||||
.help_heading(FLAG_HEADER),
|
|
||||||
)
|
|
||||||
.arg(
|
|
||||||
Arg::new("slots-per-restore-point")
|
|
||||||
.long("slots-per-restore-point")
|
|
||||||
.value_name("SLOT_COUNT")
|
|
||||||
.help(
|
|
||||||
"Specifies how often a freezer DB restore point should be stored. \
|
|
||||||
Cannot be changed after initialization. \
|
|
||||||
[default: 2048 (mainnet) or 64 (minimal)]",
|
|
||||||
)
|
|
||||||
.action(ArgAction::Set)
|
|
||||||
.display_order(0),
|
|
||||||
)
|
|
||||||
.arg(
|
|
||||||
Arg::new("freezer-dir")
|
|
||||||
.long("freezer-dir")
|
|
||||||
.value_name("DIR")
|
|
||||||
.help("Data directory for the freezer database.")
|
|
||||||
.action(ArgAction::Set)
|
|
||||||
.display_order(0),
|
|
||||||
)
|
|
||||||
.arg(
|
|
||||||
Arg::new("blob-prune-margin-epochs")
|
|
||||||
.long("blob-prune-margin-epochs")
|
|
||||||
.value_name("EPOCHS")
|
|
||||||
.help(
|
|
||||||
"The margin for blob pruning in epochs. The oldest blobs are pruned \
|
|
||||||
up until data_availability_boundary - blob_prune_margin_epochs.",
|
|
||||||
)
|
|
||||||
.action(ArgAction::Set)
|
|
||||||
.default_value("0")
|
|
||||||
.display_order(0),
|
|
||||||
)
|
|
||||||
.arg(
|
|
||||||
Arg::new("blobs-dir")
|
|
||||||
.long("blobs-dir")
|
|
||||||
.value_name("DIR")
|
|
||||||
.help("Data directory for the blobs database.")
|
|
||||||
.action(ArgAction::Set)
|
|
||||||
.display_order(0),
|
|
||||||
)
|
|
||||||
.subcommand(migrate_cli_app())
|
|
||||||
.subcommand(version_cli_app())
|
|
||||||
.subcommand(inspect_cli_app())
|
|
||||||
.subcommand(compact_cli_app())
|
|
||||||
.subcommand(prune_payloads_app())
|
|
||||||
.subcommand(prune_blobs_app())
|
|
||||||
.subcommand(prune_states_app())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn parse_client_config<E: EthSpec>(
|
fn parse_client_config<E: EthSpec>(
|
||||||
cli_args: &ArgMatches,
|
cli_args: &ArgMatches,
|
||||||
|
database_manager_config: &DatabaseManager,
|
||||||
_env: &Environment<E>,
|
_env: &Environment<E>,
|
||||||
) -> Result<ClientConfig, String> {
|
) -> Result<ClientConfig, String> {
|
||||||
let mut client_config = ClientConfig::default();
|
let mut client_config = ClientConfig::default();
|
||||||
|
|
||||||
client_config.set_data_dir(get_data_dir(cli_args));
|
client_config.set_data_dir(get_data_dir(cli_args));
|
||||||
|
client_config
|
||||||
|
.freezer_db_path
|
||||||
|
.clone_from(&database_manager_config.freezer_dir);
|
||||||
|
client_config
|
||||||
|
.blobs_db_path
|
||||||
|
.clone_from(&database_manager_config.blobs_dir);
|
||||||
|
|
||||||
if let Some(freezer_dir) = clap_utils::parse_optional(cli_args, "freezer-dir")? {
|
let (sprp, sprp_explicit) =
|
||||||
client_config.freezer_db_path = Some(freezer_dir);
|
get_slots_per_restore_point::<E>(database_manager_config.slots_per_restore_point)?;
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(blobs_db_dir) = clap_utils::parse_optional(cli_args, "blobs-dir")? {
|
|
||||||
client_config.blobs_db_path = Some(blobs_db_dir);
|
|
||||||
}
|
|
||||||
|
|
||||||
let (sprp, sprp_explicit) = get_slots_per_restore_point::<E>(cli_args)?;
|
|
||||||
client_config.store.slots_per_restore_point = sprp;
|
client_config.store.slots_per_restore_point = sprp;
|
||||||
client_config.store.slots_per_restore_point_set_explicitly = sprp_explicit;
|
client_config.store.slots_per_restore_point_set_explicitly = sprp_explicit;
|
||||||
|
client_config.store.blob_prune_margin_epochs = database_manager_config.blob_prune_margin_epochs;
|
||||||
if let Some(blob_prune_margin_epochs) =
|
|
||||||
clap_utils::parse_optional(cli_args, "blob-prune-margin-epochs")?
|
|
||||||
{
|
|
||||||
client_config.store.blob_prune_margin_epochs = blob_prune_margin_epochs;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(client_config)
|
Ok(client_config)
|
||||||
}
|
}
|
||||||
@@ -301,15 +87,21 @@ pub fn display_db_version<E: EthSpec>(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, EnumString, EnumVariantNames)]
|
#[derive(
|
||||||
|
Debug, PartialEq, Eq, Clone, EnumString, Deserialize, Serialize, EnumVariantNames, ValueEnum,
|
||||||
|
)]
|
||||||
pub enum InspectTarget {
|
pub enum InspectTarget {
|
||||||
#[strum(serialize = "sizes")]
|
#[strum(serialize = "sizes")]
|
||||||
|
#[clap(name = "sizes")]
|
||||||
ValueSizes,
|
ValueSizes,
|
||||||
#[strum(serialize = "total")]
|
#[strum(serialize = "total")]
|
||||||
|
#[clap(name = "total")]
|
||||||
ValueTotal,
|
ValueTotal,
|
||||||
#[strum(serialize = "values")]
|
#[strum(serialize = "values")]
|
||||||
|
#[clap(name = "values")]
|
||||||
Values,
|
Values,
|
||||||
#[strum(serialize = "gaps")]
|
#[strum(serialize = "gaps")]
|
||||||
|
#[clap(name = "gaps")]
|
||||||
Gaps,
|
Gaps,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -324,16 +116,18 @@ pub struct InspectConfig {
|
|||||||
output_dir: PathBuf,
|
output_dir: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_inspect_config(cli_args: &ArgMatches) -> Result<InspectConfig, String> {
|
fn parse_inspect_config(inspect_config: &Inspect) -> Result<InspectConfig, String> {
|
||||||
let column = clap_utils::parse_required(cli_args, "column")?;
|
let column: DBColumn = inspect_config
|
||||||
let target = clap_utils::parse_required(cli_args, "output")?;
|
.column
|
||||||
let skip = clap_utils::parse_optional(cli_args, "skip")?;
|
.parse()
|
||||||
let limit = clap_utils::parse_optional(cli_args, "limit")?;
|
.map_err(|e| format!("Unable to parse column flag: {e:?}"))?;
|
||||||
let freezer = cli_args.get_flag("freezer");
|
let target: InspectTarget = inspect_config.output.clone();
|
||||||
let blobs_db = cli_args.get_flag("blobs-db");
|
let skip = inspect_config.skip;
|
||||||
|
let limit = inspect_config.limit;
|
||||||
|
let freezer = inspect_config.freezer;
|
||||||
|
let blobs_db = inspect_config.blobs_db;
|
||||||
|
|
||||||
let output_dir: PathBuf =
|
let output_dir: PathBuf = inspect_config.output_dir.clone().unwrap_or_default();
|
||||||
clap_utils::parse_optional(cli_args, "output-dir")?.unwrap_or_else(PathBuf::new);
|
|
||||||
Ok(InspectConfig {
|
Ok(InspectConfig {
|
||||||
column,
|
column,
|
||||||
target,
|
target,
|
||||||
@@ -450,10 +244,13 @@ pub struct CompactConfig {
|
|||||||
blobs_db: bool,
|
blobs_db: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_compact_config(cli_args: &ArgMatches) -> Result<CompactConfig, String> {
|
fn parse_compact_config(compact_config: &Compact) -> Result<CompactConfig, String> {
|
||||||
let column = clap_utils::parse_required(cli_args, "column")?;
|
let column: DBColumn = compact_config
|
||||||
let freezer = cli_args.get_flag("freezer");
|
.column
|
||||||
let blobs_db = cli_args.get_flag("blobs-db");
|
.parse()
|
||||||
|
.expect("column is a required field");
|
||||||
|
let freezer = compact_config.freezer;
|
||||||
|
let blobs_db = compact_config.blobs_db;
|
||||||
Ok(CompactConfig {
|
Ok(CompactConfig {
|
||||||
column,
|
column,
|
||||||
freezer,
|
freezer,
|
||||||
@@ -492,8 +289,8 @@ pub struct MigrateConfig {
|
|||||||
to: SchemaVersion,
|
to: SchemaVersion,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_migrate_config(cli_args: &ArgMatches) -> Result<MigrateConfig, String> {
|
fn parse_migrate_config(migrate_config: &Migrate) -> Result<MigrateConfig, String> {
|
||||||
let to = SchemaVersion(clap_utils::parse_required(cli_args, "to")?);
|
let to = SchemaVersion(migrate_config.to);
|
||||||
|
|
||||||
Ok(MigrateConfig { to })
|
Ok(MigrateConfig { to })
|
||||||
}
|
}
|
||||||
@@ -595,9 +392,10 @@ pub fn prune_blobs<E: EthSpec>(
|
|||||||
pub struct PruneStatesConfig {
|
pub struct PruneStatesConfig {
|
||||||
confirm: bool,
|
confirm: bool,
|
||||||
}
|
}
|
||||||
|
fn parse_prune_states_config(
|
||||||
fn parse_prune_states_config(cli_args: &ArgMatches) -> Result<PruneStatesConfig, String> {
|
prune_states_config: &PruneStates,
|
||||||
let confirm = cli_args.get_flag("confirm");
|
) -> Result<PruneStatesConfig, String> {
|
||||||
|
let confirm = prune_states_config.confirm;
|
||||||
Ok(PruneStatesConfig { confirm })
|
Ok(PruneStatesConfig { confirm })
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -676,33 +474,35 @@ pub fn prune_states<E: EthSpec>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Run the database manager, returning an error string if the operation did not succeed.
|
/// Run the database manager, returning an error string if the operation did not succeed.
|
||||||
pub fn run<E: EthSpec>(cli_args: &ArgMatches, env: Environment<E>) -> Result<(), String> {
|
pub fn run<E: EthSpec>(
|
||||||
let client_config = parse_client_config(cli_args, &env)?;
|
cli_args: &ArgMatches,
|
||||||
|
db_manager_config: &DatabaseManager,
|
||||||
|
env: Environment<E>,
|
||||||
|
) -> Result<(), String> {
|
||||||
|
let client_config = parse_client_config(cli_args, db_manager_config, &env)?;
|
||||||
let context = env.core_context();
|
let context = env.core_context();
|
||||||
let log = context.log().clone();
|
let log = context.log().clone();
|
||||||
let format_err = |e| format!("Fatal error: {:?}", e);
|
let format_err = |e| format!("Fatal error: {:?}", e);
|
||||||
|
|
||||||
match cli_args.subcommand() {
|
match &db_manager_config.subcommand {
|
||||||
Some(("version", _)) => {
|
cli::DatabaseManagerSubcommand::Migrate(migrate_config) => {
|
||||||
display_db_version(client_config, &context, log).map_err(format_err)
|
let migrate_config = parse_migrate_config(migrate_config)?;
|
||||||
}
|
|
||||||
Some(("migrate", cli_args)) => {
|
|
||||||
let migrate_config = parse_migrate_config(cli_args)?;
|
|
||||||
migrate_db(migrate_config, client_config, &context, log).map_err(format_err)
|
migrate_db(migrate_config, client_config, &context, log).map_err(format_err)
|
||||||
}
|
}
|
||||||
Some(("inspect", cli_args)) => {
|
cli::DatabaseManagerSubcommand::Inspect(inspect_config) => {
|
||||||
let inspect_config = parse_inspect_config(cli_args)?;
|
let inspect_config = parse_inspect_config(inspect_config)?;
|
||||||
inspect_db::<E>(inspect_config, client_config)
|
inspect_db::<E>(inspect_config, client_config)
|
||||||
}
|
}
|
||||||
Some(("compact", cli_args)) => {
|
cli::DatabaseManagerSubcommand::Version(_) => {
|
||||||
let compact_config = parse_compact_config(cli_args)?;
|
display_db_version(client_config, &context, log).map_err(format_err)
|
||||||
compact_db::<E>(compact_config, client_config, log).map_err(format_err)
|
|
||||||
}
|
}
|
||||||
Some(("prune-payloads", _)) => {
|
cli::DatabaseManagerSubcommand::PrunePayloads(_) => {
|
||||||
prune_payloads(client_config, &context, log).map_err(format_err)
|
prune_payloads(client_config, &context, log).map_err(format_err)
|
||||||
}
|
}
|
||||||
Some(("prune-blobs", _)) => prune_blobs(client_config, &context, log).map_err(format_err),
|
cli::DatabaseManagerSubcommand::PruneBlobs(_) => {
|
||||||
Some(("prune-states", cli_args)) => {
|
prune_blobs(client_config, &context, log).map_err(format_err)
|
||||||
|
}
|
||||||
|
cli::DatabaseManagerSubcommand::PruneStates(prune_states_config) => {
|
||||||
let executor = env.core_context().executor;
|
let executor = env.core_context().executor;
|
||||||
let network_config = context
|
let network_config = context
|
||||||
.eth2_network_config
|
.eth2_network_config
|
||||||
@@ -722,10 +522,13 @@ pub fn run<E: EthSpec>(cli_args: &ArgMatches, env: Environment<E>) -> Result<(),
|
|||||||
.map_err(|e| format!("Error getting genesis state: {e}"))?
|
.map_err(|e| format!("Error getting genesis state: {e}"))?
|
||||||
.ok_or("Genesis state missing")?;
|
.ok_or("Genesis state missing")?;
|
||||||
|
|
||||||
let prune_config = parse_prune_states_config(cli_args)?;
|
let prune_config = parse_prune_states_config(prune_states_config)?;
|
||||||
|
|
||||||
prune_states(client_config, prune_config, genesis_state, &context, log)
|
prune_states(client_config, prune_config, genesis_state, &context, log)
|
||||||
}
|
}
|
||||||
_ => Err("Unknown subcommand, for help `lighthouse database_manager --help`".into()),
|
cli::DatabaseManagerSubcommand::Compact(compact_config) => {
|
||||||
|
let compact_config = parse_compact_config(compact_config)?;
|
||||||
|
compact_db::<E>(compact_config, client_config, log).map_err(format_err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
9
lighthouse/src/cli.rs
Normal file
9
lighthouse/src/cli.rs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
use clap::Parser;
|
||||||
|
use database_manager::cli::DatabaseManager;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Parser, Clone, Deserialize, Serialize, Debug)]
|
||||||
|
pub enum LighthouseSubcommands {
|
||||||
|
#[clap(name = "database_manager")]
|
||||||
|
DatabaseManager(DatabaseManager),
|
||||||
|
}
|
||||||
@@ -1,10 +1,14 @@
|
|||||||
|
mod cli;
|
||||||
mod metrics;
|
mod metrics;
|
||||||
|
|
||||||
use beacon_node::ProductionBeaconNode;
|
use beacon_node::ProductionBeaconNode;
|
||||||
|
use clap::FromArgMatches;
|
||||||
|
use clap::Subcommand;
|
||||||
use clap::{Arg, ArgAction, ArgMatches, Command};
|
use clap::{Arg, ArgAction, ArgMatches, Command};
|
||||||
use clap_utils::{
|
use clap_utils::{
|
||||||
flags::DISABLE_MALLOC_TUNING_FLAG, get_color_style, get_eth2_network_config, FLAG_HEADER,
|
flags::DISABLE_MALLOC_TUNING_FLAG, get_color_style, get_eth2_network_config, FLAG_HEADER,
|
||||||
};
|
};
|
||||||
|
use cli::LighthouseSubcommands;
|
||||||
use directory::{parse_path_or_default, DEFAULT_BEACON_NODE_DIR, DEFAULT_VALIDATOR_DIR};
|
use directory::{parse_path_or_default, DEFAULT_BEACON_NODE_DIR, DEFAULT_VALIDATOR_DIR};
|
||||||
use environment::{EnvironmentBuilder, LoggerConfig};
|
use environment::{EnvironmentBuilder, LoggerConfig};
|
||||||
use eth2_network_config::{Eth2NetworkConfig, DEFAULT_HARDCODED_NETWORK, HARDCODED_NET_NAMES};
|
use eth2_network_config::{Eth2NetworkConfig, DEFAULT_HARDCODED_NETWORK, HARDCODED_NET_NAMES};
|
||||||
@@ -87,7 +91,7 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse the CLI parameters.
|
// Parse the CLI parameters.
|
||||||
let matches = Command::new("Lighthouse")
|
let cli = Command::new("Lighthouse")
|
||||||
.version(SHORT_VERSION.as_str())
|
.version(SHORT_VERSION.as_str())
|
||||||
.author("Sigma Prime <contact@sigmaprime.io>")
|
.author("Sigma Prime <contact@sigmaprime.io>")
|
||||||
.styles(get_color_style())
|
.styles(get_color_style())
|
||||||
@@ -409,9 +413,11 @@ fn main() {
|
|||||||
.subcommand(boot_node::cli_app())
|
.subcommand(boot_node::cli_app())
|
||||||
.subcommand(validator_client::cli_app())
|
.subcommand(validator_client::cli_app())
|
||||||
.subcommand(account_manager::cli_app())
|
.subcommand(account_manager::cli_app())
|
||||||
.subcommand(database_manager::cli_app())
|
.subcommand(validator_manager::cli_app());
|
||||||
.subcommand(validator_manager::cli_app())
|
|
||||||
.get_matches();
|
let cli = LighthouseSubcommands::augment_subcommands(cli);
|
||||||
|
|
||||||
|
let matches = cli.get_matches();
|
||||||
|
|
||||||
// Configure the allocator early in the process, before it has the chance to use the default values for
|
// Configure the allocator early in the process, before it has the chance to use the default values for
|
||||||
// anything important.
|
// anything important.
|
||||||
@@ -676,14 +682,13 @@ fn run<E: EthSpec>(
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(sub_matches) = matches.subcommand_matches(database_manager::CMD) {
|
if let Ok(LighthouseSubcommands::DatabaseManager(db_manager_config)) =
|
||||||
|
LighthouseSubcommands::from_arg_matches(matches)
|
||||||
|
{
|
||||||
info!(log, "Running database manager for {} network", network_name);
|
info!(log, "Running database manager for {} network", network_name);
|
||||||
// Pass the entire `environment` to the database manager so it can run blocking operations.
|
database_manager::run(matches, &db_manager_config, environment)?;
|
||||||
database_manager::run(sub_matches, environment)?;
|
|
||||||
|
|
||||||
// Exit as soon as database manager returns control.
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
};
|
||||||
|
|
||||||
info!(log, "Lighthouse started"; "version" => VERSION);
|
info!(log, "Lighthouse started"; "version" => VERSION);
|
||||||
info!(
|
info!(
|
||||||
|
|||||||
Reference in New Issue
Block a user