Skip to content

chore: update rust toolchain, migrate to 2024 edition #3535

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions crates/pallet-domains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2210,11 +2210,10 @@ impl<T: Config> Pallet<T> {
// NOTE: during `validate_unsigned` this is implicitly checked within `is_proof_of_time_valid` since we
// are using quick verification which will return `false` if the `proof-of-time` is not seem by the node
// before.
if pre_dispatch {
if let Some(future_slot) = T::BlockSlot::future_slot(current_block_number) {
if pre_dispatch
&& let Some(future_slot) = T::BlockSlot::future_slot(current_block_number) {
ensure!(slot_number <= *future_slot, BundleError::SlotInTheFuture)
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Command can be simplified to:

cargo clippy --locked --all-targets --features runtime-benchmarks,cuda --fix --all

I couldn't automatically compile/fix cuda or x86_64/aes because I don't have the OS/hardware, so I reviewed them manually instead.


// Check if the bundle is built too long time ago and beyond `T::BundleLongevity` number of consensus blocks.
let produced_after_block_number =
Expand Down Expand Up @@ -2662,11 +2661,10 @@ impl<T: Config> Pallet<T> {
domain_id: DomainId,
operator_id: &OperatorId,
) -> Result<(BalanceOf<T>, BalanceOf<T>), BundleError> {
if let Some(pending_election_params) = LastEpochStakingDistribution::<T>::get(domain_id) {
if let Some(operator_stake) = pending_election_params.operators.get(operator_id) {
if let Some(pending_election_params) = LastEpochStakingDistribution::<T>::get(domain_id)
&& let Some(operator_stake) = pending_election_params.operators.get(operator_id) {
return Ok((*operator_stake, pending_election_params.total_domain_stake));
}
}
let domain_stake_summary =
DomainStakingSummary::<T>::get(domain_id).ok_or(BundleError::InvalidDomainId)?;
let operator_stake = domain_stake_summary
Expand Down
5 changes: 2 additions & 3 deletions crates/pallet-rewards/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,8 @@ impl<T: Config> Pallet<T> {
}
}

if let Some(block_author) = maybe_block_author {
if !block_reward.is_zero() {
if let Some(block_author) = maybe_block_author
&& !block_reward.is_zero() {
let _imbalance = T::Currency::deposit_creating(&block_author, block_reward);
T::OnReward::on_reward(block_author.clone(), block_reward);

Expand All @@ -320,7 +320,6 @@ impl<T: Config> Pallet<T> {
reward: block_reward,
});
}
}

if old_remaining_issuance != new_remaining_issuance {
RemainingIssuance::<T>::put(new_remaining_issuance);
Expand Down
39 changes: 15 additions & 24 deletions crates/pallet-subspace/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -788,15 +788,14 @@ impl<T: Config> Pallet<T> {
.voting_next
.replace(next_voting_solution_range);

if let Some(solution_range_for_rewards) = EnableRewardsBelowSolutionRange::<T>::get() {
if next_solution_range <= solution_range_for_rewards {
if let Some(solution_range_for_rewards) = EnableRewardsBelowSolutionRange::<T>::get()
&& next_solution_range <= solution_range_for_rewards {
EnableRewardsBelowSolutionRange::<T>::take();

let next_block_number =
frame_system::Pallet::<T>::current_block_number() + One::one();
EnableRewards::<T>::put(next_block_number);
}
}
});

EraStartSlot::<T>::put(current_slot);
Expand Down Expand Up @@ -948,8 +947,8 @@ impl<T: Config> Pallet<T> {
);

// Update target slot for entropy injection once we know it
if let Some(entropy_source_block_number) = maybe_entropy_source_block_number {
if let Some(entropy_value) = entropy.get_mut(&entropy_source_block_number) {
if let Some(entropy_source_block_number) = maybe_entropy_source_block_number
&& let Some(entropy_value) = entropy.get_mut(&entropy_source_block_number) {
let target_slot = pre_digest
.slot()
.saturating_add(pot_entropy_injection_delay);
Expand All @@ -965,7 +964,6 @@ impl<T: Config> Pallet<T> {
PotSlotIterations::<T>::put(pot_slot_iterations);
}
}
}

PotEntropy::<T>::put(entropy.clone());
}
Expand Down Expand Up @@ -1003,14 +1001,13 @@ impl<T: Config> Pallet<T> {
}

// Clean up old values we'll no longer need
if let Some(entry) = entropy.first_entry() {
if let Some(target_slot) = entry.get().target_slot
if let Some(entry) = entropy.first_entry()
&& let Some(target_slot) = entry.get().target_slot
&& target_slot < current_slot
{
entry.remove();
PotEntropy::<T>::put(entropy);
}
}
}
}

Expand Down Expand Up @@ -1598,19 +1595,18 @@ fn check_vote<T: Config>(
.as_ref()
== Some(&key);

if !is_equivocating {
if let Some((_reward_address, signature)) = ParentBlockVoters::<T>::get().get(&key) {
if !is_equivocating
&& let Some((_reward_address, signature)) = ParentBlockVoters::<T>::get().get(&key) {
if signature != &signed_vote.signature {
is_equivocating = true;
} else {
// The same vote should never be included more than once
return Err(CheckVoteError::DuplicateVote);
}
}
}

if !is_equivocating {
if let Some((_reward_address, signature)) =
if !is_equivocating
&& let Some((_reward_address, signature)) =
CurrentBlockVoters::<T>::get().unwrap_or_default().get(&key)
{
if signature != &signed_vote.signature {
Expand All @@ -1620,7 +1616,6 @@ fn check_vote<T: Config>(
return Err(CheckVoteError::DuplicateVote);
}
}
}

if pre_dispatch {
// During `pre_dispatch` call put farmer into the list of reward receivers.
Expand Down Expand Up @@ -1648,12 +1643,10 @@ fn check_vote<T: Config>(
CurrentBlockAuthorInfo::<T>::mutate(|maybe_info| {
if let Some((public_key, _sector_index, _piece_offset, _chunk, _slot, reward_address)) =
maybe_info
{
if public_key == &offender {
&& public_key == &offender {
// Revoke reward for block author
reward_address.take();
}
}
});

CurrentBlockVoters::<T>::mutate(|current_reward_receivers| {
Expand Down Expand Up @@ -1740,11 +1733,10 @@ impl<T: Config> subspace_runtime_primitives::FindBlockRewardAddress<T::AccountId
CurrentBlockAuthorInfo::<T>::get().and_then(
|(_public_key, _sector_index, _piece_offset, _chunk, _slot, reward_address)| {
// Rewards might be disabled, in which case no block reward
if let Some(height) = EnableRewards::<T>::get() {
if frame_system::Pallet::<T>::current_block_number() >= height {
if let Some(height) = EnableRewards::<T>::get()
&& frame_system::Pallet::<T>::current_block_number() >= height {
return reward_address;
}
}

None
},
Expand All @@ -1755,8 +1747,8 @@ impl<T: Config> subspace_runtime_primitives::FindBlockRewardAddress<T::AccountId
impl<T: Config> subspace_runtime_primitives::FindVotingRewardAddresses<T::AccountId> for Pallet<T> {
fn find_voting_reward_addresses() -> Vec<T::AccountId> {
// Rewards might be disabled, in which case no voting reward
if let Some(height) = EnableRewards::<T>::get() {
if frame_system::Pallet::<T>::current_block_number() >= height {
if let Some(height) = EnableRewards::<T>::get()
&& frame_system::Pallet::<T>::current_block_number() >= height {
// It is possible that this is called during initialization when current block
// voters are already moved into parent block voters, handle it accordingly
return CurrentBlockVoters::<T>::get()
Expand All @@ -1765,7 +1757,6 @@ impl<T: Config> subspace_runtime_primitives::FindVotingRewardAddresses<T::Accoun
.filter_map(|(reward_address, _signature)| reward_address)
.collect();
}
}

Vec::new()
}
Expand Down
21 changes: 8 additions & 13 deletions crates/sc-consensus-subspace-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,11 +527,10 @@ where
// Wait for solutions and transform proposed proof of space solutions into
// data structure `sc-consensus-subspace` expects
let forward_signature_fut = async move {
if let Ok(reward_signature) = response_receiver.await {
if let Some(signature) = reward_signature.signature {
if let Ok(reward_signature) = response_receiver.await
&& let Some(signature) = reward_signature.signature {
let _ = signature_sender.unbounded_send(signature);
}
}
};

// Run above future with timeout
Expand Down Expand Up @@ -576,11 +575,10 @@ where
// multiple (https://github.com/paritytech/jsonrpsee/issues/452)
let mut reward_signature_senders = reward_signature_senders.lock();

if reward_signature_senders.current_hash == reward_signature.hash.into() {
if let Some(mut sender) = reward_signature_senders.senders.pop() {
if reward_signature_senders.current_hash == reward_signature.hash.into()
&& let Some(mut sender) = reward_signature_senders.senders.pop() {
let _ = sender.send(reward_signature);
}
}

Ok(())
}
Expand Down Expand Up @@ -702,13 +700,11 @@ where
.flatten()
};

if let Some(sender) = maybe_sender {
if let Err(error) = sender.unbounded_send(()) {
if !error.is_closed() {
if let Some(sender) = maybe_sender
&& let Err(error) = sender.unbounded_send(())
&& !error.is_closed() {
warn!("Failed to acknowledge archived segment: {error}");
}
}
}

debug!(%segment_index, "Acknowledged archived segment.");

Expand Down Expand Up @@ -806,8 +802,7 @@ where
);

return Err(Error::StringError(format!(
"Request limit ({}) exceed the server limit: {} ",
limit, MAX_SEGMENT_HEADERS_PER_REQUEST
"Request limit ({limit}) exceed the server limit: {MAX_SEGMENT_HEADERS_PER_REQUEST} "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't need to be fixed in this PR, but there's an odd extra space at the end of this log message. A search and replace could fix them all at once.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I found more than one. After merging this pull request, I will submit a separate pull request to fix them.

)));
};

Expand Down
6 changes: 2 additions & 4 deletions crates/sc-consensus-subspace/src/archiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,7 @@ where

if segment_index != last_segment_index + SegmentIndex::ONE {
let error = format!(
"Segment index {} must strictly follow {}, can't store segment header",
segment_index, last_segment_index
"Segment index {segment_index} must strictly follow {last_segment_index}, can't store segment header"
);
return Err(sp_blockchain::Error::Application(error.into()));
}
Expand Down Expand Up @@ -1162,8 +1161,7 @@ where
if parent_block_hash != best_archived_block_hash {
let error = format!(
"Attempt to switch to a different fork beyond archiving depth, \
can't do it: parent block hash {}, best archived block hash {}",
parent_block_hash, best_archived_block_hash
can't do it: parent block hash {parent_block_hash}, best archived block hash {best_archived_block_hash}"
);
return Err(sp_blockchain::Error::Consensus(sp_consensus::Error::Other(
error.into(),
Expand Down
5 changes: 2 additions & 3 deletions crates/sc-consensus-subspace/src/block_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,11 @@ where
let parent_hash = *header.parent_hash();

let pre_digest = &subspace_digest_items.pre_digest;
if let Some(root_plot_public_key) = root_plot_public_key {
if &pre_digest.solution().public_key != root_plot_public_key {
if let Some(root_plot_public_key) = root_plot_public_key
&& &pre_digest.solution().public_key != root_plot_public_key {
// Only root plot public key is allowed.
return Err(Error::OnlyRootPlotPublicKeyAllowed);
}
}

let parent_header = self
.client
Expand Down
13 changes: 5 additions & 8 deletions crates/sc-consensus-subspace/src/slot_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,13 +499,12 @@ where
let mut maybe_pre_digest = None;

while let Some(solution) = solution_receiver.next().await {
if let Some(root_plot_public_key) = &maybe_root_plot_public_key {
if &solution.public_key != root_plot_public_key {
if let Some(root_plot_public_key) = &maybe_root_plot_public_key
&& &solution.public_key != root_plot_public_key {
// Only root plot public key is allowed, no need to even try to claim block or
// vote.
continue;
}
}

let sector_id = SectorId::new(
solution.public_key.hash(),
Expand Down Expand Up @@ -688,8 +687,8 @@ where
}

fn should_backoff(&self, slot: Slot, chain_head: &Block::Header) -> bool {
if let Some(strategy) = &self.backoff_authoring_blocks {
if let Ok(chain_head_slot) = extract_pre_digest(chain_head).map(|digest| digest.slot())
if let Some(strategy) = &self.backoff_authoring_blocks
&& let Ok(chain_head_slot) = extract_pre_digest(chain_head).map(|digest| digest.slot())
{
return strategy.should_backoff(
*chain_head.number(),
Expand All @@ -699,7 +698,6 @@ where
self.logging_target(),
);
}
}
false
}

Expand Down Expand Up @@ -889,8 +887,7 @@ where
}

Err(ConsensusError::CannotSign(format!(
"Farmer didn't sign reward. Key: {:?}",
public_key
"Farmer didn't sign reward. Key: {public_key:?}"
)))
}
}
Expand Down
5 changes: 2 additions & 3 deletions crates/sc-proof-of-time/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,11 @@ pub async fn start_slot_worker<Block, Client, SC, Worker, SO, CIDP>(
}
},
};
if let Some(last_proven_slot) = maybe_last_proven_slot {
if last_proven_slot >= slot {
if let Some(last_proven_slot) = maybe_last_proven_slot
&& last_proven_slot >= slot {
// Already processed
continue;
}
}
maybe_last_proven_slot.replace(slot);

worker.0.on_proof(slot, checkpoints);
Expand Down
5 changes: 2 additions & 3 deletions crates/sc-proof-of-time/src/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,14 @@ where
.spawn(move || {
let _guard = span.enter();

if let Some(core) = timekeeper_cpu_cores.into_iter().next() {
if !core_affinity::set_for_current(CoreId { id: core }) {
if let Some(core) = timekeeper_cpu_cores.into_iter().next()
&& !core_affinity::set_for_current(CoreId { id: core }) {
warn!(
%core,
"Failed to set core affinity, timekeeper will run on random CPU \
core",
);
}
}

if let Err(error) = set_current_thread_priority(ThreadPriority::Max) {
warn!(
Expand Down
5 changes: 2 additions & 3 deletions crates/sc-proof-of-time/src/source/gossip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@ where
);

if let Some(proofs) = self.gossip_cache.get_or_insert(sender, Default::default) {
if proofs.len() == GOSSIP_CACHE_PER_PEER_SIZE {
if let Some(proof) = proofs.pop_front() {
if proofs.len() == GOSSIP_CACHE_PER_PEER_SIZE
&& let Some(proof) = proofs.pop_front() {
trace!(
%sender,
slot = %proof.slot,
Expand All @@ -279,7 +279,6 @@ where
.lock()
.report(sender, rep::GOSSIP_TOO_MANY_PROOFS);
}
}
proofs.push_back(proof);
return;
}
Expand Down
5 changes: 2 additions & 3 deletions crates/sc-proof-of-time/src/source/timekeeper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,10 @@ pub(super) fn run_timekeeper(
)
.unwrap_or_else(|next_slot_input| next_slot_input);

if let Err(error) = proofs_sender.try_send(proof) {
if let Err(error) = block_on(proofs_sender.send(error.into_inner())) {
if let Err(error) = proofs_sender.try_send(proof)
&& let Err(error) = block_on(proofs_sender.send(error.into_inner())) {
debug!(%error, "Couldn't send checkpoints, channel is closed");
return Ok(());
}
}
}
}
8 changes: 3 additions & 5 deletions crates/sp-domains-fraud-proof/src/verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -627,13 +627,11 @@ where

// Fast path to check if the fraud proof is targeting a bad receipt that claim a non-exist extrinsic
// is invalid
if let Some(invalid_extrinsic_index) = targeted_invalid_bundle_entry.invalid_extrinsic_index() {
if let InvalidBundlesProofData::Bundle(bundle_with_proof) = proof_data {
if bundle_with_proof.bundle.extrinsics.len() as u32 <= invalid_extrinsic_index {
if let Some(invalid_extrinsic_index) = targeted_invalid_bundle_entry.invalid_extrinsic_index()
&& let InvalidBundlesProofData::Bundle(bundle_with_proof) = proof_data
&& bundle_with_proof.bundle.extrinsics.len() as u32 <= invalid_extrinsic_index {
return Ok(());
}
}
}

match &invalid_bundle_type {
InvalidBundleType::OutOfRangeTx(extrinsic_index) => {
Expand Down
Loading