Skip to content

Commit

Permalink
clippy: fix legacy_numeric_constants (#1314)
Browse files Browse the repository at this point in the history
clippy: legacy_numeric_constants
  • Loading branch information
yihau committed May 15, 2024
1 parent f9ea13c commit ec9bd79
Show file tree
Hide file tree
Showing 67 changed files with 166 additions and 189 deletions.
4 changes: 2 additions & 2 deletions account-decoder/src/parse_stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ mod test {
voter_pubkey,
stake: 20,
activation_epoch: 2,
deactivation_epoch: std::u64::MAX,
deactivation_epoch: u64::MAX,
warmup_cooldown_rate: 0.25,
},
credits_observed: 10,
Expand Down Expand Up @@ -222,7 +222,7 @@ mod test {
voter: voter_pubkey.to_string(),
stake: 20.to_string(),
activation_epoch: 2.to_string(),
deactivation_epoch: std::u64::MAX.to_string(),
deactivation_epoch: u64::MAX.to_string(),
warmup_cooldown_rate: 0.25,
},
credits_observed: 10,
Expand Down
4 changes: 2 additions & 2 deletions accounts-db/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6561,7 +6561,7 @@ impl AccountsDb {
fn report_store_stats(&self) {
let mut total_count = 0;
let mut newest_slot = 0;
let mut oldest_slot = std::u64::MAX;
let mut oldest_slot = u64::MAX;
let mut total_bytes = 0;
let mut total_alive_bytes = 0;
for (slot, store) in self.storage.iter() {
Expand Down Expand Up @@ -13252,7 +13252,7 @@ pub mod tests {
#[should_panic(expected = "overflow is detected while summing capitalization")]
fn test_checked_sum_for_capitalization_overflow() {
assert_eq!(
AccountsDb::checked_sum_for_capitalization(vec![1, u64::max_value()].into_iter()),
AccountsDb::checked_sum_for_capitalization(vec![1, u64::MAX].into_iter()),
3
);
}
Expand Down
10 changes: 5 additions & 5 deletions accounts-db/src/accounts_partition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ pub fn pubkey_range_from_partition(

type Prefix = u64;
const PREFIX_SIZE: usize = mem::size_of::<Prefix>();
const PREFIX_MAX: Prefix = Prefix::max_value();
const PREFIX_MAX: Prefix = Prefix::MAX;

let mut start_pubkey = [0x00u8; 32];
let mut end_pubkey = [0xffu8; 32];
Expand Down Expand Up @@ -319,7 +319,7 @@ pub fn partition_from_pubkey(
partition_count: PartitionsPerCycle,
) -> PartitionIndex {
type Prefix = u64;
const PREFIX_MAX: Prefix = Prefix::max_value();
const PREFIX_MAX: Prefix = Prefix::MAX;

if partition_count == 1 {
return 0;
Expand Down Expand Up @@ -503,11 +503,11 @@ pub(crate) mod tests {
);

fn should_cause_overflow(partition_count: u64) -> bool {
// Check `partition_width = (u64::max_value() + 1) / partition_count` is exact and
// Check `partition_width = (u64::MAX + 1) / partition_count` is exact and
// does not have a remainder.
// This way, `partition_width * partition_count == (u64::max_value() + 1)`,
// This way, `partition_width * partition_count == (u64::MAX + 1)`,
// so the test actually tests for overflow
(u64::max_value() - partition_count + 1) % partition_count == 0
(u64::MAX - partition_count + 1) % partition_count == 0
}

let max_exact = 64;
Expand Down
4 changes: 2 additions & 2 deletions accounts-db/src/append_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1320,7 +1320,7 @@ pub mod tests {
// wrap AppendVec in ManuallyDrop to ensure we do not remove the backing file when dropped
let av = ManuallyDrop::new(AppendVec::new(path, true, 1024 * 1024));

let too_large_data_len = u64::max_value();
let too_large_data_len = u64::MAX;
av.append_account_test(&create_test_account(10)).unwrap();

av.get_stored_account_meta_callback(0, |account| {
Expand Down Expand Up @@ -1359,7 +1359,7 @@ pub mod tests {
av.append_account_test(&executable_account).unwrap()
};

let crafted_executable = u8::max_value() - 1;
let crafted_executable = u8::MAX - 1;

// reload accounts
// ensure false is 0u8 and true is 1u8 actually
Expand Down
7 changes: 2 additions & 5 deletions accounts-db/src/hardened_unpack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1006,11 +1006,8 @@ mod tests {
let result = checked_total_size_sum(500, 500, MAX_SNAPSHOT_ARCHIVE_UNPACKED_ACTUAL_SIZE);
assert_matches!(result, Ok(1000));

let result = checked_total_size_sum(
u64::max_value() - 2,
2,
MAX_SNAPSHOT_ARCHIVE_UNPACKED_ACTUAL_SIZE,
);
let result =
checked_total_size_sum(u64::MAX - 2, 2, MAX_SNAPSHOT_ARCHIVE_UNPACKED_ACTUAL_SIZE);
assert_matches!(
result,
Err(UnpackError::Archive(ref message))
Expand Down
10 changes: 4 additions & 6 deletions banking-bench/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ fn main() {
// set cost tracker limits to MAX so it will not filter out TXs
bank.write_cost_tracker()
.unwrap()
.set_limits(std::u64::MAX, std::u64::MAX, std::u64::MAX);
.set_limits(u64::MAX, u64::MAX, u64::MAX);

let mut all_packets: Vec<PacketsPerIteration> = std::iter::from_fn(|| {
Some(PacketsPerIteration::new(
Expand Down Expand Up @@ -553,11 +553,9 @@ fn main() {
insert_time.stop();

// set cost tracker limits to MAX so it will not filter out TXs
bank.write_cost_tracker().unwrap().set_limits(
std::u64::MAX,
std::u64::MAX,
std::u64::MAX,
);
bank.write_cost_tracker()
.unwrap()
.set_limits(u64::MAX, u64::MAX, u64::MAX);

assert!(poh_recorder.read().unwrap().bank().is_none());
poh_recorder
Expand Down
2 changes: 1 addition & 1 deletion bench-tps/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl Default for Config {
websocket_url: ConfigInput::default().websocket_url,
id: Keypair::new(),
threads: 4,
duration: Duration::new(std::u64::MAX, 0),
duration: Duration::new(u64::MAX, 0),
tx_count: 50_000,
keypair_multiplier: 8,
thread_batch_sleep_ms: 1000,
Expand Down
12 changes: 6 additions & 6 deletions cli/src/cluster_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ pub fn process_catchup(
);
}

let mut previous_rpc_slot = std::i64::MAX;
let mut previous_rpc_slot = i64::MAX;
let mut previous_slot_distance: i64 = 0;
let mut retry_count: u64 = 0;
let max_retry_count = 5;
Expand Down Expand Up @@ -928,7 +928,7 @@ pub fn process_catchup(
},
node_slot,
rpc_slot,
if slot_distance == 0 || previous_rpc_slot == std::i64::MAX {
if slot_distance == 0 || previous_rpc_slot == i64::MAX {
"".to_string()
} else {
format!(
Expand Down Expand Up @@ -1504,7 +1504,7 @@ pub fn process_ping(
}
}

'mainloop: for seq in 0..count.unwrap_or(std::u64::MAX) {
'mainloop: for seq in 0..count.unwrap_or(u64::MAX) {
let now = Instant::now();
if fixed_blockhash.is_none() && now.duration_since(blockhash_acquired).as_secs() > 60 {
// Fetch a new blockhash every minute
Expand Down Expand Up @@ -1745,9 +1745,9 @@ pub fn process_live_slots(config: &CliConfig) -> ProcessResult {
let spacer = "|";
slot_progress.println(spacer);

let mut last_root = std::u64::MAX;
let mut last_root = u64::MAX;
let mut last_root_update = Instant::now();
let mut slots_per_second = std::f64::NAN;
let mut slots_per_second = f64::NAN;
loop {
if exit.load(Ordering::Relaxed) {
eprintln!("{message}");
Expand All @@ -1757,7 +1757,7 @@ pub fn process_live_slots(config: &CliConfig) -> ProcessResult {

match receiver.recv() {
Ok(new_info) => {
if last_root == std::u64::MAX {
if last_root == u64::MAX {
last_root = new_info.root;
last_root_update = Instant::now();
}
Expand Down
8 changes: 4 additions & 4 deletions cli/src/stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2362,12 +2362,12 @@ pub fn build_stake_state(
} else {
None
},
activation_epoch: Some(if stake.delegation.activation_epoch < std::u64::MAX {
activation_epoch: Some(if stake.delegation.activation_epoch < u64::MAX {
stake.delegation.activation_epoch
} else {
0
}),
deactivation_epoch: if stake.delegation.deactivation_epoch < std::u64::MAX {
deactivation_epoch: if stake.delegation.deactivation_epoch < u64::MAX {
Some(stake.delegation.deactivation_epoch)
} else {
None
Expand Down Expand Up @@ -2622,10 +2622,10 @@ pub fn process_show_stake_history(
})?;

let limit_results = match config.output_format {
OutputFormat::Json | OutputFormat::JsonCompact => std::usize::MAX,
OutputFormat::Json | OutputFormat::JsonCompact => usize::MAX,
_ => {
if limit_results == 0 {
std::usize::MAX
usize::MAX
} else {
limit_results
}
Expand Down
2 changes: 1 addition & 1 deletion core/benches/banking_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ fn bench_banking(bencher: &mut Bencher, tx_type: TransactionType) {
// set cost tracker limits to MAX so it will not filter out TXs
bank.write_cost_tracker()
.unwrap()
.set_limits(std::u64::MAX, std::u64::MAX, std::u64::MAX);
.set_limits(u64::MAX, u64::MAX, u64::MAX);

debug!("threads: {} txs: {}", num_threads, txes);

Expand Down
2 changes: 1 addition & 1 deletion core/benches/consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ fn setup(apply_cost_tracker_during_replay: bool) -> BenchFrame {
// set cost tracker limits to MAX so it will not filter out TXs
bank.write_cost_tracker()
.unwrap()
.set_limits(std::u64::MAX, std::u64::MAX, std::u64::MAX);
.set_limits(u64::MAX, u64::MAX, u64::MAX);
let bank = bank.wrap_with_bank_forks_for_tests().0;

let ledger_path = TempDir::new().unwrap();
Expand Down
6 changes: 3 additions & 3 deletions core/src/banking_stage/consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1432,7 +1432,7 @@ mod tests {
..
} = create_slow_genesis_config(10_000);
let mut bank = Bank::new_for_tests(&genesis_config);
bank.ns_per_slot = std::u128::MAX;
bank.ns_per_slot = u128::MAX;
if !apply_cost_tracker_during_replay_enabled {
bank.deactivate_feature(&feature_set::apply_cost_tracker_during_replay::id());
}
Expand Down Expand Up @@ -1665,7 +1665,7 @@ mod tests {
// set cost tracker limits to MAX so it will not filter out TXs
bank.write_cost_tracker()
.unwrap()
.set_limits(std::u64::MAX, std::u64::MAX, std::u64::MAX);
.set_limits(u64::MAX, u64::MAX, u64::MAX);

// Transfer more than the balance of the mint keypair, should cause a
// InstructionError::InsufficientFunds that is then committed. Needs to be
Expand Down Expand Up @@ -1726,7 +1726,7 @@ mod tests {
// set cost tracker limits to MAX so it will not filter out TXs
bank.write_cost_tracker()
.unwrap()
.set_limits(std::u64::MAX, std::u64::MAX, std::u64::MAX);
.set_limits(u64::MAX, u64::MAX, u64::MAX);

// Make all repetitive transactions that conflict on the `mint_keypair`, so only 1 should be executed
let mut transactions = vec![
Expand Down
4 changes: 2 additions & 2 deletions core/src/banking_trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ mod tests {
let path = temp_dir.path().join("banking-trace");
let exit = Arc::<AtomicBool>::default();
let (tracer, tracer_thread) =
BankingTracer::new(Some((&path, exit.clone(), DirByteLimit::max_value()))).unwrap();
BankingTracer::new(Some((&path, exit.clone(), DirByteLimit::MAX))).unwrap();
let (non_vote_sender, non_vote_receiver) = tracer.create_channel_non_vote();

let exit_for_dummy_thread = Arc::<AtomicBool>::default();
Expand Down Expand Up @@ -473,7 +473,7 @@ mod tests {
let path = temp_dir.path().join("banking-trace");
let exit = Arc::<AtomicBool>::default();
let (tracer, tracer_thread) =
BankingTracer::new(Some((&path, exit.clone(), DirByteLimit::max_value()))).unwrap();
BankingTracer::new(Some((&path, exit.clone(), DirByteLimit::MAX))).unwrap();
let (non_vote_sender, non_vote_receiver) = tracer.create_channel_non_vote();

let dummy_main_thread = thread::spawn(move || {
Expand Down
13 changes: 5 additions & 8 deletions core/src/cluster_slots_service/cluster_slots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,15 +283,15 @@ mod tests {
let mut map = HashMap::new();
let k1 = solana_sdk::pubkey::new_rand();
let k2 = solana_sdk::pubkey::new_rand();
map.insert(k1, std::u64::MAX / 2);
map.insert(k1, u64::MAX / 2);
map.insert(k2, 0);
cs.cluster_slots
.write()
.unwrap()
.insert(0, Arc::new(RwLock::new(map)));
c1.set_pubkey(k1);
c2.set_pubkey(k2);
assert_eq!(cs.compute_weights(0, &[c1, c2]), vec![std::u64::MAX / 4, 1]);
assert_eq!(cs.compute_weights(0, &[c1, c2]), vec![u64::MAX / 4, 1]);
}

#[test]
Expand All @@ -311,7 +311,7 @@ mod tests {
let validator_stakes: HashMap<_, _> = vec![(
k1,
NodeVoteAccounts {
total_stake: std::u64::MAX / 2,
total_stake: u64::MAX / 2,
vote_accounts: vec![Pubkey::default()],
},
)]
Expand All @@ -320,10 +320,7 @@ mod tests {
*cs.validator_stakes.write().unwrap() = Arc::new(validator_stakes);
c1.set_pubkey(k1);
c2.set_pubkey(k2);
assert_eq!(
cs.compute_weights(0, &[c1, c2]),
vec![std::u64::MAX / 4 + 1, 1]
);
assert_eq!(cs.compute_weights(0, &[c1, c2]), vec![u64::MAX / 4 + 1, 1]);
}

#[test]
Expand All @@ -345,7 +342,7 @@ mod tests {
let validator_stakes: HashMap<_, _> = vec![(
*contact_infos[1].pubkey(),
NodeVoteAccounts {
total_stake: std::u64::MAX / 2,
total_stake: u64::MAX / 2,
vote_accounts: vec![Pubkey::default()],
},
)]
Expand Down
4 changes: 2 additions & 2 deletions core/src/repair/ancestor_hashes_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1801,7 +1801,7 @@ mod test {
// If the request timed out, we should remove the slot from `ancestor_hashes_request_statuses`,
// and add it to `repairable_dead_slot_pool` or `popular_pruned_slot_pool`.
// Because the request_throttle is at its limit, we should not immediately retry the timed request.
request_throttle.resize(MAX_ANCESTOR_HASHES_SLOT_REQUESTS_PER_SECOND, std::u64::MAX);
request_throttle.resize(MAX_ANCESTOR_HASHES_SLOT_REQUESTS_PER_SECOND, u64::MAX);
AncestorHashesService::manage_ancestor_requests(
&ancestor_hashes_request_statuses,
&ancestor_hashes_request_socket,
Expand Down Expand Up @@ -1867,7 +1867,7 @@ mod test {
// 5) If we've reached the throttle limit, no requests should be made,
// but should still read off the channel for replay updates
request_throttle.clear();
request_throttle.resize(MAX_ANCESTOR_HASHES_SLOT_REQUESTS_PER_SECOND, std::u64::MAX);
request_throttle.resize(MAX_ANCESTOR_HASHES_SLOT_REQUESTS_PER_SECOND, u64::MAX);
let dead_duplicate_confirmed_slot_2 = 15;
ancestor_hashes_replay_update_sender
.send(AncestorHashesReplayUpdate::DeadDuplicateConfirmed(
Expand Down
Loading

0 comments on commit ec9bd79

Please sign in to comment.