Skip to content

Commit

Permalink
Output current checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
lbeder committed Nov 16, 2024
1 parent 32248c3 commit 00a38fe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ SlowKey Parameters:
████████████████████████████████████████████████████████████████░░░░░░░░░░░░░░░░ 5/10 80% (10s)
Current checkpoint: 1/2
Created checkpoint #5 with data hash 0x3c0c7ab8bb2001c1efd67ce049a437c760cf95d4cc2967160b708fb7216d74d1
```
Expand Down
14 changes: 9 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,14 +542,14 @@ fn main() {

pb.enable_steady_tick(Duration::from_secs(1));

let checkpoint_count = ((slowkey_opts.iterations - offset) / checkpointing_interval) as u64;
let mut current_checkpoint = 0;
let mut cpb: Option<ProgressBar> = None;

if checkpoint.is_some() && checkpointing_interval != 0 {
cpb = Some(
mb.add(ProgressBar::new(
((slowkey_opts.iterations - offset) / checkpointing_interval) as u64,
))
.with_style(ProgressStyle::with_template("{msg}").unwrap()),
mb.add(ProgressBar::new(checkpoint_count))
.with_style(ProgressStyle::with_template("{msg}").unwrap()),
);

if let Some(ref mut cpb) = &mut cpb {
Expand All @@ -575,6 +575,8 @@ fn main() {

// Create a checkpoint if we've reached the checkpoint interval
if checkpointing_interval != 0 && (current_iteration + 1) % checkpointing_interval == 0 {
current_checkpoint += 1;

let prev_data: Option<&[u8]> = if current_iteration == 0 { None } else { Some(&prev_data) };

if let Some(checkpoint) = &mut checkpoint {
Expand All @@ -585,7 +587,9 @@ fn main() {
let hash = Checkpoint::hash_checkpoint(current_iteration, current_data, prev_data);

cpb.set_message(format!(
"\nCreated checkpoint #{} with data hash {}",
"\nCurrent checkpoint: {}/{}\nCreated checkpoint #{} with data hash {}",
current_checkpoint,
checkpoint_count,
(current_iteration + 1).to_string().cyan(),
format!("0x{}", hex::encode(hash)).cyan()
));
Expand Down

0 comments on commit 00a38fe

Please sign in to comment.