Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ledger-tool: Move blockstore commands to blockstore subcommand #34597

Merged
merged 20 commits into from
Jan 10, 2024

Conversation

steviez
Copy link
Contributor

@steviez steviez commented Dec 27, 2023

Problem

solana-ledger-tool is a bit of a kitchen sink, and has upwards of 30 commands at the top level (ie 30 commands that can be invoked via solana-ledger-tool <SOME_COMMAND>). UI Aside, the contents of ledger-tool/src/main.rs are somewhat cluttered.

Summary of Changes

To reduce the clutter, this PR:

  • Introduces a new blockstore subcommand, and moves all commands that only operate on the blockstore to this new subcommand.
    • As an example, solana-ledger-tool slot is now solana-ledger-tool blockstore slot
  • Supports the old command style (solana-ledger-tool slot), but does not display those commands in the top level --help command.
    • This steers new users towards using new calling format while avoiding breaking the old calling format for people who have muscle memory with those commands

With this PR, here is the subcommand section of the output for running solana-ledger-tool help:

USAGE:
    solana-ledger-tool [FLAGS] [OPTIONS] <SUBCOMMAND>
...
SUBCOMMANDS:
    accounts                   Print account stats and contents after processing the ledger
    bank-hash                  Prints the hash of the working bank after reading the ledger
    bigtable                   Ledger data on a BigTable instance
    blockstore                 Commands to interact with a local Blockstore
    capitalization             Print capitalization (aka, total supply) while checksumming it
    compute-slot-cost          runs cost_model over the block at the given slots, computes how expensive a block was
                               based on cost_model
    create-snapshot            Create a new ledger snapshot
    genesis                    Prints the ledger's genesis config
    genesis-hash               Prints the ledger's genesis hash
    graph                      Create a Graphviz rendering of the ledger
    help                       Prints this message or the help of the given subcommand(s)
    latest-optimistic-slots    Output up to the most recent <num-slots> optimistic slots with their hashes and
                               timestamps.
    modify-genesis             Modifies genesis parameters
    program                    Run to test, debug, and analyze on-chain programs.
    shred-version              Prints the ledger's shred hash
    verify                     Verify the ledger

And here is solana-ledger-tool blockstore:

USAGE:
    solana-ledger-tool blockstore [FLAGS] [OPTIONS] <SUBCOMMAND>
...    
SUBCOMMANDS:
    analyze-storage            Output statistics in JSON format about all column families in the ledger rocksdb
    bounds                     Print lowest and highest non-empty slots. Note that there may be empty slots within
                               the bounds
    copy                       Copy the ledger
    dead-slots                 Print all the dead slots in the ledger
    duplicate-slots            Print all the duplicate slots in the ledger
    help                       Prints this message or the help of the given subcommand(s)
    json                       Print the ledger in JSON format
    latest-optimistic-slots    Output up to the most recent <num-slots> optimistic slots with their hashes and
                               timestamps.
    list-roots                 Output up to last <num-roots> root hashes and their heights starting at the given
                               block height
    parse_full_frozen          Parses log for information about critical events about ancestors of the given
                               `ending_slot`
    print                      Print the ledger
    print-file-metadata        Print the metadata of the specified ledger-store file. If no file name is specified,
                               it will print the metadata of all ledger files.
    purge                      Delete a range of slots from the ledger
    remove-dead-slot           Remove the dead flag for a slot
    repair-roots               Traverses the AncestorIterator backward from a last known root to restore missing
                               roots to the Root column
    set-dead-slot              Mark one or more slots dead
    shred-meta                 Prints raw shred metadata
    slot                       Print the contents of one or more slots

Pre-requisite PRs

In order to reduce the noise in this PR, several items that I changed while working on this have been broken out. All below PR's should be merged and this PR rebased on top before it is ready to merge.

@steviez steviez added the noCI Suppress CI on this Pull Request label Dec 27, 2023
@steviez steviez removed the noCI Suppress CI on this Pull Request label Jan 3, 2024
@steviez steviez force-pushed the lt_x_bstore_subcommand branch 2 times, most recently from 1cf2c02 to bae1793 Compare January 3, 2024 22:39
@steviez steviez added the noCI Suppress CI on this Pull Request label Jan 3, 2024
Copy link

