Add runtime support for PreRuntime and Consensus digests (#2757)

* Try to fix runtime panic

Does not work

* Fix trivial typo

* Add runtime support for `PreRuntime` and `Consensus` digests

Fixes c7d1204ce5

* Fix silly compile error.

* Fix overly-long lines

Also remove some in-progress code that would not wind up being useful
anyway.

* Respond to review comments

* delete `unset RUSTC_WRAPPER` from scripts/common.sh
* delete unnecessary `use aura::AURA_ENGINE_ID` from
  `node/runtime/src/lib.rs`
* add comments explaining why `PreRuntime` and `Consensus` must be
  special-cased in `core/sr-primitives/lib.rs`
* switch to using `$crate::rstd::marker::PhantomData` in
  `impl_outer_log!`
* improve documentation of `DigestItem::Seal`

* Fix compilation and add proof that we do not panic

Also fix some warnings.

* Apply suggestions from code review

Mostly for readability

Co-Authored-By: Sergei Pepyakin <s.pepyakin@gmail.com>

* Apply suggestions from code review

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

* $crate::rstd::marker::PhantomData → Default::default()

The import is still needed, as `Default::default()` can’t be used in
patterns.

* Bump `spec_version`

Also do some reformatting.
This commit is contained in:
DemiMarie-parity
2019-06-04 09:59:47 -04:00
committed by Bastian Köcher
parent 4d476161e2
commit 53e8ad8728
9 changed files with 144 additions and 33 deletions
+19 -3
View File
@@ -17,19 +17,21 @@
//! Consensus extension module for BABE consensus.
#![cfg_attr(not(feature = "std"), no_std)]
#![forbid(unsafe_code, warnings)]
#![forbid(unsafe_code)]
pub use timestamp;
use rstd::{result, prelude::*};
use rstd::{result, prelude::*, marker::PhantomData};
use srml_support::{decl_storage, decl_module};
use timestamp::{OnTimestampSet, Trait};
use primitives::traits::{SaturatedConversion, Saturating};
#[cfg(feature = "std")]
use timestamp::TimestampInherentData;
use parity_codec::Decode;
use parity_codec::{Encode, Decode};
use inherents::{RuntimeString, InherentIdentifier, InherentData, ProvideInherent, MakeFatalError};
#[cfg(feature = "std")]
use inherents::{InherentDataProviders, ProvideInherentData};
#[cfg(feature = "std")]
use serde::Serialize;
/// The BABE inherent identifier.
pub const INHERENT_IDENTIFIER: InherentIdentifier = *b"babeslot";
@@ -56,6 +58,20 @@ impl BabeInherentData for InherentData {
}
}
/// Logs in this module.
pub type Log<T> = RawLog<T>;
/// Logs in this module.
///
/// The type parameter distinguishes logs belonging to two different runtimes,
/// which should not be mixed.
#[cfg_attr(feature = "std", derive(Serialize, Debug))]
#[derive(Encode, Decode, PartialEq, Eq, Clone)]
pub enum RawLog<T> {
/// BABE inherent digests
PreRuntime([u8; 4], Vec<u8>, PhantomData<T>),
}
/// Provides the slot duration inherent data for BABE.
#[cfg(feature = "std")]
pub struct InherentDataProvider {