* Start to remove the `As` bound on `SimpleArtithmetic`

This just introduces standard numeric bounds, assuming a minimum of
`u32`. Also included is a saturating from/into trait allowing ergonomic
infallible conversion when you don't care if it saturates.

* Remove As from Balances trait

* Remove As from Aura module

* Remove As from Babe module

* Expunge `As` from contract

* Council module

* Democracy

* Finality tracker

* Grandpa

* First bit of indices

* indices

* Line lengths

* session

* system

* Staking

* Square up all other uses of As.

* RHD update

* Fix build/test

* Remove As trait

* line widths

* Remove final As ref

* Update srml/staking/src/lib.rs

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>

* Update core/client/src/cht.rs

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>

* Update core/client/db/src/light.rs

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>

* Apply suggestions from code review

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>

* whitespace

* Apply suggestions from code review

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>
Co-Authored-By: André Silva <andre.beat@gmail.com>

* Bring back u32 check for number on CLI
This commit is contained in:
Gavin Wood
2019-05-22 23:11:38 +01:00
committed by GitHub
parent 36987c0205
commit 3860d7c810
60 changed files with 695 additions and 491 deletions
+8 -8
View File
@@ -26,7 +26,7 @@ use inherents::{
InherentData, MakeFatalError,
};
use srml_support::StorageValue;
use primitives::traits::{As, One, Zero};
use primitives::traits::{One, Zero, SaturatedConversion};
use rstd::{prelude::*, result, cmp, vec};
use parity_codec::Decode;
use srml_system::{ensure_none, Trait as SystemTrait};
@@ -34,8 +34,8 @@ use srml_system::{ensure_none, Trait as SystemTrait};
#[cfg(feature = "std")]
use parity_codec::Encode;
const DEFAULT_WINDOW_SIZE: u64 = 101;
const DEFAULT_DELAY: u64 = 1000;
const DEFAULT_WINDOW_SIZE: u32 = 101;
const DEFAULT_DELAY: u32 = 1000;
/// The identifier for the `finalnum` inherent.
pub const INHERENT_IDENTIFIER: InherentIdentifier = *b"finalnum";
@@ -100,9 +100,9 @@ decl_storage! {
/// The median.
Median get(median) build(|_| T::BlockNumber::zero()): T::BlockNumber;
/// The number of recent samples to keep from this chain. Default is n-100
pub WindowSize get(window_size) config(window_size): T::BlockNumber = T::BlockNumber::sa(DEFAULT_WINDOW_SIZE);
pub WindowSize get(window_size) config(window_size): T::BlockNumber = DEFAULT_WINDOW_SIZE.into();
/// The delay after which point things become suspicious.
pub ReportLatency get(report_latency) config(report_latency): T::BlockNumber = T::BlockNumber::sa(DEFAULT_DELAY);
pub ReportLatency get(report_latency) config(report_latency): T::BlockNumber = DEFAULT_DELAY.into();
/// Final hint to apply in the block. `None` means "same as parent".
Update: Option<T::BlockNumber>;
@@ -154,7 +154,7 @@ impl<T: Trait> Module<T> {
// the sample size has just been shrunk.
{
// take into account the item we haven't pushed yet.
let to_prune = (recent.len() + 1).saturating_sub(window_size.as_() as usize);
let to_prune = (recent.len() + 1).saturating_sub(window_size.saturated_into::<usize>());
for drained in recent.drain(..to_prune) {
let idx = ordered.binary_search(&drained)
@@ -188,13 +188,13 @@ impl<T: Trait> Module<T> {
}
};
let our_window_size = recent.len();
let our_window_size = recent.len() as u32;
<Self as Store>::RecentHints::put(recent);
<Self as Store>::OrderedHints::put(ordered);
<Self as Store>::Median::put(median);
if T::BlockNumber::sa(our_window_size as u64) == window_size {
if T::BlockNumber::from(our_window_size) == window_size {
let now = srml_system::Module::<T>::block_number();
let latency = Self::report_latency();