Rewrite Inherent data (#1488)

* Implement new inherent data

* Fixes compilation on wasm

* Fixes after rebase

* Switch back to generate inherent stuff by macro

* Update after rebase

* Apply suggestions from code review

Co-Authored-By: bkchr <bkchr@users.noreply.github.com>

* Fix compilation after rebase

* Address grumbles

* Remove `InherentDataProviders` from `Client`

* Update wasm files after rebase

* Address grumbles

* Fixes compilation after latest merge

* Last fix
This commit is contained in:
Bastian Köcher
2019-01-22 17:52:08 +01:00
committed by GitHub
parent b14917e63f
commit 70b1af7b1e
55 changed files with 1513 additions and 661 deletions
-51
View File
@@ -511,57 +511,6 @@ macro_rules! impl_outer_log {
};
}
//TODO: https://github.com/paritytech/substrate/issues/1022
/// Basic Inherent data to include in a block; used by simple runtimes.
#[derive(Encode, Decode)]
pub struct BasicInherentData {
/// Current timestamp.
pub timestamp: u64,
/// Blank report.
pub consensus: (),
/// Aura expected slot. Can take any value during block construction.
pub aura_expected_slot: u64,
}
impl BasicInherentData {
/// Create a new `BasicInherentData` instance.
pub fn new(timestamp: u64, expected_slot: u64) -> Self {
Self {
timestamp,
consensus: (),
aura_expected_slot: expected_slot,
}
}
}
//TODO: https://github.com/paritytech/substrate/issues/1022
/// Error type used while checking inherents.
#[derive(Encode, PartialEq)]
#[cfg_attr(feature = "std", derive(Decode))]
pub enum CheckInherentError {
/// The inherents are generally valid but a delay until the given timestamp
/// is required.
ValidAtTimestamp(u64),
/// Some other error has occurred.
Other(RuntimeString),
}
impl CheckInherentError {
/// Combine two results, taking the "worse" of the two.
pub fn combine_results<F: FnOnce() -> Result<(), Self>>(this: Result<(), Self>, other: F) -> Result<(), Self> {
match this {
Ok(()) => other(),
Err(CheckInherentError::Other(s)) => Err(CheckInherentError::Other(s)),
Err(CheckInherentError::ValidAtTimestamp(x)) => match other() {
Ok(()) => Err(CheckInherentError::ValidAtTimestamp(x)),
Err(CheckInherentError::ValidAtTimestamp(y))
=> Err(CheckInherentError::ValidAtTimestamp(rstd::cmp::max(x, y))),
Err(CheckInherentError::Other(s)) => Err(CheckInherentError::Other(s)),
}
}
}
}
/// Simple blob to hold an extrinsic without commiting to its format and ensure it is serialized
/// correctly.
#[derive(PartialEq, Eq, Clone, Default, Encode, Decode)]
@@ -621,26 +621,6 @@ pub trait DigestItem: Codec + Member + MaybeSerializeDebugButNotDeserialize {
fn as_changes_trie_root(&self) -> Option<&Self::Hash>;
}
/// Something that provides an inherent for a runtime.
pub trait ProvideInherent {
/// The inherent that is provided.
type Inherent: Encode + MaybeDecode;
/// The call for setting the inherent.
type Call: Encode + MaybeDecode;
/// Create the inherent extrinsics.
///
/// # Return
///
/// Returns a vector with tuples containing the index for the extrinsic and the extrinsic itself.
fn create_inherent_extrinsics(data: Self::Inherent) -> Vec<(u32, Self::Call)>;
/// Check that the given inherent is valid.
fn check_inherent<Block: self::Block, F: Fn(&Block::Extrinsic) -> Option<&Self::Call>>(
block: &Block, data: Self::Inherent, extract_function: &F
) -> Result<(), super::CheckInherentError>;
}
/// Auxiliary wrapper that holds an api instance and binds it to the given lifetime.
pub struct ApiRef<'a, T>(T, rstd::marker::PhantomData<&'a ()>);