diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index 98507abf5d..641cbf44eb 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -83,7 +83,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // implementation changes and behavior does not, then leave spec_version as // is and increment impl_version. spec_version: 244, - impl_version: 2, + impl_version: 3, apis: RUNTIME_API_VERSIONS, transaction_version: 1, }; diff --git a/substrate/frame/support/src/inherent.rs b/substrate/frame/support/src/inherent.rs index a21bd361b6..4e09bf9dd8 100644 --- a/substrate/frame/support/src/inherent.rs +++ b/substrate/frame/support/src/inherent.rs @@ -77,7 +77,7 @@ macro_rules! impl_outer_inherent { let mut result = $crate::inherent::CheckInherentsResult::new(); for xt in block.extrinsics() { if $crate::inherent::Extrinsic::is_signed(xt).unwrap_or(false) { - break; + break } $( @@ -88,7 +88,7 @@ macro_rules! impl_outer_inherent { $module::INHERENT_IDENTIFIER, &e ).expect("There is only one fatal error; qed"); if e.is_fatal_error() { - return result; + return result } } } @@ -97,6 +97,41 @@ macro_rules! impl_outer_inherent { )* } + $( + match $module::is_inherent_required(self) { + Ok(Some(e)) => { + let found = block.extrinsics().iter().any(|xt| { + if $crate::inherent::Extrinsic::is_signed(xt).unwrap_or(false) { + return false + } + + match xt.function { + Call::$call(_) => true, + _ => false, + } + }); + + if !found { + result.put_error( + $module::INHERENT_IDENTIFIER, &e + ).expect("There is only one fatal error; qed"); + if e.is_fatal_error() { + return result + } + } + }, + Ok(None) => (), + Err(e) => { + result.put_error( + $module::INHERENT_IDENTIFIER, &e + ).expect("There is only one fatal error; qed"); + if e.is_fatal_error() { + return result + } + }, + } + )* + result } } diff --git a/substrate/primitives/inherents/src/lib.rs b/substrate/primitives/inherents/src/lib.rs index e8df2c49e5..e63382cdf2 100644 --- a/substrate/primitives/inherents/src/lib.rs +++ b/substrate/primitives/inherents/src/lib.rs @@ -408,6 +408,11 @@ pub trait ProvideInherent { /// Create an inherent out of the given `InherentData`. fn create_inherent(data: &InherentData) -> Option; + /// If `Some`, indicates that an inherent is required. Check will return the inner error if no + /// inherent is found. If `Err`, indicates that the check failed and further operations should + /// be aborted. + fn is_inherent_required(_: &InherentData) -> Result, Self::Error> { Ok(None) } + /// Check the given inherent if it is valid. /// Checking the inherent is optional and can be omitted. fn check_inherent(_: &Self::Call, _: &InherentData) -> Result<(), Self::Error> {