From 8e0ff0073a542c5cd8e49c9b20b368bb6d4650e8 Mon Sep 17 00:00:00 2001 From: David Himmelstrup Date: Tue, 8 Mar 2022 12:01:36 +0100 Subject: [PATCH 1/2] Show a progressbar when downloading tipset headers. Downloading tipset headers can take anywhere from minutes to hours. --- Cargo.lock | 1 + blockchain/chain_sync/Cargo.toml | 10 +++++++--- blockchain/chain_sync/src/tipset_syncer.rs | 9 +++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 24fb9feac633..a763b5325eb4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1080,6 +1080,7 @@ dependencies = [ "message_pool", "networks", "num-traits", + "pbr", "pretty_env_logger", "prometheus 0.12.0", "rand 0.7.3", diff --git a/blockchain/chain_sync/Cargo.toml b/blockchain/chain_sync/Cargo.toml index 4b8d3e18a017..f4a059957e0a 100644 --- a/blockchain/chain_sync/Cargo.toml +++ b/blockchain/chain_sync/Cargo.toml @@ -1,10 +1,11 @@ [package] -name = "chain_sync" +name = "chain_sync" version = "0.1.0" authors = ["ChainSafe Systems "] edition = "2021" [dependencies] +pbr = "1.0.3" address = { package = "forest_address", version = "0.3" } vm = { package = "forest_vm", version = "0.3.1" } amt = { package = "ipld_amt", version = "0.2" } @@ -17,7 +18,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" } @@ -48,7 +52,7 @@ lazy_static = "1.4.0" [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"] } diff --git a/blockchain/chain_sync/src/tipset_syncer.rs b/blockchain/chain_sync/src/tipset_syncer.rs index 4ec8a9dda23c..97d5baa3e974 100644 --- a/blockchain/chain_sync/src/tipset_syncer.rs +++ b/blockchain/chain_sync/src/tipset_syncer.rs @@ -844,10 +844,17 @@ async fn sync_headers_in_reverse( parent_tipsets.push(proposed_head.clone()); tracker.write().await.set_epoch(current_head.epoch()); + use pbr::ProgressBar; + use std::time::Duration; + let total_size = proposed_head.epoch() - current_head.epoch(); + let mut pb = ProgressBar::new(total_size as u64); + pb.set_max_refresh_rate(Some(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(), @@ -888,6 +895,8 @@ async fn sync_headers_in_reverse( 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(); From 291c0e695c0b8a6d953b1c1eef6a8551d3be8745 Mon Sep 17 00:00:00 2001 From: David Himmelstrup Date: Wed, 9 Mar 2022 15:53:46 +0100 Subject: [PATCH 2/2] Remove unnecessary 'use' statements. --- blockchain/chain_sync/src/tipset_syncer.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/blockchain/chain_sync/src/tipset_syncer.rs b/blockchain/chain_sync/src/tipset_syncer.rs index 97d5baa3e974..0593bf210a52 100644 --- a/blockchain/chain_sync/src/tipset_syncer.rs +++ b/blockchain/chain_sync/src/tipset_syncer.rs @@ -844,11 +844,9 @@ async fn sync_headers_in_reverse( parent_tipsets.push(proposed_head.clone()); tracker.write().await.set_epoch(current_head.epoch()); - use pbr::ProgressBar; - use std::time::Duration; let total_size = proposed_head.epoch() - current_head.epoch(); - let mut pb = ProgressBar::new(total_size as u64); - pb.set_max_refresh_rate(Some(Duration::from_millis(500))); + 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