Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
nikurt committed Mar 27, 2023
1 parent ddce6e6 commit 9dfc745
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions tools/state-viewer/src/state_parts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use std::fs::DirEntry;
use std::ops::Range;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::sync::Arc;
use std::time::Instant;

#[derive(clap::Subcommand, Debug, Clone)]
Expand Down Expand Up @@ -69,11 +68,10 @@ impl StatePartsSubCommand {
near_config: NearConfig,
store: Store,
) {
let runtime =
Arc::new(NightshadeRuntime::from_config(home_dir, store.clone(), &near_config));
let runtime = NightshadeRuntime::from_config(home_dir, store.clone(), &near_config);
let chain_genesis = ChainGenesis::new(&near_config.genesis);
let mut chain = Chain::new_for_view_client(
runtime,
runtime.clone(),
&chain_genesis,
DoomslugThresholdMode::TwoThirds,
false,
Expand Down Expand Up @@ -344,10 +342,23 @@ fn dump_state_parts(
.runtime_adapter
.obtain_state_part(shard_id, &sync_hash, &state_root, PartId::new(part_id, num_parts))
.unwrap();
let (first_sr, last_sr) = analyze_state_part(&state_root, &state_part);
tracing::info!(target: "state-parts", part_id, ?first_sr, ?last_sr);
part_storage.write(&state_part, part_id, num_parts);
tracing::info!(target: "state-parts", part_id, part_length = state_part.len(), elapsed_sec = timer.elapsed().as_secs_f64(), "Wrote a state part");
let elapsed_sec = timer.elapsed().as_secs_f64();
let (first_sr, last_sr) = analyze_state_part(&state_root, &state_part);
let (first_sr, first_sr_key_len) =
first_sr.map_or((None, None), |sr| (Some(sr.0), Some(sr.1)));
let (last_sr, last_sr_key_len) =
last_sr.map_or((None, None), |sr| (Some(sr.0), Some(sr.1)));
tracing::info!(
target: "state-parts",
part_id,
part_length = state_part.len(),
elapsed_sec,
?first_sr,
?first_sr_key_len,
?last_sr,
?last_sr_key_len,
"Wrote a state part");
}
tracing::info!(target: "state-parts", total_elapsed_sec = timer.elapsed().as_secs_f64(), "Wrote all requested state parts");
}
Expand All @@ -356,19 +367,20 @@ fn dump_state_parts(
fn analyze_state_part(
state_root: &StateRoot,
data: &[u8],
) -> (Option<StateRecord>, Option<StateRecord>) {
) -> (Option<(StateRecord, usize)>, Option<(StateRecord, usize)>) {
let trie_nodes = BorshDeserialize::try_from_slice(data).unwrap();
let trie = Trie::from_recorded_storage(PartialStorage { nodes: trie_nodes }, *state_root);

let mut first_sr = None;
let mut last_sr = None;
for item in trie.iter().unwrap() {
if let Ok((key, value)) = item {
let key_len = key.len();
if let Some(sr) = StateRecord::from_raw_key_value(key, value) {
if first_sr.is_none() {
first_sr = Some(sr);
first_sr = Some((sr, key_len));
} else {
last_sr = Some(sr);
last_sr = Some((sr, key_len));
}
}
}
Expand Down

0 comments on commit 9dfc745

Please sign in to comment.