Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"),
)))
}

Comment on lines +189 to +196
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@4meta5 This is why I was wondering whether we still need the check in on_finalize.

See paritytech/substrate#7941 for my best understanding of how this trait works.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. This should work, but still need to clear the storage item in on_finalize so it can be set in the next block. So can remove the assert!(<Author>::take) and replace it with <Author>::kill()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@4meta5 Could you please investigate whether this cleanup is valid in another PR?

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