Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show a progressbar when downloading tipset headers. #1469

Merged
merged 4 commits into from
Mar 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

10 changes: 7 additions & 3 deletions blockchain/chain_sync/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
[package]
name = "chain_sync"
name = "chain_sync"
version = "0.1.0"
authors = ["ChainSafe Systems <info@chainsafe.io>"]
edition = "2021"

[dependencies]
pbr = "1.0.3"
anyhow = "1.0"
cid_orig = { package = "cid", version = "0.8" }
fvm_shared = { version = "0.1", default-features = false }
Expand All @@ -20,7 +21,10 @@ libp2p = { version = "0.40.0-rc.1", default-features = false }
cid = { package = "forest_cid", version = "0.3" }
ipld_blockstore = "0.1"
chain = { path = "../chain" }
message = { package = "forest_message", version = "0.7", features = ["proofs", "blst"] }
message = { package = "forest_message", version = "0.7", features = [
"proofs",
"blst",
] }
state_tree = { path = "../../vm/state_tree/" }
state_manager = { path = "../state_manager/" }
num-bigint = { path = "../../utils/bigint", package = "forest_bigint" }
Expand Down Expand Up @@ -52,7 +56,7 @@ statediff = { path = "../../utils/statediff", optional = true }

[dev-dependencies]
test_utils = { version = "0.1.0", path = "../../utils/test_utils/", features = [
"test_constructors"
"test_constructors",
] }
base64 = "0.13"
genesis = { path = "../../utils/genesis", features = ["testing"] }
Expand Down
7 changes: 7 additions & 0 deletions blockchain/chain_sync/src/tipset_syncer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -844,10 +844,15 @@ async fn sync_headers_in_reverse<DB: BlockStore + Sync + Send + 'static>(
parent_tipsets.push(proposed_head.clone());
tracker.write().await.set_epoch(current_head.epoch());

let total_size = proposed_head.epoch() - current_head.epoch();
let mut pb = pbr::ProgressBar::new(total_size as u64);
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);
validate_tipset_against_cache(
bad_block_cache.clone(),
oldest_parent.parents(),
Expand Down Expand Up @@ -888,6 +893,8 @@ async fn sync_headers_in_reverse<DB: BlockStore + Sync + Send + 'static>(
parent_tipsets.push(tipset);
}
}
pb.finish();

// Unwrapping is safe here because we assume that the tipset
// vector was initialized with a tipset that will not be removed
let oldest_tipset = parent_tipsets.last().unwrap().clone();
Expand Down