This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
add notes and warnings to ProvideInherent docs #9730
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
197b216
add notes and warnings to ProvideInherent docs
apopiak 9ba7d68
rephrase ProvideInherent doc comments
apopiak 895afe5
more comment refinement
apopiak 568a70f
remove multiple inherents note
apopiak e1f29cb
remove repetition
apopiak f848dfc
replace inherent example in docs
apopiak d7395be
add note about who checks is_inherent_required
apopiak 1234f51
Merge branch 'master' of github.com:paritytech/substrate into apopiak…
apopiak 57b0525
Apply suggestions from code review
apopiak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,9 +24,12 @@ pub use sp_inherents::{ | |
| CheckInherentsResult, InherentData, InherentIdentifier, IsFatalError, MakeFatalError, | ||
| }; | ||
|
|
||
| /// A pallet that provides or verifies an inherent extrinsic. | ||
| /// A pallet that provides or verifies an inherent extrinsic will implement this trait. | ||
| /// | ||
| /// The pallet may provide the inherent, verify an inherent, or both provide and verify. | ||
| /// The pallet may provide an inherent, verify an inherent, or both provide and verify. | ||
| /// | ||
| /// Briefly, inherent extrinsics ("inherents") are extrinsics that are added to a block by the block | ||
| /// producer. See [`sp_inherents`] for more documentation on inherents. | ||
| pub trait ProvideInherent { | ||
| /// The call type of the pallet. | ||
| type Call; | ||
|
|
@@ -36,6 +39,12 @@ pub trait ProvideInherent { | |
| const INHERENT_IDENTIFIER: self::InherentIdentifier; | ||
|
|
||
| /// Create an inherent out of the given `InherentData`. | ||
| /// | ||
| /// NOTE: All checks necessary to ensure that the inherent is correct and that can be done in | ||
| /// the runtime should happen in the returned `Call`. | ||
| /// E.g. if this provides the timestamp, the call will check that the given timestamp is | ||
| /// increasing the old timestamp by more than a minimum and it will also check that the | ||
| /// timestamp hasn't already been set in the current block. | ||
| fn create_inherent(data: &InherentData) -> Option<Self::Call>; | ||
|
|
||
| /// Determines whether this inherent is required in this block. | ||
|
|
@@ -44,15 +53,17 @@ pub trait ProvideInherent { | |
| /// implementation returns this. | ||
| /// | ||
| /// - `Ok(Some(e))` indicates that this inherent is required in this block. `construct_runtime!` | ||
| /// will call this function from in its implementation of `fn check_extrinsics`. | ||
| /// will call this function in its implementation of `fn check_extrinsics`. | ||
| /// If the inherent is not present, it will return `e`. | ||
| /// | ||
| /// - `Err(_)` indicates that this function failed and further operations should be aborted. | ||
| /// | ||
| /// NOTE: If inherent is required then the runtime asserts that the block contains at least | ||
| /// NOTE: If the inherent is required then the runtime asserts that the block contains at least | ||
| /// one inherent for which: | ||
| /// * type is [`Self::Call`], | ||
| /// * [`Self::is_inherent`] returns true. | ||
|
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'm not sure how to write it but this |
||
| /// | ||
| /// NOTE: This is currently only checked by block producers, not all full nodes. | ||
bkchr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| fn is_inherent_required(_: &InherentData) -> Result<Option<Self::Error>, Self::Error> { | ||
| Ok(None) | ||
| } | ||
|
|
@@ -64,21 +75,27 @@ pub trait ProvideInherent { | |
| /// included in the block by its author. Whereas the second parameter represents the inherent | ||
| /// data that the verifying node calculates. | ||
| /// | ||
| /// NOTE: A block can contains multiple inherent. | ||
| /// This is intended to allow for checks that cannot be done within the runtime such as, e.g., | ||
| /// the timestamp. | ||
| /// | ||
| /// # Warning | ||
| /// | ||
| /// This check is not guaranteed to be run by all full nodes and cannot be relied upon for | ||
| /// ensuring that the block is correct. | ||
| fn check_inherent(_: &Self::Call, _: &InherentData) -> Result<(), Self::Error> { | ||
| Ok(()) | ||
| } | ||
|
|
||
| /// Return whether the call is an inherent call. | ||
| /// | ||
| /// NOTE: Signed extrinsics are not inherent, but signed extrinsic with the given call variant | ||
| /// can be dispatched. | ||
| /// NOTE: Signed extrinsics are not inherents, but a signed extrinsic with the given call | ||
| /// variant can be dispatched. | ||
| /// | ||
| /// # Warning | ||
| /// | ||
| /// In FRAME, inherent are enforced to be before other extrinsics, for this reason, | ||
| /// In FRAME, inherents are enforced to be executed before other extrinsics. For this reason, | ||
| /// pallets with unsigned transactions **must ensure** that no unsigned transaction call | ||
| /// is an inherent call, when implementing `ValidateUnsigned::validate_unsigned`. | ||
| /// Otherwise block producer can produce invalid blocks by including them after non inherent. | ||
| /// Otherwise block producers can produce invalid blocks by including them after non inherents. | ||
| fn is_inherent(call: &Self::Call) -> bool; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.