Skip to content
Closed
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
14 changes: 14 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ bincode = "1"
bitvec = "1"
byteorder = "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
# feature ourselves when desired.
c-kzg = { version = "1", default-features = false }
Expand Down
11 changes: 6 additions & 5 deletions beacon_node/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,10 @@ pub fn get_config<E: EthSpec>(
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_set_explicitly = sprp_explicit;

Expand Down Expand Up @@ -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.
pub fn get_slots_per_restore_point<E: EthSpec>(
cli_args: &ArgMatches,
slots_per_restore_point: Option<u64>,
) -> Result<(u64, bool), String> {
if let Some(slots_per_restore_point) =
clap_utils::parse_optional(cli_args, "slots-per-restore-point")?
{
if let Some(slots_per_restore_point) = slots_per_restore_point {
Ok((slots_per_restore_point, true))
} else {
let default = std::cmp::min(
Expand Down
2 changes: 1 addition & 1 deletion book/src/help_general.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Commands:
is the recommended way to provide a network boot-node since it has a
reduced attack surface compared to a full beacon node.
database_manager
Manage a beacon node database [aliases: db]
Manage a beacon node database. [aliases: db]
validator_client
When connected to a beacon node, performs the duties of a staked
validator (e.g., proposing blocks and attestations). [aliases: v, vc,
Expand Down
1 change: 1 addition & 0 deletions database_manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ store = { workspace = true }
types = { workspace = true }
slog = { workspace = true }
strum = { workspace = true }
serde = { workspace = true }
257 changes: 257 additions & 0 deletions database_manager/src/cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,257 @@
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;

#[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, 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),
Edit(Edit),
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,

// TODO InspectTarget::VARIANTS
#[clap(
long,
value_name = "TARGET",
default_value_t = String::from("sizes"),
help = "Select the type of output to show",
display_order = 0,
)]
pub output: String,

#[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 = "Edit raw database values.")]
pub struct Edit {
#[clap(
long,
value_name = "TAG",
help = "3-byte column ID (see `DBColumn`)",
display_order = 0
)]
pub column: String,

#[clap(long, value_name = "HEX", help = "Key to write", display_order = 0)]
pub key: String,

#[clap(long, value_name = "PATH", help = "Value to write", display_order = 0)]
pub value: PathBuf,

#[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,
}

#[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>,
}
Loading