Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
mvines authored and mergify[bot] committed Apr 19, 2021
1 parent b379004 commit f59d4f2
Show file tree
Hide file tree
Showing 39 changed files with 112 additions and 143 deletions.
8 changes: 3 additions & 5 deletions clap-utils/src/keypair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,9 @@ impl DefaultSigner {
unique_signers.push(default_signer);
}

for signer in bulk_signers.into_iter() {
if let Some(signer) = signer {
if !unique_signers.iter().any(|s| s == &signer) {
unique_signers.push(signer);
}
for signer in bulk_signers.into_iter().flatten() {
if !unique_signers.iter().any(|s| s == &signer) {
unique_signers.push(signer);
}
}
Ok(CliSignerInfo {
Expand Down
2 changes: 1 addition & 1 deletion cli/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1782,7 +1782,7 @@ fn read_and_verify_elf(program_location: &str) -> Result<Vec<u8>, Box<dyn std::e
.map_err(|err| format!("Unable to read program file: {}", err))?;

// Verify the program
Executable::<BpfError, ThisInstructionMeter>::from_elf(
<dyn Executable<BpfError, ThisInstructionMeter>>::from_elf(
&program_data,
Some(|x| bpf_verifier::check(x)),
Config::default(),
Expand Down
4 changes: 2 additions & 2 deletions cli/src/stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,9 @@ pub fn parse_stake_create_account(
staker,
withdrawer,
lockup: Lockup {
custodian,
epoch,
unix_timestamp,
epoch,
custodian,
},
amount,
sign_only,
Expand Down
2 changes: 1 addition & 1 deletion client/src/thin_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ impl ThinClient {
let rpc_clients: Vec<_> = rpc_addrs.into_iter().map(RpcClient::new_socket).collect();
let optimizer = ClientOptimizer::new(rpc_clients.len());
Self {
tpu_addrs,
transactions_socket,
tpu_addrs,
rpc_clients,
optimizer,
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/banking_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2634,7 +2634,7 @@ mod tests {
// should still be unprocessed
assert_eq!(
buffered_packets.len(),
packets_vec[interrupted_iteration + 1..].iter().count()
packets_vec[interrupted_iteration + 1..].len()
);
for ((remaining_unprocessed_packet, _, _forwarded), original_packet) in
buffered_packets
Expand Down
1 change: 0 additions & 1 deletion core/src/broadcast_stage/standard_broadcast_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ impl StandardBroadcastRun {
num_expected_batches,
slot_start_ts: self
.slot_broadcast_start
.clone()
.expect("Start timestamp must exist for a slot if we're broadcasting the slot"),
});
get_leader_schedule_time.stop();
Expand Down
21 changes: 7 additions & 14 deletions core/src/cluster_info_vote_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1430,26 +1430,19 @@ mod tests {
let slot_vote_tracker = vote_tracker.get_slot_vote_tracker(vote_slot).unwrap();
let r_slot_vote_tracker = &slot_vote_tracker.read().unwrap();

assert_eq!(
r_slot_vote_tracker
.optimistic_votes_tracker(&vote_bank_hash)
.unwrap()
.stake(),
100
);
if events == vec![1] {
// Check `gossip_only_stake` is not incremented
assert_eq!(
r_slot_vote_tracker
.optimistic_votes_tracker(&vote_bank_hash)
.unwrap()
.stake(),
100
);
assert_eq!(r_slot_vote_tracker.gossip_only_stake, 0);
} else {
// Check that both the `gossip_only_stake` and `total_voted_stake` both
// increased
assert_eq!(
r_slot_vote_tracker
.optimistic_votes_tracker(&vote_bank_hash)
.unwrap()
.stake(),
100
);
assert_eq!(r_slot_vote_tracker.gossip_only_stake, 100);
}
}
Expand Down
6 changes: 2 additions & 4 deletions core/src/commitment_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,15 +315,13 @@ mod tests {
);

for a in ancestors {
let mut expected = BlockCommitment::default();
if a <= root {
let mut expected = BlockCommitment::default();
expected.increase_rooted_stake(lamports);
assert_eq!(*commitment.get(&a).unwrap(), expected);
} else {
let mut expected = BlockCommitment::default();
expected.increase_confirmation_stake(1, lamports);
assert_eq!(*commitment.get(&a).unwrap(), expected);
}
assert_eq!(*commitment.get(&a).unwrap(), expected);
}
assert_eq!(rooted_stake[0], (root, lamports));
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,7 @@ impl SavedTower {
pub fn new<T: Signer>(tower: &Tower, keypair: &Arc<T>) -> Result<Self> {
let data = bincode::serialize(tower)?;
let signature = keypair.sign_message(&data);
Ok(Self { data, signature })
Ok(Self { signature, data })
}

pub fn verify(&self, pubkey: &Pubkey) -> bool {
Expand Down
6 changes: 3 additions & 3 deletions core/src/progress_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,11 @@ impl ForkProgress {
num_blocks_on_fork,
num_dropped_blocks_on_fork,
propagated_stats: PropagatedStats {
prev_leader_slot,
is_leader_slot,
propagated_validators_stake,
propagated_validators,
propagated_validators_stake,
is_propagated,
is_leader_slot,
prev_leader_slot,
total_epoch_stake,
..PropagatedStats::default()
},
Expand Down
2 changes: 1 addition & 1 deletion core/src/retransmit_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ fn update_retransmit_stats(
),
);
let mut packets_by_slot = stats.packets_by_slot.lock().unwrap();
let old_packets_by_slot = std::mem::replace(&mut *packets_by_slot, BTreeMap::new());
let old_packets_by_slot = std::mem::take(&mut *packets_by_slot);
drop(packets_by_slot);

for (slot, num_shreds) in old_packets_by_slot {
Expand Down
4 changes: 2 additions & 2 deletions core/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ impl JsonRpcRequestProcessor {
return Ok(self
.runtime
.block_on(bigtable_ledger_storage.get_confirmed_blocks(start_slot, limit))
.unwrap_or_else(|_| vec![]));
.unwrap_or_default());
}
}

Expand Down Expand Up @@ -1246,7 +1246,7 @@ impl JsonRpcRequestProcessor {
);
self.blockstore
.get_confirmed_signatures_for_address(pubkey, start_slot, end_slot)
.unwrap_or_else(|_| vec![])
.unwrap_or_default()
} else {
vec![]
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/rpc_subscriptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,8 @@ impl RpcSubscriptions {
let exit_clone = exit.clone();
let subscriptions = Subscriptions {
account_subscriptions,
logs_subscriptions,
program_subscriptions,
logs_subscriptions,
signature_subscriptions,
gossip_account_subscriptions,
gossip_logs_subscriptions,
Expand Down
2 changes: 1 addition & 1 deletion core/src/test_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,8 @@ impl TestValidator {
preserve_ledger,
rpc_pubsub_url,
rpc_url,
gossip,
tpu,
gossip,
validator,
vote_account_address,
})
Expand Down
4 changes: 2 additions & 2 deletions genesis/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,10 +506,10 @@ fn main() -> Result<(), Box<dyn error::Error>> {
let mut genesis_config = GenesisConfig {
native_instruction_processors,
ticks_per_slot,
epoch_schedule,
poh_config,
fee_rate_governor,
rent,
poh_config,
epoch_schedule,
cluster_type,
..GenesisConfig::default()
};
Expand Down
2 changes: 1 addition & 1 deletion gossip/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ fn process_spy_results(
}
}
if let Some(node) = pubkey {
if validators.iter().find(|x| x.id == node).is_none() {
if !validators.iter().any(|x| x.id == node) {
eprintln!("Error: Could not find node {:?}", node);
exit(1);
}
Expand Down
4 changes: 3 additions & 1 deletion install/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,9 @@ pub fn init_or_update(config_file: &str, is_init: bool, check_only: bool) -> Res
print_update_manifest(&update_manifest);

if timestamp_secs()
< u64::from_str_radix(crate::build_env::BUILD_SECONDS_SINCE_UNIX_EPOCH, 10).unwrap()
< crate::build_env::BUILD_SECONDS_SINCE_UNIX_EPOCH
.parse::<u64>()
.unwrap()
{
return Err("Unable to update as system time seems unreliable".to_string());
}
Expand Down
52 changes: 24 additions & 28 deletions ledger-tool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1656,35 +1656,31 @@ fn main() {
let log_file = PathBuf::from(value_t_or_exit!(arg_matches, "log_path", String));
let f = BufReader::new(File::open(log_file).unwrap());
println!("Reading log file");
for line in f.lines() {
if let Ok(line) = line {
let parse_results = {
if let Some(slot_string) = frozen_regex.captures_iter(&line).next() {
Some((slot_string, &mut frozen))
} else {
full_regex
.captures_iter(&line)
.next()
.map(|slot_string| (slot_string, &mut full))
}
};
for line in f.lines().flatten() {
let parse_results = {
if let Some(slot_string) = frozen_regex.captures_iter(&line).next() {
Some((slot_string, &mut frozen))
} else {
full_regex
.captures_iter(&line)
.next()
.map(|slot_string| (slot_string, &mut full))
}
};

if let Some((slot_string, map)) = parse_results {
let slot = slot_string
.get(1)
.expect("Only one match group")
.as_str()
.parse::<u64>()
.unwrap();
if ancestors.contains(&slot) && !map.contains_key(&slot) {
map.insert(slot, line);
}
if slot == ending_slot
&& frozen.contains_key(&slot)
&& full.contains_key(&slot)
{
break;
}
if let Some((slot_string, map)) = parse_results {
let slot = slot_string
.get(1)
.expect("Only one match group")
.as_str()
.parse::<u64>()
.unwrap();
if ancestors.contains(&slot) && !map.contains_key(&slot) {
map.insert(slot, line);
}
if slot == ending_slot && frozen.contains_key(&slot) && full.contains_key(&slot)
{
break;
}
}
}
Expand Down
10 changes: 3 additions & 7 deletions ledger/src/blockstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4708,14 +4708,10 @@ pub mod tests {
if slot % 3 == 0 {
let shred0 = shreds_for_slot.remove(0);
missing_shreds.push(shred0);
blockstore
.insert_shreds(shreds_for_slot, None, false)
.unwrap();
} else {
blockstore
.insert_shreds(shreds_for_slot, None, false)
.unwrap();
}
blockstore
.insert_shreds(shreds_for_slot, None, false)
.unwrap();
}

// Check metadata
Expand Down
7 changes: 7 additions & 0 deletions ledger/src/blockstore_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ impl<T: SlotColumn> Column for T {
index
}

#[allow(clippy::wrong_self_convention)]
fn as_index(slot: Slot) -> u64 {
slot
}
Expand Down Expand Up @@ -480,6 +481,7 @@ impl Column for columns::TransactionStatus {
index.0
}

#[allow(clippy::wrong_self_convention)]
fn as_index(index: u64) -> Self::Index {
(index, Signature::default(), 0)
}
Expand Down Expand Up @@ -516,6 +518,7 @@ impl Column for columns::AddressSignatures {
index.0
}

#[allow(clippy::wrong_self_convention)]
fn as_index(index: u64) -> Self::Index {
(index, Pubkey::default(), 0, Signature::default())
}
Expand All @@ -542,6 +545,7 @@ impl Column for columns::TransactionStatusIndex {
index
}

#[allow(clippy::wrong_self_convention)]
fn as_index(slot: u64) -> u64 {
slot
}
Expand Down Expand Up @@ -590,6 +594,7 @@ impl Column for columns::ShredCode {
index.0
}

#[allow(clippy::wrong_self_convention)]
fn as_index(slot: Slot) -> Self::Index {
(slot, 0)
}
Expand Down Expand Up @@ -619,6 +624,7 @@ impl Column for columns::ShredData {
index.0
}

#[allow(clippy::wrong_self_convention)]
fn as_index(slot: Slot) -> Self::Index {
(slot, 0)
}
Expand Down Expand Up @@ -697,6 +703,7 @@ impl Column for columns::ErasureMeta {
index.0
}

#[allow(clippy::wrong_self_convention)]
fn as_index(slot: Slot) -> Self::Index {
(slot, 0)
}
Expand Down
4 changes: 1 addition & 3 deletions ledger/src/leader_schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ impl LeaderSchedule {
.map(|i| {
if i % repeat == 0 {
current_node = ids[weighted_index.sample(rng)];
current_node
} else {
current_node
}
current_node
})
.collect();
Self::new_from_schedule(slot_leaders)
Expand Down
Loading

0 comments on commit f59d4f2

Please sign in to comment.