@@ -24,9 +24,12 @@ pub use sp_inherents::{
24
24
CheckInherentsResult , InherentData , InherentIdentifier , IsFatalError , MakeFatalError ,
25
25
} ;
26
26
27
- /// A pallet that provides or verifies an inherent extrinsic.
27
+ /// A pallet that provides or verifies an inherent extrinsic will implement this trait .
28
28
///
29
- /// The pallet may provide the inherent, verify an inherent, or both provide and verify.
29
+ /// The pallet may provide an inherent, verify an inherent, or both provide and verify.
30
+ ///
31
+ /// Briefly, inherent extrinsics ("inherents") are extrinsics that are added to a block by the block
32
+ /// producer. See [`sp_inherents`] for more documentation on inherents.
30
33
pub trait ProvideInherent {
31
34
/// The call type of the pallet.
32
35
type Call ;
@@ -36,6 +39,12 @@ pub trait ProvideInherent {
36
39
const INHERENT_IDENTIFIER : self :: InherentIdentifier ;
37
40
38
41
/// Create an inherent out of the given `InherentData`.
42
+ ///
43
+ /// NOTE: All checks necessary to ensure that the inherent is correct and that can be done in
44
+ /// the runtime should happen in the returned `Call`.
45
+ /// E.g. if this provides the timestamp, the call will check that the given timestamp is
46
+ /// increasing the old timestamp by more than a minimum and it will also check that the
47
+ /// timestamp hasn't already been set in the current block.
39
48
fn create_inherent ( data : & InherentData ) -> Option < Self :: Call > ;
40
49
41
50
/// Determines whether this inherent is required in this block.
@@ -44,15 +53,17 @@ pub trait ProvideInherent {
44
53
/// implementation returns this.
45
54
///
46
55
/// - `Ok(Some(e))` indicates that this inherent is required in this block. `construct_runtime!`
47
- /// will call this function from in its implementation of `fn check_extrinsics`.
56
+ /// will call this function in its implementation of `fn check_extrinsics`.
48
57
/// If the inherent is not present, it will return `e`.
49
58
///
50
59
/// - `Err(_)` indicates that this function failed and further operations should be aborted.
51
60
///
52
- /// NOTE: If inherent is required then the runtime asserts that the block contains at least
61
+ /// NOTE: If the inherent is required then the runtime asserts that the block contains at least
53
62
/// one inherent for which:
54
63
/// * type is [`Self::Call`],
55
64
/// * [`Self::is_inherent`] returns true.
65
+ ///
66
+ /// NOTE: This is currently only checked by block producers, not all full nodes.
56
67
fn is_inherent_required ( _: & InherentData ) -> Result < Option < Self :: Error > , Self :: Error > {
57
68
Ok ( None )
58
69
}
@@ -64,21 +75,27 @@ pub trait ProvideInherent {
64
75
/// included in the block by its author. Whereas the second parameter represents the inherent
65
76
/// data that the verifying node calculates.
66
77
///
67
- /// NOTE: A block can contains multiple inherent.
78
+ /// This is intended to allow for checks that cannot be done within the runtime such as, e.g.,
79
+ /// the timestamp.
80
+ ///
81
+ /// # Warning
82
+ ///
83
+ /// This check is not guaranteed to be run by all full nodes and cannot be relied upon for
84
+ /// ensuring that the block is correct.
68
85
fn check_inherent ( _: & Self :: Call , _: & InherentData ) -> Result < ( ) , Self :: Error > {
69
86
Ok ( ( ) )
70
87
}
71
88
72
89
/// Return whether the call is an inherent call.
73
90
///
74
- /// NOTE: Signed extrinsics are not inherent , but signed extrinsic with the given call variant
75
- /// can be dispatched.
91
+ /// NOTE: Signed extrinsics are not inherents , but a signed extrinsic with the given call
92
+ /// variant can be dispatched.
76
93
///
77
94
/// # Warning
78
95
///
79
- /// In FRAME, inherent are enforced to be before other extrinsics, for this reason,
96
+ /// In FRAME, inherents are enforced to be executed before other extrinsics. For this reason,
80
97
/// pallets with unsigned transactions **must ensure** that no unsigned transaction call
81
98
/// is an inherent call, when implementing `ValidateUnsigned::validate_unsigned`.
82
- /// Otherwise block producer can produce invalid blocks by including them after non inherent .
99
+ /// Otherwise block producers can produce invalid blocks by including them after non inherents .
83
100
fn is_inherent ( call : & Self :: Call ) -> bool ;
84
101
}
0 commit comments