Skip to content

Commit

Permalink
Clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
iamyulong committed Oct 12, 2023
1 parent fbe5aa8 commit 2d24dba
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion simulator/src/replay/cmd_prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl Prepare {
header.set_cksum();
tar.append(&header, payload.as_slice()).unwrap();

// bump version and print progress
// print progress
if version < 1000 || version % 1000 == 0 {
println!("New version: {}", version);
}
Expand Down
14 changes: 13 additions & 1 deletion simulator/src/replay/cmd_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use radix_engine_stores::rocks_db_with_merkle_tree::RocksDBWithMerkleTreeSubstat
use std::fs::File;
use std::io::Read;
use std::path::PathBuf;
use std::time::Duration;
use tar::Archive;
use transaction::validation::{
NotarizedTransactionValidator, TransactionValidator, ValidationConfig,
Expand Down Expand Up @@ -77,7 +78,8 @@ impl Run {
let new_version = database.get_current_version();
if new_version < 1000 || new_version % 1000 == 0 {
let new_root = database.get_current_root_hash();
println!("New version: {}, {}", new_version, new_root);
let duration = start.elapsed();
print_progress(duration, new_version, new_root);
}
}
let duration = start.elapsed();
Expand All @@ -89,6 +91,16 @@ impl Run {
}
}

pub fn print_progress(duration: Duration, new_version: u64, new_root: Hash) {
let seconds = duration.as_secs() % 60;
let minutes = (duration.as_secs() / 60) % 60;
let hours = (duration.as_secs() / 60) / 60;
println!(
"New version: {}, {}, {:0>2}:{:0>2}:{:0>2}",
new_version, new_root, hours, minutes, seconds
);
}

pub fn decompress_entry(mut entry: tar::Entry<GzDecoder<File>>) -> Option<(u64, Vec<u8>)> {
let tx_version = entry
.header()
Expand Down
4 changes: 3 additions & 1 deletion simulator/src/replay/cmd_run_in_memory.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::replay::decompress_entry;
use crate::replay::execute_ledger_transaction;
use crate::replay::print_progress;
use crate::replay::Error;
use clap::Parser;
use flate2::read::GzDecoder;
Expand Down Expand Up @@ -69,7 +70,8 @@ impl RunInMemory {
let new_version = database.get_current_version();
if new_version < 1000 || new_version % 1000 == 0 {
let new_root = database.get_current_root_hash();
println!("New version: {}, {}", new_version, new_root);
let duration = start.elapsed();
print_progress(duration, new_version, new_root);
}
}
let duration = start.elapsed();
Expand Down

0 comments on commit 2d24dba

Please sign in to comment.