Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
jcnelson committed Oct 6, 2020
1 parent 04bfa07 commit abe8416
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 37 deletions.
41 changes: 28 additions & 13 deletions src/chainstate/stacks/db/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -3511,11 +3511,18 @@ impl StacksChainState {
&candidate.parent_anchored_block_hash,
&candidate.parent_consensus_hash,
];
let hdr_row = query_row_panic::<StacksHeaderInfo, _, _>(headers_conn, &hdr_sql, hdr_args, || format!(
let hdr_row = query_row_panic::<StacksHeaderInfo, _, _>(
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!(
Expand All @@ -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!();
}
};
Expand All @@ -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
Expand Down
21 changes: 11 additions & 10 deletions src/net/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand All @@ -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();
Expand All @@ -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());
Expand All @@ -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 {
Expand All @@ -3194,7 +3195,7 @@ pub mod test {
}
true
},
|_| { true },
|_| true,
);

endpoint_thread_1.join().unwrap();
Expand Down
12 changes: 5 additions & 7 deletions src/net/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1291,7 +1292,7 @@ mod test {
},
);
}

#[test]
fn test_http_no_connecting_event_id_leak() {
use std::net::TcpListener;
Expand Down Expand Up @@ -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()) {
Expand Down
26 changes: 19 additions & 7 deletions testnet/stacks-node/src/syncctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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.",
Expand All @@ -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;
}

Expand Down Expand Up @@ -434,4 +447,3 @@ impl PoxSyncWatchdog {
ibd
}
}

0 comments on commit abe8416

Please sign in to comment.