Prepare for latest clippy (nightly 09-10-2022) (#12466)

This commit is contained in:
Bastian Köcher
2022-10-18 12:07:02 +02:00
committed by GitHub
parent 8671fb7615
commit 738dc8460e
15 changed files with 28 additions and 32 deletions
@@ -63,7 +63,7 @@ impl Era {
/// does not exceed `BlockHashCount` parameter passed to `system` module, since that
/// prunes old blocks and renders transactions immediately invalid.
pub fn mortal(period: u64, current: u64) -> Self {
let period = period.checked_next_power_of_two().unwrap_or(1 << 16).max(4).min(1 << 16);
let period = period.checked_next_power_of_two().unwrap_or(1 << 16).clamp(4, 1 << 16);
let phase = current % period;
let quantize_factor = (period >> 12).max(1);
let quantized_phase = phase / quantize_factor * quantize_factor;
@@ -105,7 +105,7 @@ impl Encode for Era {
Self::Immortal => output.push_byte(0),
Self::Mortal(period, phase) => {
let quantize_factor = (*period as u64 >> 12).max(1);
let encoded = (period.trailing_zeros() - 1).max(1).min(15) as u16 |
let encoded = (period.trailing_zeros() - 1).clamp(1, 15) as u16 |
((phase / quantize_factor) << 4) as u16;
encoded.encode_to(output);
},
@@ -77,8 +77,8 @@ const STORAGE_LOCK_DEFAULT_EXPIRY_DURATION: Duration = Duration::from_millis(20_
const STORAGE_LOCK_DEFAULT_EXPIRY_BLOCKS: u32 = 4;
/// Time between checks if the lock is still being held in milliseconds.
const STORAGE_LOCK_PER_CHECK_ITERATION_SNOOZE_MIN: Duration = Duration::from_millis(100);
const STORAGE_LOCK_PER_CHECK_ITERATION_SNOOZE_MAX: Duration = Duration::from_millis(10);
const STORAGE_LOCK_PER_CHECK_ITERATION_SNOOZE_MIN: Duration = Duration::from_millis(10);
const STORAGE_LOCK_PER_CHECK_ITERATION_SNOOZE_MAX: Duration = Duration::from_millis(100);
/// Lockable item for use with a persisted storage lock.
///
@@ -137,10 +137,9 @@ impl Lockable for Time {
let remainder: Duration = now.diff(deadline);
// do not snooze the full duration, but instead snooze max 100ms
// it might get unlocked in another thread
use core::cmp::{max, min};
let snooze = max(
min(remainder, STORAGE_LOCK_PER_CHECK_ITERATION_SNOOZE_MAX),
let snooze = remainder.clamp(
STORAGE_LOCK_PER_CHECK_ITERATION_SNOOZE_MIN,
STORAGE_LOCK_PER_CHECK_ITERATION_SNOOZE_MAX,
);
sp_io::offchain::sleep_until(now.add(snooze));
}
@@ -239,10 +238,9 @@ impl<B: BlockNumberProvider> Lockable for BlockAndTime<B> {
fn snooze(deadline: &Self::Deadline) {
let now = offchain::timestamp();
let remainder: Duration = now.diff(&(deadline.timestamp));
use core::cmp::{max, min};
let snooze = max(
min(remainder, STORAGE_LOCK_PER_CHECK_ITERATION_SNOOZE_MAX),
let snooze = remainder.clamp(
STORAGE_LOCK_PER_CHECK_ITERATION_SNOOZE_MIN,
STORAGE_LOCK_PER_CHECK_ITERATION_SNOOZE_MAX,
);
sp_io::offchain::sleep_until(now.add(snooze));
}