From fdc31e99df9dd3498c43d7fc308d38fb8ce1624a Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Fri, 1 Mar 2019 13:10:17 -0800 Subject: [PATCH] Clean up type casts --- runtime/src/bank.rs | 2 +- runtime/src/hash_queue.rs | 2 +- sdk/src/timing.rs | 4 ++-- src/banking_stage.rs | 7 ++----- src/poh_service.rs | 2 +- src/rpc_request.rs | 2 +- wallet/src/wallet.rs | 8 ++++---- 7 files changed, 12 insertions(+), 15 deletions(-) diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 3b7cd77889..41462347b6 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -343,7 +343,7 @@ impl Bank { tick_hash_queue.register_hash(hash); tick_hash_queue.hash_height() }; - if current_tick_height % NUM_TICKS_PER_SECOND as u64 == 0 { + if current_tick_height % NUM_TICKS_PER_SECOND == 0 { self.status_cache.write().unwrap().new_cache(hash); } } diff --git a/runtime/src/hash_queue.rs b/runtime/src/hash_queue.rs index 53ccfb4e4e..c1cb531321 100644 --- a/runtime/src/hash_queue.rs +++ b/runtime/src/hash_queue.rs @@ -71,7 +71,7 @@ impl HashQueue { // this clean up can be deferred until sigs gets larger // because we verify entry.nth every place we check for validity - if self.entries.len() >= MAX_RECENT_TICK_HASHES as usize { + if self.entries.len() >= MAX_RECENT_TICK_HASHES { self.entries.retain(|_, entry| { hash_height - entry.hash_height <= MAX_RECENT_TICK_HASHES as u64 }); diff --git a/sdk/src/timing.rs b/sdk/src/timing.rs index 852f8b7d59..396767652a 100644 --- a/sdk/src/timing.rs +++ b/sdk/src/timing.rs @@ -2,7 +2,7 @@ use std::time::Duration; use std::time::{SystemTime, UNIX_EPOCH}; -pub const NUM_TICKS_PER_SECOND: usize = 10; +pub const NUM_TICKS_PER_SECOND: u64 = 10; // At 10 ticks/s, 8 ticks per slot implies that leader rotation and voting will happen // every 800 ms. A fast voting cadence ensures faster finality and convergence @@ -17,7 +17,7 @@ pub const DEFAULT_SLOTS_PER_EPOCH: u64 = 64; /// not be processed by the network. pub const MAX_HASH_AGE_IN_SECONDS: usize = 120; -pub const MAX_RECENT_TICK_HASHES: usize = NUM_TICKS_PER_SECOND * MAX_HASH_AGE_IN_SECONDS; +pub const MAX_RECENT_TICK_HASHES: usize = NUM_TICKS_PER_SECOND as usize * MAX_HASH_AGE_IN_SECONDS; pub fn duration_as_us(d: &Duration) -> u64 { (d.as_secs() * 1000 * 1000) + (u64::from(d.subsec_nanos()) / 1_000) diff --git a/src/banking_stage.rs b/src/banking_stage.rs index 933c4d9398..a9a0c4824e 100644 --- a/src/banking_stage.rs +++ b/src/banking_stage.rs @@ -172,11 +172,8 @@ impl BankingStage { // the likelihood of any single thread getting starved and processing old ids. // TODO: Banking stage threads should be prioritized to complete faster then this queue // expires. - let (loaded_accounts, results) = bank.load_and_execute_transactions( - txs, - lock_results, - MAX_RECENT_TICK_HASHES as usize / 2, - ); + let (loaded_accounts, results) = + bank.load_and_execute_transactions(txs, lock_results, MAX_RECENT_TICK_HASHES / 2); let load_execute_time = now.elapsed(); let record_time = { diff --git a/src/poh_service.rs b/src/poh_service.rs index 1510614e66..a871226f05 100644 --- a/src/poh_service.rs +++ b/src/poh_service.rs @@ -25,7 +25,7 @@ pub enum PohServiceConfig { impl Default for PohServiceConfig { fn default() -> PohServiceConfig { // TODO: Change this to Tick to enable PoH - PohServiceConfig::Sleep(Duration::from_millis(1000 / NUM_TICKS_PER_SECOND as u64)) + PohServiceConfig::Sleep(Duration::from_millis(1000 / NUM_TICKS_PER_SECOND)) } } diff --git a/src/rpc_request.rs b/src/rpc_request.rs index e547302f6b..366a856b00 100644 --- a/src/rpc_request.rs +++ b/src/rpc_request.rs @@ -88,7 +88,7 @@ impl RpcClient { // Sleep for approximately half a slot sleep(Duration::from_millis( - 500 * DEFAULT_TICKS_PER_SLOT / NUM_TICKS_PER_SECOND as u64, + 500 * DEFAULT_TICKS_PER_SLOT / NUM_TICKS_PER_SECOND, )); } } diff --git a/wallet/src/wallet.rs b/wallet/src/wallet.rs index 4256072245..7d920afb1b 100644 --- a/wallet/src/wallet.rs +++ b/wallet/src/wallet.rs @@ -754,7 +754,7 @@ fn get_next_last_id( next_last_id_retries -= 1; // Retry ~twice during a slot sleep(Duration::from_millis( - 500 * DEFAULT_TICKS_PER_SLOT / NUM_TICKS_PER_SECOND as u64, + 500 * DEFAULT_TICKS_PER_SLOT / NUM_TICKS_PER_SECOND, )); } } @@ -816,7 +816,7 @@ fn send_and_confirm_transaction( if cfg!(not(test)) { // Retry ~twice during a slot sleep(Duration::from_millis( - 500 * DEFAULT_TICKS_PER_SLOT / NUM_TICKS_PER_SECOND as u64, + 500 * DEFAULT_TICKS_PER_SLOT / NUM_TICKS_PER_SECOND, )); } }; @@ -857,7 +857,7 @@ fn send_and_confirm_transactions( if cfg!(not(test)) { // Delay ~1 tick between write transactions in an attempt to reduce AccountInUse errors // since all the write transactions modify the same program account - sleep(Duration::from_millis(1000 / NUM_TICKS_PER_SECOND as u64)); + sleep(Duration::from_millis(1000 / NUM_TICKS_PER_SECOND)); } let signature = send_transaction(&rpc_client, &transaction).ok(); @@ -871,7 +871,7 @@ fn send_and_confirm_transactions( if cfg!(not(test)) { // Retry ~twice during a slot sleep(Duration::from_millis( - 500 * DEFAULT_TICKS_PER_SLOT / NUM_TICKS_PER_SECOND as u64, + 500 * DEFAULT_TICKS_PER_SLOT / NUM_TICKS_PER_SECOND, )); }