-
Notifications
You must be signed in to change notification settings - Fork 384
Make author inherent both required and mandatory #210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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<T: Config> { | ||
| /// 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!(<Author<T>>::get().is_none(), Error::<T>::AuthorAlreadySet); | ||
|
|
@@ -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"); | ||
| } | ||
| } | ||
|
|
@@ -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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 See paritytech/substrate#7941 for my best understanding of how this trait works.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.