Skip to content

Commit ce03b5f

Browse files
committed
chore: run cargo -Zgitoxide -Zgit clippy --locked --all-targets --features runtime-benchmarks,cuda --fix --all -- -D warnings
1 parent a6a202f commit ce03b5f

51 files changed

Lines changed: 164 additions & 247 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

crates/pallet-domains/src/lib.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2212,11 +2212,10 @@ impl<T: Config> Pallet<T> {
22122212
// NOTE: during `validate_unsigned` this is implicitly checked within `is_proof_of_time_valid` since we
22132213
// are using quick verification which will return `false` if the `proof-of-time` is not seem by the node
22142214
// before.
2215-
if pre_dispatch {
2216-
if let Some(future_slot) = T::BlockSlot::future_slot(current_block_number) {
2215+
if pre_dispatch
2216+
&& let Some(future_slot) = T::BlockSlot::future_slot(current_block_number) {
22172217
ensure!(slot_number <= *future_slot, BundleError::SlotInTheFuture)
22182218
}
2219-
}
22202219

22212220
// Check if the bundle is built too long time ago and beyond `T::BundleLongevity` number of consensus blocks.
22222221
let produced_after_block_number =
@@ -2673,11 +2672,10 @@ impl<T: Config> Pallet<T> {
26732672
domain_id: DomainId,
26742673
operator_id: &OperatorId,
26752674
) -> Result<(BalanceOf<T>, BalanceOf<T>), BundleError> {
2676-
if let Some(pending_election_params) = LastEpochStakingDistribution::<T>::get(domain_id) {
2677-
if let Some(operator_stake) = pending_election_params.operators.get(operator_id) {
2675+
if let Some(pending_election_params) = LastEpochStakingDistribution::<T>::get(domain_id)
2676+
&& let Some(operator_stake) = pending_election_params.operators.get(operator_id) {
26782677
return Ok((*operator_stake, pending_election_params.total_domain_stake));
26792678
}
2680-
}
26812679
let domain_stake_summary =
26822680
DomainStakingSummary::<T>::get(domain_id).ok_or(BundleError::InvalidDomainId)?;
26832681
let operator_stake = domain_stake_summary

crates/pallet-subspace/src/lib.rs

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -788,15 +788,14 @@ impl<T: Config> Pallet<T> {
788788
.voting_next
789789
.replace(next_voting_solution_range);
790790

791-
if let Some(solution_range_for_rewards) = EnableRewardsBelowSolutionRange::<T>::get() {
792-
if next_solution_range <= solution_range_for_rewards {
791+
if let Some(solution_range_for_rewards) = EnableRewardsBelowSolutionRange::<T>::get()
792+
&& next_solution_range <= solution_range_for_rewards {
793793
EnableRewardsBelowSolutionRange::<T>::take();
794794

795795
let next_block_number =
796796
frame_system::Pallet::<T>::current_block_number() + One::one();
797797
EnableRewards::<T>::put(next_block_number);
798798
}
799-
}
800799
});
801800

802801
EraStartSlot::<T>::put(current_slot);
@@ -950,8 +949,8 @@ impl<T: Config> Pallet<T> {
950949
);
951950

952951
// Update target slot for entropy injection once we know it
953-
if let Some(entropy_source_block_number) = maybe_entropy_source_block_number {
954-
if let Some(entropy_value) = entropy.get_mut(&entropy_source_block_number) {
952+
if let Some(entropy_source_block_number) = maybe_entropy_source_block_number
953+
&& let Some(entropy_value) = entropy.get_mut(&entropy_source_block_number) {
955954
let target_slot = pre_digest
956955
.slot()
957956
.saturating_add(pot_entropy_injection_delay);
@@ -973,7 +972,6 @@ impl<T: Config> Pallet<T> {
973972
PotSlotIterations::<T>::put(pot_slot_iterations);
974973
}
975974
}
976-
}
977975

978976
PotEntropy::<T>::put(entropy.clone());
979977
}
@@ -1014,14 +1012,13 @@ impl<T: Config> Pallet<T> {
10141012
}
10151013

10161014
// Clean up old values we'll no longer need
1017-
if let Some(entry) = entropy.first_entry() {
1018-
if let Some(target_slot) = entry.get().target_slot
1015+
if let Some(entry) = entropy.first_entry()
1016+
&& let Some(target_slot) = entry.get().target_slot
10191017
&& target_slot < current_slot
10201018
{
10211019
entry.remove();
10221020
PotEntropy::<T>::put(entropy);
10231021
}
1024-
}
10251022
}
10261023
}
10271024

@@ -1636,19 +1633,18 @@ fn check_vote<T: Config>(
16361633
.as_ref()
16371634
== Some(&key);
16381635

1639-
if !is_equivocating {
1640-
if let Some((_reward_address, signature)) = ParentBlockVoters::<T>::get().get(&key) {
1636+
if !is_equivocating
1637+
&& let Some((_reward_address, signature)) = ParentBlockVoters::<T>::get().get(&key) {
16411638
if signature != &signed_vote.signature {
16421639
is_equivocating = true;
16431640
} else {
16441641
// The same vote should never be included more than once
16451642
return Err(CheckVoteError::DuplicateVote);
16461643
}
16471644
}
1648-
}
16491645

1650-
if !is_equivocating {
1651-
if let Some((_reward_address, signature)) =
1646+
if !is_equivocating
1647+
&& let Some((_reward_address, signature)) =
16521648
CurrentBlockVoters::<T>::get().unwrap_or_default().get(&key)
16531649
{
16541650
if signature != &signed_vote.signature {
@@ -1658,7 +1654,6 @@ fn check_vote<T: Config>(
16581654
return Err(CheckVoteError::DuplicateVote);
16591655
}
16601656
}
1661-
}
16621657

16631658
if pre_dispatch {
16641659
// During `pre_dispatch` call put farmer into the list of reward receivers.
@@ -1686,12 +1681,10 @@ fn check_vote<T: Config>(
16861681
CurrentBlockAuthorInfo::<T>::mutate(|maybe_info| {
16871682
if let Some((public_key, _sector_index, _piece_offset, _chunk, _slot, reward_address)) =
16881683
maybe_info
1689-
{
1690-
if public_key == &offender {
1684+
&& public_key == &offender {
16911685
// Revoke reward for block author
16921686
reward_address.take();
16931687
}
1694-
}
16951688
});
16961689

16971690
CurrentBlockVoters::<T>::mutate(|current_reward_receivers| {
@@ -1778,11 +1771,10 @@ impl<T: Config> subspace_runtime_primitives::FindBlockRewardAddress<T::AccountId
17781771
CurrentBlockAuthorInfo::<T>::get().and_then(
17791772
|(_public_key, _sector_index, _piece_offset, _chunk, _slot, reward_address)| {
17801773
// Rewards might be disabled, in which case no block reward
1781-
if let Some(height) = EnableRewards::<T>::get() {
1782-
if frame_system::Pallet::<T>::current_block_number() >= height {
1774+
if let Some(height) = EnableRewards::<T>::get()
1775+
&& frame_system::Pallet::<T>::current_block_number() >= height {
17831776
return reward_address;
17841777
}
1785-
}
17861778

17871779
None
17881780
},
@@ -1793,8 +1785,8 @@ impl<T: Config> subspace_runtime_primitives::FindBlockRewardAddress<T::AccountId
17931785
impl<T: Config> subspace_runtime_primitives::FindVotingRewardAddresses<T::AccountId> for Pallet<T> {
17941786
fn find_voting_reward_addresses() -> Vec<T::AccountId> {
17951787
// Rewards might be disabled, in which case no voting reward
1796-
if let Some(height) = EnableRewards::<T>::get() {
1797-
if frame_system::Pallet::<T>::current_block_number() >= height {
1788+
if let Some(height) = EnableRewards::<T>::get()
1789+
&& frame_system::Pallet::<T>::current_block_number() >= height {
17981790
// It is possible that this is called during initialization when current block
17991791
// voters are already moved into parent block voters, handle it accordingly
18001792
return CurrentBlockVoters::<T>::get()
@@ -1803,7 +1795,6 @@ impl<T: Config> subspace_runtime_primitives::FindVotingRewardAddresses<T::Accoun
18031795
.filter_map(|(reward_address, _signature)| reward_address)
18041796
.collect();
18051797
}
1806-
}
18071798

18081799
Vec::new()
18091800
}

crates/sc-consensus-subspace-rpc/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -806,8 +806,7 @@ where
806806
);
807807

808808
return Err(Error::StringError(format!(
809-
"Request limit ({}) exceed the server limit: {} ",
810-
limit, MAX_SEGMENT_HEADERS_PER_REQUEST
809+
"Request limit ({limit}) exceed the server limit: {MAX_SEGMENT_HEADERS_PER_REQUEST} "
811810
)));
812811
};
813812

crates/sc-consensus-subspace/src/archiver.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,7 @@ where
196196

197197
if segment_index != last_segment_index + SegmentIndex::ONE {
198198
let error = format!(
199-
"Segment index {} must strictly follow {}, can't store segment header",
200-
segment_index, last_segment_index
199+
"Segment index {segment_index} must strictly follow {last_segment_index}, can't store segment header"
201200
);
202201
return Err(sp_blockchain::Error::Application(error.into()));
203202
}
@@ -1162,8 +1161,7 @@ where
11621161
if parent_block_hash != best_archived_block_hash {
11631162
let error = format!(
11641163
"Attempt to switch to a different fork beyond archiving depth, \
1165-
can't do it: parent block hash {}, best archived block hash {}",
1166-
parent_block_hash, best_archived_block_hash
1164+
can't do it: parent block hash {parent_block_hash}, best archived block hash {best_archived_block_hash}"
11671165
);
11681166
return Err(sp_blockchain::Error::Consensus(sp_consensus::Error::Other(
11691167
error.into(),

crates/sc-consensus-subspace/src/block_import.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,12 +332,11 @@ where
332332
let parent_hash = *header.parent_hash();
333333

334334
let pre_digest = &subspace_digest_items.pre_digest;
335-
if let Some(root_plot_public_key) = root_plot_public_key {
336-
if &pre_digest.solution().public_key != root_plot_public_key {
335+
if let Some(root_plot_public_key) = root_plot_public_key
336+
&& &pre_digest.solution().public_key != root_plot_public_key {
337337
// Only root plot public key is allowed.
338338
return Err(Error::OnlyRootPlotPublicKeyAllowed);
339339
}
340-
}
341340

342341
let parent_header = self
343342
.client

crates/sc-consensus-subspace/src/slot_worker.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -499,13 +499,12 @@ where
499499
let mut maybe_pre_digest = None;
500500

501501
while let Some(solution) = solution_receiver.next().await {
502-
if let Some(root_plot_public_key) = &maybe_root_plot_public_key {
503-
if &solution.public_key != root_plot_public_key {
502+
if let Some(root_plot_public_key) = &maybe_root_plot_public_key
503+
&& &solution.public_key != root_plot_public_key {
504504
// Only root plot public key is allowed, no need to even try to claim block or
505505
// vote.
506506
continue;
507507
}
508-
}
509508

510509
let sector_id = SectorId::new(
511510
solution.public_key.hash(),
@@ -688,8 +687,8 @@ where
688687
}
689688

690689
fn should_backoff(&self, slot: Slot, chain_head: &Block::Header) -> bool {
691-
if let Some(strategy) = &self.backoff_authoring_blocks {
692-
if let Ok(chain_head_slot) = extract_pre_digest(chain_head).map(|digest| digest.slot())
690+
if let Some(strategy) = &self.backoff_authoring_blocks
691+
&& let Ok(chain_head_slot) = extract_pre_digest(chain_head).map(|digest| digest.slot())
693692
{
694693
return strategy.should_backoff(
695694
*chain_head.number(),
@@ -699,7 +698,6 @@ where
699698
self.logging_target(),
700699
);
701700
}
702-
}
703701
false
704702
}
705703

@@ -889,8 +887,7 @@ where
889887
}
890888

891889
Err(ConsensusError::CannotSign(format!(
892-
"Farmer didn't sign reward. Key: {:?}",
893-
public_key
890+
"Farmer didn't sign reward. Key: {public_key:?}"
894891
)))
895892
}
896893
}

crates/sc-proof-of-time/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,11 @@ pub async fn start_slot_worker<Block, Client, SC, Worker, SO, CIDP>(
9090
}
9191
},
9292
};
93-
if let Some(last_proven_slot) = maybe_last_proven_slot {
94-
if last_proven_slot >= slot {
93+
if let Some(last_proven_slot) = maybe_last_proven_slot
94+
&& last_proven_slot >= slot {
9595
// Already processed
9696
continue;
9797
}
98-
}
9998
maybe_last_proven_slot.replace(slot);
10099

101100
worker.0.on_proof(slot, checkpoints);

crates/sc-proof-of-time/src/source.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,14 @@ where
144144
.spawn(move || {
145145
let _guard = span.enter();
146146

147-
if let Some(core) = timekeeper_cpu_cores.into_iter().next() {
148-
if !core_affinity::set_for_current(CoreId { id: core }) {
147+
if let Some(core) = timekeeper_cpu_cores.into_iter().next()
148+
&& !core_affinity::set_for_current(CoreId { id: core }) {
149149
warn!(
150150
%core,
151151
"Failed to set core affinity, timekeeper will run on random CPU \
152152
core",
153153
);
154154
}
155-
}
156155

157156
if let Err(error) = set_current_thread_priority(ThreadPriority::Max) {
158157
warn!(

crates/sc-proof-of-time/src/source/gossip.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,8 @@ where
266266
);
267267

268268
if let Some(proofs) = self.gossip_cache.get_or_insert(sender, Default::default) {
269-
if proofs.len() == GOSSIP_CACHE_PER_PEER_SIZE {
270-
if let Some(proof) = proofs.pop_front() {
269+
if proofs.len() == GOSSIP_CACHE_PER_PEER_SIZE
270+
&& let Some(proof) = proofs.pop_front() {
271271
trace!(
272272
%sender,
273273
slot = %proof.slot,
@@ -279,7 +279,6 @@ where
279279
.lock()
280280
.report(sender, rep::GOSSIP_TOO_MANY_PROOFS);
281281
}
282-
}
283282
proofs.push_back(proof);
284283
return;
285284
}

crates/sc-proof-of-time/src/source/timekeeper.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,10 @@ pub(super) fn run_timekeeper(
6161
)
6262
.unwrap_or_else(|next_slot_input| next_slot_input);
6363

64-
if let Err(error) = proofs_sender.try_send(proof) {
65-
if let Err(error) = block_on(proofs_sender.send(error.into_inner())) {
64+
if let Err(error) = proofs_sender.try_send(proof)
65+
&& let Err(error) = block_on(proofs_sender.send(error.into_inner())) {
6666
debug!(%error, "Couldn't send checkpoints, channel is closed");
6767
return Ok(());
6868
}
69-
}
7069
}
7170
}

0 commit comments

Comments
 (0)