Skip to content

Commit

Permalink
feat: show rescan progress
Browse files Browse the repository at this point in the history
  • Loading branch information
michael1011 committed Jun 29, 2024
1 parent c33b828 commit bb63153
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/claimer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use rayon::iter::IntoParallelRefIterator;
use rayon::iter::ParallelIterator;
use std::cmp;
use std::error::Error;
use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::Arc;
use tokio::runtime::Builder;

Expand Down Expand Up @@ -131,7 +132,7 @@ impl Claimer {
let block_range: Vec<u64> = (rescan_height..block_count + 1).collect();

let (sender, receiver) = crossbeam_channel::bounded(block_range.len());
for task in IntoIterator::into_iter(block_range) {
for task in IntoIterator::into_iter(block_range.clone()) {
sender.send(task).unwrap();
}

Expand All @@ -146,6 +147,9 @@ impl Claimer {
.build()
.unwrap();

let processed_blocks = AtomicU64::new(0);
let blocks_to_rescan = block_range.len();

(0..rescan_threads)
.map(|_| receiver.clone())
.collect::<Vec<Receiver<u64>>>()
Expand Down Expand Up @@ -184,6 +188,13 @@ impl Claimer {
self_clone.clone().handle_tx(tx).await;
}
});

let processed = processed_blocks.fetch_add(1, Ordering::SeqCst) + 1;

if processed % 10 == 0 {
let processed_perc = processed as f64 / blocks_to_rescan as f64;
info!("Rescan progress: {:.2}%", processed_perc * 100.0);
}
}
});

Expand Down

0 comments on commit bb63153

Please sign in to comment.