From 45f8b6e91ff6c54260d25fcef84d17395764f8f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Sun, 13 Jun 2021 12:41:13 +0100 Subject: [PATCH] pallet-authorship: Fixing some nitpicks (#9095) As reviewing the pallet yesterday, I have found some nitpicks that I fixed. --- substrate/frame/authorship/src/lib.rs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/substrate/frame/authorship/src/lib.rs b/substrate/frame/authorship/src/lib.rs index 9b46a3fe11..98d20ec621 100644 --- a/substrate/frame/authorship/src/lib.rs +++ b/substrate/frame/authorship/src/lib.rs @@ -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 Pallet { 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 Pallet { return Err(Error::::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 = >::block_hash(uncle.number()) == hash; if duplicate || in_chain { @@ -341,15 +337,14 @@ impl Pallet { } fn prune_old_uncles(minimum_height: T::BlockNumber) { - let mut uncles = >::get(); + let uncles = >::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); - >::put(uncles); + >::put(&uncles[prune_index..]); } }