Skip to content

Commit

Permalink
Merge refs/heads/master into decouple/jsonrpc/remove-actix
Browse files Browse the repository at this point in the history
  • Loading branch information
near-bulldozer[bot] authored May 30, 2022
2 parents 3ed3fa3 + 9e3c4db commit 671f70f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 11 deletions.
7 changes: 4 additions & 3 deletions tools/state-viewer/src/apply_chain_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ fn apply_block_from_range(
maybe_add_to_csv(
csv_file_mutex,
&format!(
"{},{},{},{},{},{},{},{},{},{}",
"{},{},{},{},{},{},{},{},{},{},{}",
height,
block_hash,
block_author,
Expand All @@ -319,7 +319,8 @@ fn apply_block_from_range(
apply_result.total_gas_burnt,
chunk_present,
apply_result.processed_delayed_receipts.len(),
delayed_indices.map_or(0, |d| d.next_available_index - d.first_index)
delayed_indices.map_or(0, |d| d.next_available_index - d.first_index),
apply_result.trie_changes.state_changes().len(),
),
);
progress_reporter.inc_and_report_progress(apply_result.total_gas_burnt);
Expand Down Expand Up @@ -358,7 +359,7 @@ pub fn apply_chain_range(

println!("Printing results including outcomes of applying receipts");
let csv_file_mutex = Arc::new(Mutex::new(csv_file));
maybe_add_to_csv(&csv_file_mutex, "Height,Hash,Author,#Tx,#Receipt,Timestamp,GasUsed,ChunkPresent,#ProcessedDelayedReceipts,#DelayedReceipts");
maybe_add_to_csv(&csv_file_mutex, "Height,Hash,Author,#Tx,#Receipt,Timestamp,GasUsed,ChunkPresent,#ProcessedDelayedReceipts,#DelayedReceipts,#StateChanges");

let range = start_height..=end_height;
let progress_reporter = ProgressReporter {
Expand Down
13 changes: 12 additions & 1 deletion tools/state-viewer/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,22 @@ pub struct ChainCmd {
start_index: BlockHeight,
#[clap(long)]
end_index: BlockHeight,
// If true, show the full hash (block hash and chunk hash) when printing.
// If false, show only first couple chars.
#[clap(long)]
show_full_hashes: bool,
}

impl ChainCmd {
pub fn run(self, home_dir: &Path, near_config: NearConfig, store: Store) {
print_chain(self.start_index, self.end_index, home_dir, near_config, store);
print_chain(
self.start_index,
self.end_index,
home_dir,
near_config,
store,
self.show_full_hashes,
);
}
}

Expand Down
23 changes: 16 additions & 7 deletions tools/state-viewer/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ pub(crate) fn print_chain(
home_dir: &Path,
near_config: NearConfig,
store: Store,
show_full_hashes: bool,
) {
let chain_store = ChainStore::new(
store.clone(),
Expand All @@ -235,7 +236,11 @@ pub(crate) fn print_chain(
if let Ok(block_hash) = chain_store.get_block_hash_by_height(height) {
let header = chain_store.get_block_header(&block_hash).unwrap().clone();
if height == 0 {
println!("{: >3} {}", header.height(), format_hash(*header.hash()));
println!(
"{: >3} {}",
header.height(),
format_hash(*header.hash(), show_full_hashes)
);
} else {
let parent_header =
chain_store.get_block_header(header.prev_hash()).unwrap().clone();
Expand All @@ -246,7 +251,7 @@ pub(crate) fn print_chain(
account_id_to_blocks = HashMap::new();
println!(
"Epoch {} Validators {:?}",
format_hash(epoch_id.0),
format_hash(epoch_id.0, show_full_hashes),
runtime
.get_epoch_block_producers_ordered(&epoch_id, header.hash())
.unwrap()
Expand All @@ -272,7 +277,7 @@ pub(crate) fn print_chain(
chunk_debug_str.push(format!(
"{}: {} {: >3} Tgas ",
shard_id,
format_hash(chunk.chunk_hash().0),
format_hash(chunk.chunk_hash().0, show_full_hashes),
chunk.cloned_header().gas_used() / (1024 * 1024 * 1024 * 1024)
));
}
Expand All @@ -281,10 +286,10 @@ pub(crate) fn print_chain(
println!(
"{: >3} {} | {: >10} | parent: {: >3} {} | {} {}",
header.height(),
format_hash(*header.hash()),
format_hash(*header.hash(), show_full_hashes),
block_producer,
parent_header.height(),
format_hash(*parent_header.hash()),
format_hash(*parent_header.hash(), show_full_hashes),
chunk_mask_to_str(header.chunk_mask()),
chunk_debug_str.join("|")
);
Expand Down Expand Up @@ -728,8 +733,12 @@ fn load_trie_stop_at_height(
(runtime, state_roots, last_block.header().clone())
}

pub fn format_hash(h: CryptoHash) -> String {
to_base(&h)[..7].to_string()
pub fn format_hash(h: CryptoHash, show_full_hashes: bool) -> String {
if show_full_hashes {
to_base(&h).to_string()
} else {
to_base(&h)[..7].to_string()
}
}

pub fn chunk_mask_to_str(mask: &[bool]) -> String {
Expand Down

0 comments on commit 671f70f

Please sign in to comment.