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
pallet-timestamp: Remove ValidAtTimestamp error variant
#13346
Merged
paritytech-processbot
merged 4 commits into
master
from
bkchr-remove-too-far-in-the-future
Feb 14, 2023
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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 |
|---|---|---|
|
|
@@ -134,10 +134,9 @@ impl From<Duration> for Timestamp { | |
| #[derive(Encode, sp_runtime::RuntimeDebug)] | ||
| #[cfg_attr(feature = "std", derive(Decode, thiserror::Error))] | ||
| pub enum InherentError { | ||
| /// The timestamp is valid in the future. | ||
| /// This is a non-fatal-error and will not stop checking the inherents. | ||
| #[cfg_attr(feature = "std", error("Block will be valid at {0}."))] | ||
| ValidAtTimestamp(InherentType), | ||
| /// The time between the blocks is too short. | ||
| #[cfg_attr(feature = "std", error("The time between the blocks is too short."))] | ||
| TimeBetweenBlocksTooShort, | ||
|
||
| /// The block timestamp is too far in the future | ||
| #[cfg_attr(feature = "std", error("The timestamp of the block is too far in the future."))] | ||
| TooFarInFuture, | ||
|
|
@@ -146,7 +145,7 @@ pub enum InherentError { | |
| impl IsFatalError for InherentError { | ||
| fn is_fatal_error(&self) -> bool { | ||
| match self { | ||
| InherentError::ValidAtTimestamp(_) => false, | ||
| InherentError::TimeBetweenBlocksTooShort => true, | ||
| InherentError::TooFarInFuture => true, | ||
| } | ||
| } | ||
|
|
@@ -240,34 +239,8 @@ impl sp_inherents::InherentDataProvider for InherentDataProvider { | |
| identifier: &InherentIdentifier, | ||
| error: &[u8], | ||
| ) -> Option<Result<(), sp_inherents::Error>> { | ||
| if *identifier != INHERENT_IDENTIFIER { | ||
| return None | ||
| } | ||
|
|
||
| match InherentError::try_from(&INHERENT_IDENTIFIER, error)? { | ||
| InherentError::ValidAtTimestamp(valid) => { | ||
| let max_drift = self.max_drift; | ||
| let timestamp = self.timestamp; | ||
| // halt import until timestamp is valid. | ||
| // reject when too far ahead. | ||
| if valid > timestamp + max_drift { | ||
| return Some(Err(sp_inherents::Error::Application(Box::from( | ||
| InherentError::TooFarInFuture, | ||
| )))) | ||
| } | ||
|
|
||
| let diff = valid.checked_sub(timestamp).unwrap_or_default(); | ||
| log::info!( | ||
| target: "timestamp", | ||
| "halting for block {} milliseconds in the future", | ||
| diff.0, | ||
| ); | ||
|
|
||
| futures_timer::Delay::new(diff.as_duration()).await; | ||
|
|
||
| Some(Ok(())) | ||
| }, | ||
| o => Some(Err(sp_inherents::Error::Application(Box::from(o)))), | ||
| } | ||
| Some(Err(sp_inherents::Error::Application(Box::from(InherentError::try_from( | ||
davxy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| identifier, error, | ||
| )?)))) | ||
| } | ||
| } | ||
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.