diff --git a/frame/aura/src/lib.rs b/frame/aura/src/lib.rs index 61937da286ada..1952f467bdbb5 100644 --- a/frame/aura/src/lib.rs +++ b/frame/aura/src/lib.rs @@ -112,6 +112,35 @@ pub mod pallet { Pallet::::initialize_authorities(&self.authorities); } } + + #[pallet::inherent] + impl ProvideInherent for Pallet { + type Call = pallet_timestamp::Call; + type Error = MakeFatalError; + const INHERENT_IDENTIFIER: InherentIdentifier = INHERENT_IDENTIFIER; + + fn create_inherent(_: &InherentData) -> Option { + None + } + + /// Verify the validity of the inherent using the timestamp. + fn check_inherent(call: &Self::Call, data: &InherentData) -> result::Result<(), Self::Error> { + let timestamp = match call { + pallet_timestamp::Call::set(ref timestamp) => timestamp.clone(), + _ => return Ok(()), + }; + + let timestamp_based_slot = timestamp / Self::slot_duration(); + + let seal_slot = u64::from(data.aura_inherent_data()?).saturated_into(); + + if timestamp_based_slot == seal_slot { + Ok(()) + } else { + Err(sp_inherents::Error::from("timestamp set in block doesn't match slot in seal").into()) + } + } + } } impl Pallet { @@ -242,31 +271,3 @@ impl OnTimestampSet for Pallet { // TODO [#3398] Generate offence report for all authorities that skipped their slots. } } - -impl ProvideInherent for Pallet { - type Call = pallet_timestamp::Call; - type Error = MakeFatalError; - const INHERENT_IDENTIFIER: InherentIdentifier = INHERENT_IDENTIFIER; - - fn create_inherent(_: &InherentData) -> Option { - None - } - - /// Verify the validity of the inherent using the timestamp. - fn check_inherent(call: &Self::Call, data: &InherentData) -> result::Result<(), Self::Error> { - let timestamp = match call { - pallet_timestamp::Call::set(ref timestamp) => timestamp.clone(), - _ => return Ok(()), - }; - - let timestamp_based_slot = timestamp / Self::slot_duration(); - - let seal_slot = u64::from(data.aura_inherent_data()?).saturated_into(); - - if timestamp_based_slot == seal_slot { - Ok(()) - } else { - Err(sp_inherents::Error::from("timestamp set in block doesn't match slot in seal").into()) - } - } -}