Skip to content

Commit

Permalink
Use progress bars when downloading headers and scanning the blockchai…
Browse files Browse the repository at this point in the history
…n. (#1480)
  • Loading branch information
lemmih authored Mar 16, 2022
1 parent dcc553e commit 879cb3e
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions blockchain/chain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ authors = ["ChainSafe Systems <info@chainsafe.io>"]
edition = "2021"

[dependencies]
pbr = "1.0.3"
blocks = { package = "forest_blocks", path = "../blocks", features = ["json"] }
db = { package = "forest_db", version = "0.1" }
cid = { package = "forest_cid", version = "0.3" }
Expand Down
9 changes: 9 additions & 0 deletions blockchain/chain/src/store/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ where
if from.epoch() - to <= SKIP_LENGTH {
return self.walk_back(from, to).await;
}
let total_size = from.epoch() - to;
let mut pb = pbr::ProgressBar::new(total_size as u64);
pb.message("Scanning blockchain ");
pb.set_max_refresh_rate(Some(std::time::Duration::from_millis(500)));

let rounded = self.round_down(from).await?;

Expand All @@ -79,6 +83,11 @@ where
} else if to > lbe.target_height {
return self.walk_back(lbe.tipset.clone(), to).await;
}
let to_be_done = lbe.tipset.epoch() - to;
// Don't show the progress bar if we're doing less than 10_000 units of work.
if total_size > 10_000 {
pb.set((total_size - to_be_done) as u64);
}

cur = lbe.target.clone();
}
Expand Down
4 changes: 3 additions & 1 deletion blockchain/chain_sync/src/tipset_syncer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -846,13 +846,15 @@ async fn sync_headers_in_reverse<DB: BlockStore + Sync + Send + 'static>(

let total_size = proposed_head.epoch() - current_head.epoch();
let mut pb = pbr::ProgressBar::new(total_size as u64);
pb.message("Downloading headers ");
pb.set_max_refresh_rate(Some(std::time::Duration::from_millis(500)));

'sync: loop {
// Unwrapping is safe here because the tipset vector always
// has at least one element
let oldest_parent = parent_tipsets.last().unwrap();
pb.set((oldest_parent.epoch() - total_size).abs() as u64);
let work_to_be_done = oldest_parent.epoch() - current_head.epoch();
pb.set((work_to_be_done - total_size).abs() as u64);
validate_tipset_against_cache(
bad_block_cache.clone(),
oldest_parent.parents(),
Expand Down
2 changes: 1 addition & 1 deletion node/forest_libp2p/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ where
},
interval_event = interval.next() => if interval_event.is_some() {
// Print peer count on an interval.
info!("Peers connected: {}", swarm_stream.get_mut().behaviour_mut().peers().len());
debug!("Peers connected: {}", swarm_stream.get_mut().behaviour_mut().peers().len());
}
};
}
Expand Down
2 changes: 2 additions & 0 deletions utils/net_utils/src/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ impl TryFrom<Url> for FetchProgress<AsyncBody, Stdout> {
let request = task::block_on(client.get_async(url.as_str()))?;

let mut pb = ProgressBar::new(total_size);
pb.message("Downloading/Importing snapshot ");
pb.set_units(Units::Bytes);
pb.set_max_refresh_rate(Some(Duration::from_millis(500)));

Expand All @@ -89,6 +90,7 @@ impl TryFrom<File> for FetchProgress<BufReader<File>, Stdout> {
let total_size = async_std::task::block_on(file.metadata())?.len();

let mut pb = ProgressBar::new(total_size);
pb.message("Importing snapshot ");
pb.set_units(Units::Bytes);
pb.set_max_refresh_rate(Some(Duration::from_millis(500)));

Expand Down

0 comments on commit 879cb3e

Please sign in to comment.