From 3d8448e78ec0f8b27614c1dfe81c4e0091780067 Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Wed, 27 Jan 2021 16:03:07 -0500 Subject: [PATCH 1/2] make author inherent both required and mandatory --- pallets/author-inherent/src/lib.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/pallets/author-inherent/src/lib.rs b/pallets/author-inherent/src/lib.rs index 637f1ac7c47..98eb6417092 100644 --- a/pallets/author-inherent/src/lib.rs +++ b/pallets/author-inherent/src/lib.rs @@ -20,7 +20,9 @@ #![cfg_attr(not(feature = "std"), no_std)] -use frame_support::{decl_error, decl_event, decl_module, decl_storage, ensure}; +use frame_support::{ + decl_error, decl_event, decl_module, decl_storage, ensure, weights::DispatchClass, +}; use frame_system::{ensure_none, Config as System}; use parity_scale_codec::{Decode, Encode}; #[cfg(feature = "std")] @@ -69,6 +71,7 @@ decl_error! { pub enum Error for Module { /// Author already set in block. AuthorAlreadySet, + /// The author in the inherent is not an eligible author. CannotBeAuthor, } } @@ -86,7 +89,10 @@ decl_module! { fn deposit_event() = default; /// Inherent to set the author of a block - #[weight = 0] + #[weight = ( + 0, + DispatchClass::Mandatory + )] fn set_author(origin, author: T::AccountId) { ensure_none(origin)?; ensure!(>::get().is_none(), Error::::AuthorAlreadySet); @@ -112,6 +118,7 @@ decl_module! { } fn on_finalize() { + // Do we still need this now that it is required? assert!(>::take().is_some(), "Author inherent must be in the block"); } } @@ -179,6 +186,14 @@ impl ProvideInherent for Module { type Error = InherentError; const INHERENT_IDENTIFIER: InherentIdentifier = INHERENT_IDENTIFIER; + fn is_inherent_required(_: &InherentData) -> Result, Self::Error> { + // Return Ok(Some(_)) unconditionally because this inherent is required in every block + // If it is not found, throw an AuthorInherentRequired error. + Ok(Some(InherentError::Other( + sp_runtime::RuntimeString::Borrowed("AuthorInherentRequired"), + ))) + } + fn create_inherent(data: &InherentData) -> Option { // Grab the Vec labelled with "author__" from the map of all inherent data let author_raw = data From a67edfe9d0944a32d24b1af115146d72a880fc47 Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Wed, 27 Jan 2021 16:07:56 -0500 Subject: [PATCH 2/2] bump runtime version --- runtime/src/parachain.rs | 2 +- runtime/src/standalone.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/src/parachain.rs b/runtime/src/parachain.rs index eafc39e8132..9eef9deed82 100644 --- a/runtime/src/parachain.rs +++ b/runtime/src/parachain.rs @@ -22,7 +22,7 @@ macro_rules! runtime_parachain { spec_name: create_runtime_str!("moonbase-alphanet"), impl_name: create_runtime_str!("moonbase-alphanet"), authoring_version: 3, - spec_version: 11, + spec_version: 12, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 2, diff --git a/runtime/src/standalone.rs b/runtime/src/standalone.rs index 298298cd667..9561badc7d3 100644 --- a/runtime/src/standalone.rs +++ b/runtime/src/standalone.rs @@ -31,7 +31,7 @@ macro_rules! runtime_standalone { spec_name: create_runtime_str!("moonbeam-standalone"), impl_name: create_runtime_str!("moonbeam-standalone"), authoring_version: 3, - spec_version: 11, + spec_version: 12, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 2,