Skip to content

Commit

Permalink
Make author inherent both required and mandatory (paritytech#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshOrndorff authored Jan 28, 2021
1 parent 636ae70 commit c39f32b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
19 changes: 17 additions & 2 deletions pallets/author-inherent/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -69,6 +71,7 @@ decl_error! {
pub enum Error for Module<T: Config> {
/// Author already set in block.
AuthorAlreadySet,
/// The author in the inherent is not an eligible author.
CannotBeAuthor,
}
}
Expand All @@ -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!(<Author<T>>::get().is_none(), Error::<T>::AuthorAlreadySet);
Expand All @@ -112,6 +118,7 @@ decl_module! {
}

fn on_finalize() {
// Do we still need this now that it is required?
assert!(<Author<T>>::take().is_some(), "Author inherent must be in the block");
}
}
Expand Down Expand Up @@ -179,6 +186,14 @@ impl<T: Config> ProvideInherent for Module<T> {
type Error = InherentError;
const INHERENT_IDENTIFIER: InherentIdentifier = INHERENT_IDENTIFIER;

fn is_inherent_required(_: &InherentData) -> Result<Option<Self::Error>, 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<Self::Call> {
// Grab the Vec<u8> labelled with "author__" from the map of all inherent data
let author_raw = data
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/standalone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit c39f32b

Please sign in to comment.