From abe8416f58af3ff94e9041a0bb22aed997efb687 Mon Sep 17 00:00:00 2001 From: Jude Nelson Date: Mon, 5 Oct 2020 21:08:03 -0400 Subject: [PATCH] cargo fmt --- src/chainstate/stacks/db/blocks.rs | 41 ++++++++++++++++++++---------- src/net/download.rs | 21 +++++++-------- src/net/server.rs | 12 ++++----- testnet/stacks-node/src/syncctl.rs | 26 ++++++++++++++----- 4 files changed, 63 insertions(+), 37 deletions(-) diff --git a/src/chainstate/stacks/db/blocks.rs b/src/chainstate/stacks/db/blocks.rs index 0996d4f70c..b78d53e0aa 100644 --- a/src/chainstate/stacks/db/blocks.rs +++ b/src/chainstate/stacks/db/blocks.rs @@ -47,8 +47,8 @@ use std::path::{Path, PathBuf}; use util::db::Error as db_error; use util::db::{ - query_count, query_int, query_row, query_row_columns, query_rows, tx_busy_handler, DBConn, - FromColumn, FromRow, query_row_panic + query_count, query_int, query_row, query_row_columns, query_row_panic, query_rows, + tx_busy_handler, DBConn, FromColumn, FromRow, }; use util::db::u64_to_sql; @@ -3511,11 +3511,18 @@ impl StacksChainState { &candidate.parent_anchored_block_hash, &candidate.parent_consensus_hash, ]; - let hdr_row = query_row_panic::(headers_conn, &hdr_sql, hdr_args, || format!( + let hdr_row = query_row_panic::( + headers_conn, + &hdr_sql, + hdr_args, + || { + format!( "Stored the same block twice: {}/{}", &candidate.parent_anchored_block_hash, &candidate.parent_consensus_hash - ))?; + ) + }, + )?; match hdr_row { Some(_) => { debug!( @@ -3540,16 +3547,27 @@ impl StacksChainState { if can_attach { // load up the block data - candidate.block_data = match StacksChainState::load_block_bytes(blocks_path, &candidate.consensus_hash, &candidate.anchored_block_hash)? { + candidate.block_data = match StacksChainState::load_block_bytes( + blocks_path, + &candidate.consensus_hash, + &candidate.anchored_block_hash, + )? { Some(bytes) => { if bytes.len() == 0 { - error!("CORRUPTION: No block data for {}/{}", &candidate.consensus_hash, &candidate.anchored_block_hash); + error!( + "CORRUPTION: No block data for {}/{}", + &candidate.consensus_hash, + &candidate.anchored_block_hash + ); panic!(); } bytes - }, + } None => { - error!("CORRUPTION: No block data for {}/{}", &candidate.consensus_hash, &candidate.anchored_block_hash); + error!( + "CORRUPTION: No block data for {}/{}", + &candidate.consensus_hash, &candidate.anchored_block_hash + ); panic!(); } }; @@ -3558,13 +3576,10 @@ impl StacksChainState { match StacksChainState::find_parent_staging_microblock_stream( blocks_tx, blocks_path, - &candidate + &candidate, )? { Some(parent_staging_microblocks) => { - return Ok(Some(( - parent_staging_microblocks, - candidate, - ))); + return Ok(Some((parent_staging_microblocks, candidate))); } None => { // no microblock data yet, so we can't process this block diff --git a/src/net/download.rs b/src/net/download.rs index adba263549..431b18078e 100644 --- a/src/net/download.rs +++ b/src/net/download.rs @@ -2258,8 +2258,8 @@ pub mod test { use net::test::*; use net::*; use std::collections::HashMap; - use util::test::*; use util::sleep_ms; + use util::test::*; fn get_peer_availability( peer: &mut TestPeer, @@ -3113,9 +3113,9 @@ pub mod test { #[ignore] #[should_panic(expected = "blocked URL")] pub fn test_get_blocks_and_microblocks_ban_url() { + use std::convert::TryFrom; use std::net::TcpListener; use std::thread; - use std::convert::TryFrom; let listener_1 = TcpListener::bind("127.0.0.1:3260").unwrap(); let listener_2 = TcpListener::bind("127.0.0.1:3262").unwrap(); @@ -3125,7 +3125,7 @@ pub mod test { test_debug!("Accepted 1 {:?}", &addr); sleep_ms(60_000); }); - + let endpoint_thread_2 = thread::spawn(move || { let (sock, addr) = listener_2.accept().unwrap(); test_debug!("Accepted 2 {:?}", &addr); @@ -3144,8 +3144,10 @@ pub mod test { peer_configs[1].connection_opts.disable_block_advertisement = true; // announce URLs to our fake handlers - peer_configs[0].data_url = UrlString::try_from("http://127.0.0.1:3260".to_string()).unwrap(); - peer_configs[1].data_url = UrlString::try_from("http://127.0.0.1:3262".to_string()).unwrap(); + peer_configs[0].data_url = + UrlString::try_from("http://127.0.0.1:3260".to_string()).unwrap(); + peer_configs[1].data_url = + UrlString::try_from("http://127.0.0.1:3262".to_string()).unwrap(); let peer_0 = peer_configs[0].to_neighbor(); let peer_1 = peer_configs[1].to_neighbor(); @@ -3156,8 +3158,7 @@ pub mod test { // build up block data to replicate let mut block_data = vec![]; for _ in 0..num_blocks { - let (mut burn_ops, stacks_block, microblocks) = - peers[1].make_default_tenure(); + let (mut burn_ops, stacks_block, microblocks) = peers[1].make_default_tenure(); let (_, burn_header_hash, consensus_hash) = peers[1].next_burnchain_block(burn_ops.clone()); @@ -3180,12 +3181,12 @@ pub mod test { block_data }, |_| {}, - |peer| { + |peer| { let mut blocked = 0; match peer.network.block_downloader { Some(ref dl) => { blocked = dl.blocked_urls.len(); - }, + } None => {} } if blocked >= 1 { @@ -3194,7 +3195,7 @@ pub mod test { } true }, - |_| { true }, + |_| true, ); endpoint_thread_1.join().unwrap(); diff --git a/src/net/server.rs b/src/net/server.rs index 21ce6c8cc1..f08c04d724 100644 --- a/src/net/server.rs +++ b/src/net/server.rs @@ -794,7 +794,7 @@ mod test { let mut peer = TestPeer::new(peer_config); let view = peer.get_burnchain_view().unwrap(); let (http_sx, http_rx) = sync_channel(1); - + let network_id = peer.config.network_id; let chainstate_path = peer.chainstate_path.clone(); @@ -823,7 +823,8 @@ mod test { let mut client_requests = vec![]; let mut client_threads = vec![]; let mut client_handles = vec![]; - let (mut chainstate, _) = StacksChainState::open(false, network_id, &chainstate_path).unwrap(); + let (mut chainstate, _) = + StacksChainState::open(false, network_id, &chainstate_path).unwrap(); for i in 0..num_clients { let request = make_request(i, &mut chainstate); client_requests.push(request); @@ -1291,7 +1292,7 @@ mod test { }, ); } - + #[test] fn test_http_no_connecting_event_id_leak() { use std::net::TcpListener; @@ -1323,15 +1324,12 @@ mod test { let request_bytes = StacksHttp::serialize_request(&request).unwrap(); request_bytes }, - |client_id, res| { - true - }, + |client_id, res| true, ); assert_eq!(num_events, 2); } - #[test] fn test_http_noop() { if std::env::var("BLOCKSTACK_HTTP_TEST") != Ok("1".to_string()) { diff --git a/testnet/stacks-node/src/syncctl.rs b/testnet/stacks-node/src/syncctl.rs index fafb445389..b46093b355 100644 --- a/testnet/stacks-node/src/syncctl.rs +++ b/testnet/stacks-node/src/syncctl.rs @@ -115,7 +115,8 @@ impl PoxSyncWatchdog { burnchain_tip: &BurnchainTip, burnchain_height: u64, ) -> bool { - burnchain_tip.block_snapshot.block_height + (burnchain.stable_confirmations as u64) < burnchain_height + burnchain_tip.block_snapshot.block_height + (burnchain.stable_confirmations as u64) + < burnchain_height } /// Calculate the first derivative of a list of points @@ -301,14 +302,21 @@ impl PoxSyncWatchdog { < burnchain.first_block_height + (burnchain.pox_constants.reward_cycle_length as u64) { debug!("PoX watchdog in first reward cycle -- sync immediately"); - return PoxSyncWatchdog::infer_initial_block_download(burnchain, burnchain_tip, burnchain_height); + return PoxSyncWatchdog::infer_initial_block_download( + burnchain, + burnchain_tip, + burnchain_height, + ); } let mut steady_state = false; let ibd = loop { - let ibd = - PoxSyncWatchdog::infer_initial_block_download(burnchain, burnchain_tip, burnchain_height); + let ibd = PoxSyncWatchdog::infer_initial_block_download( + burnchain, + burnchain_tip, + burnchain_height, + ); let expected_first_block_deadline = self.watch_start_ts + (self.estimated_block_download_time as u64); @@ -357,7 +365,11 @@ impl PoxSyncWatchdog { if self.watch_start_ts > 0 && (self.new_attachable_blocks.len() as u64) < self.max_samples - && self.watch_start_ts + self.max_samples + self.steady_state_burnchain_sync_interval * (burnchain.stable_confirmations as u64) < get_epoch_time_secs() + && self.watch_start_ts + + self.max_samples + + self.steady_state_burnchain_sync_interval + * (burnchain.stable_confirmations as u64) + < get_epoch_time_secs() { debug!( "PoX watchdog: could not calculate {} samples in {} seconds. Assuming suspend/resume, or assuming load is too high.", @@ -367,7 +379,8 @@ impl PoxSyncWatchdog { self.reset(burnchain, burnchain_tip.block_snapshot.block_height); self.watch_start_ts = get_epoch_time_secs(); - self.steady_state_resync_ts = get_epoch_time_secs() + self.steady_state_burnchain_sync_interval; + self.steady_state_resync_ts = + get_epoch_time_secs() + self.steady_state_burnchain_sync_interval; continue; } @@ -434,4 +447,3 @@ impl PoxSyncWatchdog { ibd } } -