codecov bot commented Jan 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (744c2cb) 81.8% compared to head (a4eba32) 81.8%.

Additional details and impacted files
@@            Coverage Diff            @@
##           master   #34597     +/-   ##
=========================================
- Coverage    81.8%    81.8%   -0.1%     
=========================================
  Files         824      824             
  Lines      222393   222393             
=========================================
- Hits       181984   181924     -60     
- Misses      40409    40469     +60     

@steviez steviez changed the title ledger-tool: Move blockstore command to blockstore subcommand ledger-tool: Move blockstore commands to blockstore subcommand Jan 4, 2024
@steviez steviez removed the noCI Suppress CI on this Pull Request label Jan 4, 2024
@steviez
Copy link
Contributor Author

steviez commented Jan 4, 2024

Ok, I think I have pulled out everything that I can to shrink this PR. That being said, still a pretty decent line count. But, I think commits are broken up pretty well such that review shouldn't be too insane. Let me know if this is not the case @CriesofCarrots and we can brainstorm on how to break this up even further.

I spot-checked a few items, ie that the following two calls both work:

$ cargo run -- bounds --ledger ./
$ cargo run -- blockstore bounds --ledger ./

I had previously spot-checked every command, but will probably do that again tomorrow just incase. It could be nice to have a unit-test, but that would seemingly entail

  1. Moving the App creation and its' args into a subfunction AND
  2. Repeating some of the lists of all the subcommand that should show up in both places
    let matches = App::new(crate_name!())

So, I'm initially leaning towards no unit test, but open to discussion

@steviez steviez marked this pull request as ready for review January 4, 2024 05:37
Copy link
Contributor

@CriesofCarrots CriesofCarrots left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! I diffed almost all the move blocks and didn't come up with anything to comment on :)

Comment on lines +297 to +311
let starting_slot_arg = Arg::with_name("starting_slot")
.long("starting-slot")
.value_name("SLOT")
.takes_value(true)
.default_value("0")
.help("Start at this slot");
let ending_slot_arg = Arg::with_name("ending_slot")
.long("ending-slot")
.value_name("SLOT")
.takes_value(true)
.help("The last slot to iterate to");
let allow_dead_slots_arg = Arg::with_name("allow_dead_slots")
.long("allow-dead-slots")
.takes_value(false)
.help("Output dead slots as well");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we/should we dedupe these with the existing definitions in main.rs at some point?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah definitely; it is not expressed here, but I loosely allude to wanting to do some reorganization on that front in the problem descriptions for #34694 (a PR I have yet to add you too 😉).

The goals there would be deduping argument definitions (there were a few dupes prior to my changes here), and also creating several groupings of arguments. The groupings could be added to subcommands via this function to avoid long repeated lists like this for the [verify, create-snapshot, graph, ...] commands:

solana/ledger-tool/src/main.rs

Lines 1368 to 1392 in 8438544

.arg(&no_snapshot_arg)
.arg(&account_paths_arg)
.arg(&accounts_hash_cache_path_arg)
.arg(&accounts_index_path_arg)
.arg(&halt_at_slot_arg)
.arg(&limit_load_slot_count_from_snapshot_arg)
.arg(&accounts_index_bins)
.arg(&accounts_index_limit)
.arg(&disable_disk_index)
.arg(&accountsdb_skip_shrink)
.arg(&accountsdb_verify_refcounts)
.arg(&accounts_db_test_skip_rewrites_but_include_in_bank_hash)
.arg(&verify_index_arg)
.arg(&accounts_db_skip_initial_hash_calc_arg)
.arg(&ancient_append_vecs)
.arg(&halt_at_slot_store_hash_raw_data)
.arg(&hard_forks_arg)
.arg(&accounts_db_test_hash_calculation_arg)
.arg(&os_memory_stats_reporting_arg)
.arg(&allow_dead_slots_arg)
.arg(&max_genesis_archive_unpacked_size_arg)
.arg(&debug_key_arg)
.arg(&geyser_plugin_args)
.arg(&use_snapshot_archives_at_startup)
.arg(

@steviez steviez merged commit 7ee9d9a into solana-labs:master Jan 10, 2024
35 checks passed
@steviez steviez deleted the lt_x_bstore_subcommand branch January 10, 2024 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants