Skip to content

Commit e32de67

Browse files
authored
[replay-2] Make progress during replay of a digests file nicer (#24515)
## Description Make the output when replaying a digests file much nicer. ## Test plan Ran it locally. --- ## Release notes Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required. For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates. - [ ] Protocol: - [ ] Nodes (Validators and Full nodes): - [ ] gRPC: - [ ] JSON-RPC: - [ ] GraphQL: - [ ] CLI: - [ ] Rust SDK: - [ ] Indexing Framework:
1 parent 1baebbb commit e32de67

File tree

4 files changed

+33
-16
lines changed

4 files changed

+33
-16
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/sui-replay-2/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ tokio = { workspace = true, features = ["full"] }
4545
toml.workspace = true
4646
tracing.workspace = true
4747
zstd.workspace = true
48+
indicatif.workspace = true
4849

4950
[features]
5051
tracing = [

crates/sui-replay-2/src/lib.rs

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ use crate::{
99
};
1010
use anyhow::{Result, anyhow, bail};
1111
use clap::{Parser, ValueEnum};
12+
use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
1213
use serde::Deserialize;
1314
use similar::{ChangeTag, TextDiff};
1415
use std::{
1516
fs,
1617
io::Write,
1718
path::{Path, PathBuf},
19+
time::Duration,
1820
};
1921
use sui_config::sui_config_dir;
2022
use sui_data_store::{
@@ -24,7 +26,7 @@ use sui_data_store::{
2426
use sui_json_rpc_types::SuiTransactionBlockEffects;
2527
use sui_types::effects::TransactionEffects;
2628
// Disambiguate external tracing crate from local `crate::tracing` module using absolute path.
27-
use ::tracing::{Instrument, debug, error, info, info_span, warn};
29+
use ::tracing::{Instrument, debug, error, info_span, warn};
2830

2931
pub mod artifacts;
3032
pub mod displays;
@@ -505,11 +507,20 @@ where
505507
let mut total_metrics = TotalMetrics::new();
506508
let mut executor_provider = ExecutorProvider::new(cache_executor);
507509

510+
let mp = MultiProgress::new();
511+
let tx_spinner = mp.add(ProgressBar::new_spinner());
512+
let progress_bar = mp.add(ProgressBar::new(digests.len() as u64));
513+
514+
tx_spinner.set_style(ProgressStyle::with_template("{spinner}: {msg}").unwrap());
515+
tx_spinner.enable_steady_tick(Duration::from_millis(80));
516+
508517
for tx_digest in digests {
509518
let tx_dir = output_root_dir.join(tx_digest);
510519
let artifact_manager = ArtifactManager::new(&tx_dir, overwrite_existing)?;
511520
let span = info_span!("replay", tx_digest = %tx_digest);
512521

522+
tx_spinner.set_message(format!("Executing transaction {}", tx_digest));
523+
513524
let tx_start = Instant::now();
514525
let result = replay_transaction(
515526
&artifact_manager,
@@ -530,14 +541,17 @@ where
530541

531542
// Print per-transaction result
532543
let status = if success { "OK" } else { "FAILED" };
533-
if track_time {
534-
println!(
535-
"> Replayed txn {} ({}): exec_ms={}, total_ms={}",
536-
tx_digest, status, exec_ms, tx_total_ms
537-
);
544+
545+
let time_info = if track_time {
546+
format!(
547+
" ({}): exec_ms={}, total_ms={}",
548+
status, exec_ms, tx_total_ms
549+
)
538550
} else {
539-
println!("> Replayed txn {} ({})", tx_digest, status);
540-
}
551+
"".to_owned()
552+
};
553+
554+
tx_spinner.println(format!("Executed transaction {}{}", tx_digest, time_info));
541555

542556
match result {
543557
Err(e) if terminate_early => {
@@ -547,12 +561,13 @@ where
547561
Err(e) => {
548562
error!(tx_digest = %tx_digest, error = ?e, "Replay failed");
549563
}
550-
Ok(_) => {
551-
info!(tx_digest = %tx_digest, "Replay succeeded");
552-
}
564+
Ok(_) => {}
553565
}
566+
progress_bar.inc(1);
554567
}
555568

569+
tx_spinner.finish_and_clear();
570+
556571
if verbose {
557572
let mut out = std::io::stdout().lock();
558573
let _ = writeln!(out, "\nData store summary:");

crates/sui-replay-2/src/replay_txn.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use sui_types::{
3939
gas::SuiGasStatusAPI,
4040
transaction::{InputObjectKind, ObjectReadResult, ObjectReadResultKind},
4141
};
42-
use tracing::{debug, error, info, info_span, trace};
42+
use tracing::{debug, error, info_span, trace, warn};
4343

4444
pub type ObjectVersion = u64;
4545
pub type PackageVersion = u64;
@@ -148,7 +148,7 @@ pub(crate) async fn replay_transaction<S: ReadDataStore>(
148148
}
149149

150150
// Save results
151-
info!(
151+
debug!(
152152
tx_digest = %tx_digest,
153153
result = ?result,
154154
output_dir = %artifact_manager.base_path.display(),
@@ -191,15 +191,15 @@ pub(crate) async fn replay_transaction<S: ReadDataStore>(
191191
if let sui_types::transaction::TransactionKind::ProgrammableTransaction(ptb) =
192192
context_and_effects.txn_data.kind()
193193
{
194-
info!(tx_digest = %tx_digest, "Extracting move call info for {} commands", ptb.commands.len());
194+
debug!(tx_digest = %tx_digest, "Extracting move call info for {} commands", ptb.commands.len());
195195
match MoveCallInfo::from_transaction(ptb, &context_and_effects.object_cache) {
196196
Ok(move_call_info) => {
197197
let successful_extractions = move_call_info
198198
.command_signatures
199199
.iter()
200200
.filter(|s| s.is_some())
201201
.count();
202-
info!(tx_digest = %tx_digest, "Successfully extracted {} function signatures out of {} commands",
202+
debug!(tx_digest = %tx_digest, "Successfully extracted {} function signatures out of {} commands",
203203
successful_extractions, move_call_info.command_signatures.len());
204204

205205
artifact_manager
@@ -209,7 +209,7 @@ pub(crate) async fn replay_transaction<S: ReadDataStore>(
209209
.unwrap();
210210
}
211211
Err(e) => {
212-
info!(tx_digest = %tx_digest, "Failed to extract move call info: {}", e);
212+
warn!(tx_digest = %tx_digest, "Failed to extract move call info: {}", e);
213213
}
214214
}
215215
}

0 commit comments

Comments
 (0)