Skip to content

Commit

Permalink
ledger-tool: Remove duplicate slot output code (solana-labs#1255)
Browse files Browse the repository at this point in the history
This makes the slot subcommand use the same output method as bigtable
block to output blocks (-vv). Doing so creates consistency between the
two commands as well as removing a duplicate implementation in the
ledger-tool code. The shared type also supports json output which the
ledger-tool implementation did not.
  • Loading branch information
steviez authored May 15, 2024
1 parent e86ab5a commit bd09ba6
Show file tree
Hide file tree
Showing 7 changed files with 194 additions and 234 deletions.
2 changes: 1 addition & 1 deletion ledger-tool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ solana-cost-model = { workspace = true }
solana-entry = { workspace = true }
solana-geyser-plugin-manager = { workspace = true }
solana-gossip = { workspace = true }
solana-ledger = { workspace = true }
solana-ledger = { workspace = true, features = ["dev-context-only-utils"] }
solana-logger = { workspace = true }
solana-measure = { workspace = true }
solana-program-runtime = { workspace = true }
Expand Down
26 changes: 6 additions & 20 deletions ledger-tool/src/bigtable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
use {
crate::{
ledger_path::canonicalize_ledger_path,
output::{CliBlockWithEntries, CliEntries, EncodedConfirmedBlockWithEntries},
output::{
encode_confirmed_block, CliBlockWithEntries, CliEntries,
EncodedConfirmedBlockWithEntries,
},
},
clap::{
value_t, value_t_or_exit, values_t_or_exit, App, AppSettings, Arg, ArgMatches, SubCommand,
Expand All @@ -25,10 +28,7 @@ use {
},
solana_sdk::{clock::Slot, pubkey::Pubkey, signature::Signature},
solana_storage_bigtable::CredentialType,
solana_transaction_status::{
BlockEncodingOptions, ConfirmedBlock, EncodeError, EncodedConfirmedBlock,
TransactionDetails, UiTransactionEncoding, VersionedConfirmedBlock,
},
solana_transaction_status::{ConfirmedBlock, UiTransactionEncoding, VersionedConfirmedBlock},
std::{
cmp::min,
collections::HashSet,
Expand Down Expand Up @@ -124,21 +124,7 @@ async fn block(
.map_err(|err| format!("Failed to connect to storage: {err:?}"))?;

let confirmed_block = bigtable.get_confirmed_block(slot).await?;
let encoded_block = confirmed_block
.encode_with_options(
UiTransactionEncoding::Base64,
BlockEncodingOptions {
transaction_details: TransactionDetails::Full,
show_rewards: true,
max_supported_transaction_version: Some(0),
},
)
.map_err(|err| match err {
EncodeError::UnsupportedTransactionVersion(version) => {
format!("Failed to process unsupported transaction version ({version}) in block")
}
})?;
let encoded_block: EncodedConfirmedBlock = encoded_block.into();
let encoded_block = encode_confirmed_block(confirmed_block)?;

if show_entries {
let entries = bigtable.get_entries(slot).await?;
Expand Down
12 changes: 6 additions & 6 deletions ledger-tool/src/blockstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ fn do_blockstore_process_command(ledger_path: &Path, matches: &ArgMatches<'_>) -
num_slots,
verbose_level,
only_rooted,
);
)?;
}
("print-file-metadata", Some(arg_matches)) => {
let blockstore =
Expand Down Expand Up @@ -1019,20 +1019,20 @@ fn do_blockstore_process_command(ledger_path: &Path, matches: &ArgMatches<'_>) -
("slot", Some(arg_matches)) => {
let slots = values_t_or_exit!(arg_matches, "slots", Slot);
let allow_dead_slots = arg_matches.is_present("allow_dead_slots");
let output_format = OutputFormat::from_matches(arg_matches, "output_format", false);

let blockstore =
crate::open_blockstore(&ledger_path, arg_matches, AccessType::Secondary);
for slot in slots {
println!("Slot {slot}");
if let Err(err) = output_slot(
output_slot(
&blockstore,
slot,
allow_dead_slots,
&OutputFormat::Display,
&output_format,
verbose_level,
&mut HashMap::new(),
) {
eprintln!("{err}");
}
)?;
}
}
_ => unreachable!(),
Expand Down
6 changes: 6 additions & 0 deletions ledger-tool/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@ pub enum LedgerToolError {
#[error("{0}")]
SerdeJson(#[from] serde_json::Error),

#[error("{0}")]
TransactionEncode(#[from] solana_transaction_status::EncodeError),

#[error("{0}")]
Io(#[from] std::io::Error),

#[error("{0}")]
Generic(String),

#[error("{0}")]
BadArgument(String),
}
Loading

0 comments on commit bd09ba6

Please sign in to comment.