pallet-authorship: Fixing some nitpicks (#9095)

As reviewing the pallet yesterday, I have found some nitpicks that I
fixed.
This commit is contained in:
Bastian Köcher
2021-06-13 12:41:13 +01:00
committed by GitHub
parent df0a50f966
commit 45f8b6e91f
+5 -10
View File
@@ -27,7 +27,7 @@ use frame_support::{
inherent::{InherentData, ProvideInherent, InherentIdentifier},
};
use codec::{Encode, Decode};
use sp_runtime::traits::{Header as HeaderT, One, Zero};
use sp_runtime::traits::{Header as HeaderT, One, Saturating};
use sp_authorship::{INHERENT_IDENTIFIER, UnclesInherentData, InherentError};
const MAX_UNCLES: usize = 10;
@@ -298,11 +298,7 @@ impl<T: Config> Pallet<T> {
let (minimum_height, maximum_height) = {
let uncle_generations = T::UncleGenerations::get();
let min = if now >= uncle_generations {
now - uncle_generations
} else {
Zero::zero()
};
let min = now.saturating_sub(uncle_generations);
(min, now)
};
@@ -329,7 +325,7 @@ impl<T: Config> Pallet<T> {
return Err(Error::<T>::OldUncle.into());
}
let duplicate = existing_uncles.into_iter().find(|h| **h == hash).is_some();
let duplicate = existing_uncles.into_iter().any(|h| *h == hash);
let in_chain = <frame_system::Pallet<T>>::block_hash(uncle.number()) == hash;
if duplicate || in_chain {
@@ -341,15 +337,14 @@ impl<T: Config> Pallet<T> {
}
fn prune_old_uncles(minimum_height: T::BlockNumber) {
let mut uncles = <Uncles<T>>::get();
let uncles = <Uncles<T>>::get();
let prune_entries = uncles.iter().take_while(|item| match item {
UncleEntryItem::Uncle(_, _) => true,
UncleEntryItem::InclusionHeight(height) => height < &minimum_height,
});
let prune_index = prune_entries.count();
let _ = uncles.drain(..prune_index);
<Uncles<T>>::put(uncles);
<Uncles<T>>::put(&uncles[prune_index..]);
}
}