Skip to content

Commit a22e66a

Browse files
committed
fix automatically fixable or obvious lints
1 parent b735118 commit a22e66a

File tree

28 files changed

+468
-492
lines changed

28 files changed

+468
-492
lines changed

account_manager/src/validator/exit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,6 @@ mod tests {
409409
)
410410
.unwrap();
411411

412-
assert_eq!(expected_pk, kp.pk.into());
412+
assert_eq!(expected_pk, kp.pk);
413413
}
414414
}

beacon_node/beacon_chain/src/shuffling_cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ mod test {
512512
}
513513

514514
assert!(
515-
!cache.contains(&shuffling_id_and_committee_caches.get(0).unwrap().0),
515+
!cache.contains(&shuffling_id_and_committee_caches.first().unwrap().0),
516516
"should not contain oldest epoch shuffling id"
517517
);
518518
assert_eq!(

beacon_node/beacon_chain/tests/attestation_production.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ async fn produces_attestations_from_attestation_simulator_service() {
7070
}
7171

7272
// Compare the prometheus metrics that evaluates the performance of the unaggregated attestations
73-
let hit_prometheus_metrics = vec![
73+
let hit_prometheus_metrics = [
7474
metrics::VALIDATOR_MONITOR_ATTESTATION_SIMULATOR_HEAD_ATTESTER_HIT_TOTAL,
7575
metrics::VALIDATOR_MONITOR_ATTESTATION_SIMULATOR_TARGET_ATTESTER_HIT_TOTAL,
7676
metrics::VALIDATOR_MONITOR_ATTESTATION_SIMULATOR_SOURCE_ATTESTER_HIT_TOTAL,
7777
];
78-
let miss_prometheus_metrics = vec![
78+
let miss_prometheus_metrics = [
7979
metrics::VALIDATOR_MONITOR_ATTESTATION_SIMULATOR_HEAD_ATTESTER_MISS_TOTAL,
8080
metrics::VALIDATOR_MONITOR_ATTESTATION_SIMULATOR_TARGET_ATTESTER_MISS_TOTAL,
8181
metrics::VALIDATOR_MONITOR_ATTESTATION_SIMULATOR_SOURCE_ATTESTER_MISS_TOTAL,

beacon_node/beacon_chain/tests/attestation_verification.rs

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -431,10 +431,12 @@ impl GossipTester {
431431
.chain
432432
.verify_aggregated_attestation_for_gossip(&aggregate)
433433
.err()
434-
.expect(&format!(
435-
"{} should error during verify_aggregated_attestation_for_gossip",
436-
desc
437-
));
434+
.unwrap_or_else(|| {
435+
panic!(
436+
"{} should error during verify_aggregated_attestation_for_gossip",
437+
desc
438+
)
439+
});
438440
inspect_err(&self, err);
439441

440442
/*
@@ -449,10 +451,12 @@ impl GossipTester {
449451
.unwrap();
450452

451453
assert_eq!(results.len(), 2);
452-
let batch_err = results.pop().unwrap().err().expect(&format!(
453-
"{} should error during batch_verify_aggregated_attestations_for_gossip",
454-
desc
455-
));
454+
let batch_err = results.pop().unwrap().err().unwrap_or_else(|| {
455+
panic!(
456+
"{} should error during batch_verify_aggregated_attestations_for_gossip",
457+
desc
458+
)
459+
});
456460
inspect_err(&self, batch_err);
457461

458462
self
@@ -475,10 +479,12 @@ impl GossipTester {
475479
.chain
476480
.verify_unaggregated_attestation_for_gossip(&attn, Some(subnet_id))
477481
.err()
478-
.expect(&format!(
479-
"{} should error during verify_unaggregated_attestation_for_gossip",
480-
desc
481-
));
482+
.unwrap_or_else(|| {
483+
panic!(
484+
"{} should error during verify_unaggregated_attestation_for_gossip",
485+
desc
486+
)
487+
});
482488
inspect_err(&self, err);
483489

484490
/*
@@ -496,10 +502,12 @@ impl GossipTester {
496502
)
497503
.unwrap();
498504
assert_eq!(results.len(), 2);
499-
let batch_err = results.pop().unwrap().err().expect(&format!(
500-
"{} should error during batch_verify_unaggregated_attestations_for_gossip",
501-
desc
502-
));
505+
let batch_err = results.pop().unwrap().err().unwrap_or_else(|| {
506+
panic!(
507+
"{} should error during batch_verify_unaggregated_attestations_for_gossip",
508+
desc
509+
)
510+
});
503511
inspect_err(&self, batch_err);
504512

505513
self
@@ -816,7 +824,7 @@ async fn aggregated_gossip_verification() {
816824
let (index, sk) = tester.non_aggregator();
817825
*a = SignedAggregateAndProof::from_aggregate(
818826
index as u64,
819-
tester.valid_aggregate.message().aggregate().clone(),
827+
tester.valid_aggregate.message().aggregate(),
820828
None,
821829
&sk,
822830
&chain.canonical_head.cached_head().head_fork(),

beacon_node/beacon_chain/tests/bellatrix.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ async fn merge_with_terminal_block_hash_override() {
8282

8383
let block = &harness.chain.head_snapshot().beacon_block;
8484

85-
let execution_payload = block.message().body().execution_payload().unwrap().clone();
85+
let execution_payload = block.message().body().execution_payload().unwrap();
8686
if i == 0 {
8787
assert_eq!(execution_payload.block_hash(), genesis_pow_block_hash);
8888
}
@@ -207,15 +207,7 @@ async fn base_altair_bellatrix_with_terminal_block_after_fork() {
207207
harness.extend_slots(1).await;
208208

209209
let block = &harness.chain.head_snapshot().beacon_block;
210-
execution_payloads.push(
211-
block
212-
.message()
213-
.body()
214-
.execution_payload()
215-
.unwrap()
216-
.clone()
217-
.into(),
218-
);
210+
execution_payloads.push(block.message().body().execution_payload().unwrap().into());
219211
}
220212

221213
verify_execution_payload_chain(execution_payloads.as_slice());

beacon_node/beacon_chain/tests/payload_invalidation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ async fn invalid_payload_invalidates_parent() {
413413
rig.import_block(Payload::Valid).await; // Import a valid transition block.
414414
rig.move_to_first_justification(Payload::Syncing).await;
415415

416-
let roots = vec![
416+
let roots = [
417417
rig.import_block(Payload::Syncing).await,
418418
rig.import_block(Payload::Syncing).await,
419419
rig.import_block(Payload::Syncing).await,
@@ -1049,7 +1049,7 @@ async fn invalid_parent() {
10491049

10501050
// Ensure the block built atop an invalid payload is invalid for gossip.
10511051
assert!(matches!(
1052-
rig.harness.chain.clone().verify_block_for_gossip(block.clone().into()).await,
1052+
rig.harness.chain.clone().verify_block_for_gossip(block.clone()).await,
10531053
Err(BlockError::ParentExecutionPayloadInvalid { parent_root: invalid_root })
10541054
if invalid_root == parent_root
10551055
));

beacon_node/beacon_chain/tests/store_tests.rs

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ async fn long_skip() {
330330
final_blocks as usize,
331331
BlockStrategy::ForkCanonicalChainAt {
332332
previous_slot: Slot::new(initial_blocks),
333-
first_slot: Slot::new(initial_blocks + skip_slots as u64 + 1),
333+
first_slot: Slot::new(initial_blocks + skip_slots + 1),
334334
},
335335
AttestationStrategy::AllValidators,
336336
)
@@ -381,8 +381,7 @@ async fn randao_genesis_storage() {
381381
.beacon_state
382382
.randao_mixes()
383383
.iter()
384-
.find(|x| **x == genesis_value)
385-
.is_some());
384+
.any(|x| *x == genesis_value));
386385

387386
// Then upon adding one more block, it isn't
388387
harness.advance_slot();
@@ -393,14 +392,13 @@ async fn randao_genesis_storage() {
393392
AttestationStrategy::AllValidators,
394393
)
395394
.await;
396-
assert!(harness
395+
assert!(!harness
397396
.chain
398397
.head_snapshot()
399398
.beacon_state
400399
.randao_mixes()
401400
.iter()
402-
.find(|x| **x == genesis_value)
403-
.is_none());
401+
.any(|x| *x == genesis_value));
404402

405403
check_finalization(&harness, num_slots);
406404
check_split_slot(&harness, store);
@@ -1062,7 +1060,7 @@ fn check_shuffling_compatible(
10621060
let current_epoch_shuffling_is_compatible = harness.chain.shuffling_is_compatible(
10631061
&block_root,
10641062
head_state.current_epoch(),
1065-
&head_state,
1063+
head_state,
10661064
);
10671065

10681066
// Check for consistency with the more expensive shuffling lookup.
@@ -1102,7 +1100,7 @@ fn check_shuffling_compatible(
11021100
let previous_epoch_shuffling_is_compatible = harness.chain.shuffling_is_compatible(
11031101
&block_root,
11041102
head_state.previous_epoch(),
1105-
&head_state,
1103+
head_state,
11061104
);
11071105
harness
11081106
.chain
@@ -1130,14 +1128,11 @@ fn check_shuffling_compatible(
11301128

11311129
// Targeting two epochs before the current epoch should always return false
11321130
if head_state.current_epoch() >= 2 {
1133-
assert_eq!(
1134-
harness.chain.shuffling_is_compatible(
1135-
&block_root,
1136-
head_state.current_epoch() - 2,
1137-
&head_state
1138-
),
1139-
false
1140-
);
1131+
assert!(!harness.chain.shuffling_is_compatible(
1132+
&block_root,
1133+
head_state.current_epoch() - 2,
1134+
head_state
1135+
));
11411136
}
11421137
}
11431138
}
@@ -1939,7 +1934,7 @@ async fn prune_single_block_long_skip() {
19391934
2 * slots_per_epoch,
19401935
1,
19411936
2 * slots_per_epoch,
1942-
2 * slots_per_epoch as u64,
1937+
2 * slots_per_epoch,
19431938
1,
19441939
)
19451940
.await;
@@ -1965,23 +1960,23 @@ async fn prune_shared_skip_states_epoch_boundaries() {
19651960
pruning_test(slots_per_epoch - 1, 2, slots_per_epoch, 1, slots_per_epoch).await;
19661961
pruning_test(
19671962
2 * slots_per_epoch + slots_per_epoch / 2,
1968-
slots_per_epoch as u64 / 2,
1963+
slots_per_epoch / 2,
19691964
slots_per_epoch,
1970-
slots_per_epoch as u64 / 2 + 1,
1965+
slots_per_epoch / 2 + 1,
19711966
slots_per_epoch,
19721967
)
19731968
.await;
19741969
pruning_test(
19751970
2 * slots_per_epoch + slots_per_epoch / 2,
1976-
slots_per_epoch as u64 / 2,
1971+
slots_per_epoch / 2,
19771972
slots_per_epoch,
1978-
slots_per_epoch as u64 / 2 + 1,
1973+
slots_per_epoch / 2 + 1,
19791974
slots_per_epoch,
19801975
)
19811976
.await;
19821977
pruning_test(
19831978
2 * slots_per_epoch - 1,
1984-
slots_per_epoch as u64,
1979+
slots_per_epoch,
19851980
1,
19861981
0,
19871982
2 * slots_per_epoch,
@@ -2094,7 +2089,7 @@ async fn pruning_test(
20942089
);
20952090
check_chain_dump(
20962091
&harness,
2097-
(num_initial_blocks + num_canonical_middle_blocks + num_finalization_blocks + 1) as u64,
2092+
num_initial_blocks + num_canonical_middle_blocks + num_finalization_blocks + 1,
20982093
);
20992094

21002095
let all_canonical_states = harness

beacon_node/beacon_chain/tests/sync_committee_verification.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ fn get_valid_sync_committee_message_for_block(
7373
let head_state = harness.chain.head_beacon_state_cloned();
7474
let (signature, _) = harness
7575
.make_sync_committee_messages(&head_state, block_root, slot, relative_sync_committee)
76-
.get(0)
76+
.first()
7777
.expect("sync messages should exist")
7878
.get(message_index)
7979
.expect("first sync message should exist")
@@ -104,7 +104,7 @@ fn get_valid_sync_contribution(
104104
);
105105

106106
let (_, contribution_opt) = sync_contributions
107-
.get(0)
107+
.first()
108108
.expect("sync contributions should exist");
109109
let contribution = contribution_opt
110110
.as_ref()

beacon_node/beacon_chain/tests/tests.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ async fn find_reorgs() {
170170

171171
harness
172172
.extend_chain(
173-
num_blocks_produced as usize,
173+
num_blocks_produced,
174174
BlockStrategy::OnCanonicalHead,
175175
// No need to produce attestations for this test.
176176
AttestationStrategy::SomeValidators(vec![]),
@@ -203,7 +203,7 @@ async fn find_reorgs() {
203203
assert_eq!(
204204
find_reorg_slot(
205205
&harness.chain,
206-
&head_state,
206+
head_state,
207207
harness.chain.head_beacon_block().canonical_root()
208208
),
209209
head_slot
@@ -503,7 +503,6 @@ async fn unaggregated_attestations_added_to_fork_choice_some_none() {
503503
.unwrap();
504504

505505
let validator_slots: Vec<(usize, Slot)> = (0..VALIDATOR_COUNT)
506-
.into_iter()
507506
.map(|validator_index| {
508507
let slot = state
509508
.get_attestation_duties(validator_index, RelativeEpoch::Current)

beacon_node/http_api/tests/broadcast_validation_tests.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ pub async fn consensus_gossip() {
322322
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
323323
pub async fn consensus_partial_pass_only_consensus() {
324324
/* this test targets gossip-level validation */
325-
let validation_level: Option<BroadcastValidation> = Some(BroadcastValidation::Consensus);
325+
let validation_level = BroadcastValidation::Consensus;
326326

327327
// Validator count needs to be at least 32 or proposer boost gets set to 0 when computing
328328
// `validator_count // 32`.
@@ -378,7 +378,7 @@ pub async fn consensus_partial_pass_only_consensus() {
378378
tester.harness.chain.clone(),
379379
&channel.0,
380380
test_logger,
381-
validation_level.unwrap(),
381+
validation_level,
382382
StatusCode::ACCEPTED,
383383
network_globals,
384384
)
@@ -615,8 +615,7 @@ pub async fn equivocation_gossip() {
615615
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
616616
pub async fn equivocation_consensus_late_equivocation() {
617617
/* this test targets gossip-level validation */
618-
let validation_level: Option<BroadcastValidation> =
619-
Some(BroadcastValidation::ConsensusAndEquivocation);
618+
let validation_level = BroadcastValidation::ConsensusAndEquivocation;
620619

621620
// Validator count needs to be at least 32 or proposer boost gets set to 0 when computing
622621
// `validator_count // 32`.
@@ -671,7 +670,7 @@ pub async fn equivocation_consensus_late_equivocation() {
671670
tester.harness.chain,
672671
&channel.0,
673672
test_logger,
674-
validation_level.unwrap(),
673+
validation_level,
675674
StatusCode::ACCEPTED,
676675
network_globals,
677676
)
@@ -1228,8 +1227,7 @@ pub async fn blinded_equivocation_gossip() {
12281227
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
12291228
pub async fn blinded_equivocation_consensus_late_equivocation() {
12301229
/* this test targets gossip-level validation */
1231-
let validation_level: Option<BroadcastValidation> =
1232-
Some(BroadcastValidation::ConsensusAndEquivocation);
1230+
let validation_level = BroadcastValidation::ConsensusAndEquivocation;
12331231

12341232
// Validator count needs to be at least 32 or proposer boost gets set to 0 when computing
12351233
// `validator_count // 32`.
@@ -1311,7 +1309,7 @@ pub async fn blinded_equivocation_consensus_late_equivocation() {
13111309
tester.harness.chain,
13121310
&channel.0,
13131311
test_logger,
1314-
validation_level.unwrap(),
1312+
validation_level,
13151313
StatusCode::ACCEPTED,
13161314
network_globals,
13171315
)
@@ -1465,8 +1463,8 @@ pub async fn block_seen_on_gossip_with_some_blobs() {
14651463
"need at least 2 blobs for partial reveal"
14661464
);
14671465

1468-
let partial_kzg_proofs = vec![blobs.0.get(0).unwrap().clone()];
1469-
let partial_blobs = vec![blobs.1.get(0).unwrap().clone()];
1466+
let partial_kzg_proofs = vec![*blobs.0.first().unwrap()];
1467+
let partial_blobs = vec![blobs.1.first().unwrap().clone()];
14701468

14711469
// Simulate the block being seen on gossip.
14721470
block

0 commit comments

Comments
 (0)