agave_validator/commands/blockstore/
mod.rs1use {
2 crate::{
3 admin_rpc_service,
4 commands::{FromClapArgMatches, Result},
5 },
6 clap::{App, AppSettings, Arg, ArgMatches, SubCommand, value_t},
7 solana_clap_utils::input_validators::is_parsable,
8 solana_clock::Slot,
9 std::path::Path,
10};
11
12const COMMAND: &str = "blockstore";
13
14#[derive(Debug, PartialEq)]
15#[cfg_attr(test, derive(Default))]
16pub struct BlockstorePurgeArgs {
17 pub maximum_purge_slot: Slot,
18}
19
20impl FromClapArgMatches for BlockstorePurgeArgs {
21 fn from_clap_arg_match(matches: &ArgMatches) -> Result<Self> {
22 Ok(BlockstorePurgeArgs {
23 maximum_purge_slot: value_t!(matches, "maximum_purge_slot", Slot)?,
24 })
25 }
26}
27
28pub fn command<'a>() -> App<'a, 'a> {
29 SubCommand::with_name(COMMAND)
30 .about("Interact with the validator's Blockstore")
31 .setting(AppSettings::SubcommandRequiredElseHelp)
32 .setting(AppSettings::InferSubcommands)
33 .setting(AppSettings::Hidden)
34 .subcommand(
35 SubCommand::with_name("purge")
36 .about("Delete blocks from the Blockstore")
37 .arg(
38 Arg::with_name("maximum_purge_slot")
39 .long("maximum-purge-slot")
40 .value_name("MAXIMUM_PURGE_SLOT")
41 .index(1)
42 .takes_value(true)
43 .required(true)
44 .validator(is_parsable::<Slot>)
45 .help(
46 "The maximum slot to purge from the Blockstore. All slots up to and \
47 including MAXIMUM_PURGE_SLOT will be purged",
48 ),
49 ),
50 )
51}
52
53pub fn execute(matches: &ArgMatches, ledger_path: &Path) -> Result<()> {
54 match matches.subcommand() {
55 ("purge", Some(subcommand_matches)) => {
56 let BlockstorePurgeArgs { maximum_purge_slot } =
57 BlockstorePurgeArgs::from_clap_arg_match(subcommand_matches)?;
58
59 let admin_client = admin_rpc_service::connect(ledger_path);
60 admin_rpc_service::runtime().block_on(async move {
61 admin_client
62 .await?
63 .blockstore_purge(maximum_purge_slot)
64 .await
65 })?;
66 }
67 _ => unreachable!(),
68 }
69
70 Ok(())
71}