Skip to content
This repository was archived by the owner on May 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
123 commits
Select commit Hold shift + click to select a range
2d597fc
Merkle Mountain Range pallet improvements (#7891)
tomusdrw Jan 28, 2021
64df2f9
Introduce a `Slot` type (#7997)
bkchr Jan 28, 2021
68d7157
Clarify and expand ProvideInherent docs (#7941)
JoshOrndorff Jan 28, 2021
ae3dabb
Introduce sc_peerset::DropReason (#7996)
tomaka Jan 29, 2021
a51a988
Doc fixes for sc-telemetry & API struct rename (#7934)
cecton Jan 29, 2021
1d5d13a
Fix telemetry span not entering properly & enter span in sc-cli (#7951)
cecton Jan 29, 2021
93b231e
Update parity-scale-codec to 2.0 (#7994)
gui1117 Jan 29, 2021
caff191
Test is_inherent_required (#8002)
amarsinghcodes Jan 29, 2021
9659509
Sync: Fix issue of not freeing a block announcement slot (#8006)
bkchr Jan 29, 2021
a45e3f2
CI: return flaming fir deployment (#8007)
TriplEight Jan 29, 2021
30ec0be
chore: fix typos (#8013)
yjhmelody Feb 1, 2021
017a9a0
Fix tracing spans are not being forwarded to spawned task (#8009)
bkchr Feb 1, 2021
043cb0a
make AllModules public (#8017)
apopiak Feb 1, 2021
5a5f06e
client/network: Use request response for light client requests (#7895)
mxinden Feb 1, 2021
b7fc46d
relax translate closure to FnMut (#8019)
apopiak Feb 1, 2021
26f3d68
Remove outdated Grafana information (#8012)
tomaka Feb 1, 2021
b201d7c
contracts: Emit event on contract termination (#8014)
athei Feb 2, 2021
7cb5eed
Fix tracing tests (#8022)
bkchr Feb 2, 2021
aaf6598
contracts: Improve documentation (#8018)
athei Feb 2, 2021
d5b0856
Disable Kademlia random walk when --reserved-nodes is passed (#7999)
tomaka Feb 2, 2021
81ca765
Convert AURA to new pallet macro (#8020)
bkchr Feb 2, 2021
bc69520
Rename system_networkState to system_unstable_networkState (#8001)
tomaka Feb 2, 2021
075796f
Decouple the session validators from im-online (#7127)
liuchengxu Feb 2, 2021
c7f52d1
better formatting for doc comments (#8030)
JoshOrndorff Feb 2, 2021
5a94966
Add a send_request function to NetworkService (#8008)
eskimor Feb 2, 2021
56c64cf
Storage chains: serve transactions over IPFS/bitswap (#7963)
arkpar Feb 3, 2021
9d7b884
Improve log line (#8032)
tomaka Feb 3, 2021
2fb4534
Export `IfDisconnected` in public module. (#8034)
eskimor Feb 3, 2021
9b40d50
frame-system: Index type 'MaybeSerializeDeserialize' bound. (#8035)
shaunxw Feb 3, 2021
f80d23b
contracts: Make ChainExtension trait generic over the runtime (#8003)
athei Feb 3, 2021
840478a
AURA: Switch to `CurrentSlot` instead of `LastTimestamp` (#8023)
bkchr Feb 3, 2021
dc02c65
contracts: Charge rent for code storage (#7935)
athei Feb 4, 2021
169b16f
Migrate assets pallet to new macros (#7984)
dvdplm Feb 4, 2021
85c479f
babe, grandpa: cleanup stale equivocation reports (#8041)
andresilva Feb 4, 2021
05eb8d9
move some pallet test to use construct_runtime (#8049)
gui1117 Feb 4, 2021
6105169
Migrate more pallet tests to construct_runtime (#8051)
ascjones Feb 4, 2021
a675f9a
Update dependencies ahead of next release (#8015)
gnunicorn Feb 4, 2021
3c9b031
transaction-pool: drop unpropagable txs if local node cant author blo…
andresilva Feb 4, 2021
cc71cca
Fix some problems with `prove_warp_sync` (#8037)
expenses Feb 5, 2021
09ba69f
CheckSpecVersion reference fix (#8056)
al3mart Feb 5, 2021
f14488d
contracts: Remove ConfigCache (#8047)
athei Feb 5, 2021
26e9a11
Extend SS58 network identifiers (#8039)
gavofyork Feb 6, 2021
0b719f8
Use construct_runtime in tests (#8059)
gui1117 Feb 6, 2021
bbc7b0e
Bump wasmtime from 0.19.0 to 0.22.0 (#7865)
dependabot[bot] Feb 8, 2021
29aca98
Remove backwards-compatibility networking hack (#8068)
tomaka Feb 8, 2021
07a5f29
Switch to latest `impl-trait-for-tuples` (#8082)
bkchr Feb 9, 2021
66cfa92
Add Crust Network SS58 Address (#8064)
badkk Feb 9, 2021
077c480
Add Ares SS58 address type (#8061)
jiyilanzhou Feb 9, 2021
273bc7b
Replace last usages of `<() as PalletInfo>` in substrate (#8080)
gui1117 Feb 9, 2021
4777aba
Remove PalletInfo impl for () (#8090)
ascjones Feb 9, 2021
48e9d49
WasmExecutor takes a cache directory (#8057)
pepyakin Feb 9, 2021
9c5da5c
Add Aventus ss58 address (#8050)
nahuseyoum Feb 9, 2021
28b950e
sc-network: switch on default features for libp2p on non-wasm-builds …
gnunicorn Feb 10, 2021
91a7418
pallet macro: easier syntax for `#[pallet::pallet]` with `struct Pall…
gui1117 Feb 10, 2021
90c9706
Pallet attribute macro migrate guidelines minor fixes (#8094)
shaunxw Feb 10, 2021
90bb153
Switch to use `diener patch` for companion build (#8073)
bkchr Feb 10, 2021
22441aa
Migrate pallet-balances to pallet attribute macro (#7936)
ascjones Feb 10, 2021
ce018b8
babe, grandpa: set longevity for equivocation report transactions (#8…
andresilva Feb 10, 2021
ba290e0
Migrate pallet-timestamp to pallet attribute macro. (#8078)
shaunxw Feb 10, 2021
12562bb
Use log level error to report telemetry (#8097)
cecton Feb 10, 2021
49a4103
Releasing 3.0 (#8098)
gnunicorn Feb 10, 2021
3957f43
[CI] Move check_labels to github actions (#8099)
s3krit Feb 11, 2021
27c03f2
Update sc-finality-grandp-warp-sync to 0.9.0 and remove 'publish = fa…
expenses Feb 12, 2021
4e50238
Remove all code related to sentry nodes (#8079)
tomaka Feb 15, 2021
386914e
Add code blocks to doc diagrams (#8118)
shawntabrizi Feb 15, 2021
13b6998
Simplify runtime api error handling (#8114)
bkchr Feb 15, 2021
171ad23
CI: temp. allow cargo deny to fail (#8122)
TriplEight Feb 15, 2021
da6b3e2
Update Grafana dashboards (#8127)
tomaka Feb 15, 2021
e03ca38
grandpa: make the VotingRule API async (#8101)
andresilva Feb 15, 2021
d054593
Create a macro which automates creation of benchmark test suites. (#8…
coriolinus Feb 16, 2021
5e8df39
Move dust collection hook to outside of account mutate (#8087)
gavofyork Feb 16, 2021
fb1b15c
fix deprecated usage of panic (#8134)
gui1117 Feb 16, 2021
7d2de01
Remove inherent in pallet-babe (#8124)
gui1117 Feb 16, 2021
743accb
Fix telemetry span not entering properly attempt 3 (#8043)
cecton Feb 17, 2021
cd11670
Unbreak browser test CI (#8149)
tomaka Feb 18, 2021
75a2d29
Benchmark macro: Allow multiple bounds in where (#8116)
weichweich Feb 18, 2021
ca63242
Make it clear in CLI that paritydb is experimental (#8152)
bkchr Feb 18, 2021
2c99434
Extract transactions handling from protocol.rs (#8110)
tomaka Feb 18, 2021
f53d72f
Remove `OnSlot` associated type (#8156)
bkchr Feb 18, 2021
1c842c4
Fix warning in rustdoc job (#8159)
bkchr Feb 19, 2021
9029ab0
CI: test and update ci image, codeowners (#8142)
TriplEight Feb 19, 2021
394c52e
Migration testing runtime API/Bot (#8038)
kianenigma Feb 19, 2021
3c1c49e
Ensure we spawn the block import worker as an essential task (#8155)
bkchr Feb 19, 2021
e808d14
Update to libp2p-0.35.1 (#8141)
romanb Feb 22, 2021
824adac
contracts: Consider contract size in weights (#8086)
athei Feb 22, 2021
11e879f
Allow `transfer_keep_alive` to transfer all free balance (#8125)
gui1117 Feb 22, 2021
fd88fbf
Migrate examples to use pallet macro (#8138)
gui1117 Feb 22, 2021
5949485
Make keystore return `None` when a key doesn't exist (#8163)
bkchr Feb 22, 2021
4f9ee57
contracts: Convert to framev2 macros (#8157)
athei Feb 22, 2021
061ff5d
Fix: stash account reaped when ledger.active == ED (#8170)
gui1117 Feb 22, 2021
2237564
Bump thread_local (#8174)
arkpar Feb 22, 2021
528c14b
Return number of keys removed when calling `storage_kill` on child tr…
shawntabrizi Feb 22, 2021
904495b
Make Regex in ss58codec and secret phrase crypto static (#8117) (#8177)
anvie Feb 22, 2021
e6ac7e7
Add a Prometheus alert on no incoming connection (#7517)
tomaka Feb 23, 2021
27e1f89
Bump lru dependency (#8182)
tomaka Feb 23, 2021
1c434cd
Decouple Staking and Election - Part 2 Unsigned Phase (#7909)
kianenigma Feb 23, 2021
ad8c585
Remove suicide from frame_system weights (#8184)
s3krit Feb 23, 2021
c736c60
Reserve ss58 prefix 48 for Neatcoin (#8165)
sorpaas Feb 23, 2021
8643b9d
Make `on_slot` return the block with the post header (#8188)
bkchr Feb 24, 2021
6bd9aad
[multisig, insubstantial] WeightTooLow -> MaxWeightTooLow (#8112)
Feb 24, 2021
1db5108
Update lib.rs (#8192)
kianenigma Feb 24, 2021
61b1eb8
Fix transactions not being propagated to authorities (#8212)
tomaka Feb 26, 2021
76ce4dc
Merge remote-tracking branch 'upstream/polkadot-v0.8.29' into feature…
MRamanenkau Sep 7, 2022
177de33
Fixes after merge
MRamanenkau Sep 7, 2022
6703bd9
Use actual ddc-pallet
MRamanenkau Sep 7, 2022
e86ec81
Update ddc-pallet
MRamanenkau Sep 7, 2022
4bd527a
Update codec versions
MRamanenkau Sep 7, 2022
46870a5
Fix issue with getrandom
MRamanenkau Sep 7, 2022
f9e76d5
Add PalletInfo implementation
MRamanenkau Sep 8, 2022
45487ea
Fix ddc-metrics-offchain-worker
MRamanenkau Sep 8, 2022
f015dc8
Add PalletInfo implementation in erc721
MRamanenkau Sep 8, 2022
92cfcc4
Fix remining issues with tests
MRamanenkau Sep 8, 2022
2e17c3f
Fix path to binary
MRamanenkau Sep 8, 2022
d31bd2a
Update ddc pallet
MRamanenkau Sep 9, 2022
ad98d51
Fix bridge tests
MRamanenkau Sep 9, 2022
4224d54
Use constract_runtime! in ddc-metrics-offchain-worker
MRamanenkau Sep 9, 2022
86e82fd
Fix PalletInfo in erc721
MRamanenkau Sep 9, 2022
6b09ce6
Update ddc-pallet
MRamanenkau Sep 9, 2022
b1cd98a
Adjust max wasm code size
MRamanenkau Sep 10, 2022
38c9954
Update MaxCodeSize
MRamanenkau Sep 12, 2022
c903063
Add release notes
MRamanenkau Sep 12, 2022
a1040cb
Remove old commented code
MRamanenkau Sep 13, 2022
dbf947c
Merge branch 'feature/update-to-polkadot-v0-8-28' into feature/update…
MRamanenkau Nov 29, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Migrate pallet-timestamp to pallet attribute macro. (paritytech#8078)
* Migrate pallet-timestamp to pallet attribute macro.

* Migrate inherent.

* Unify private visbility.

* Update benchmarking.

* Update storage usages.
  • Loading branch information
shaunxw authored Feb 10, 2021
commit ba290e0c8b55d6312ffe7c6c180e22618fa9b6f0
8 changes: 4 additions & 4 deletions frame/timestamp/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ benchmarks! {
set {
let t = MAX_TIME;
// Ignore write to `DidUpdate` since it transient.
let did_update_key = crate::DidUpdate::hashed_key().to_vec();
let did_update_key = crate::DidUpdate::<T>::hashed_key().to_vec();
frame_benchmarking::benchmarking::add_to_whitelist(TrackedStorageKey {
key: did_update_key,
has_been_read: false,
Expand All @@ -47,13 +47,13 @@ benchmarks! {
on_finalize {
let t = MAX_TIME;
Timestamp::<T>::set(RawOrigin::None.into(), t.into())?;
ensure!(DidUpdate::exists(), "Time was not set.");
ensure!(DidUpdate::<T>::exists(), "Time was not set.");
// Ignore read/write to `DidUpdate` since it is transient.
let did_update_key = crate::DidUpdate::hashed_key().to_vec();
let did_update_key = crate::DidUpdate::<T>::hashed_key().to_vec();
frame_benchmarking::benchmarking::add_to_whitelist(did_update_key.into());
}: { Timestamp::<T>::on_finalize(t.into()); }
verify {
ensure!(!DidUpdate::exists(), "Time was not removed.");
ensure!(!DidUpdate::<T>::exists(), "Time was not removed.");
}
}

Expand Down
206 changes: 107 additions & 99 deletions frame/timestamp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//! # Timestamp Module
//! # Timestamp Pallet
//!
//! The Timestamp module provides functionality to get and set the on-chain time.
//! The Timestamp pallet provides functionality to get and set the on-chain time.
//!
//! - [`timestamp::Config`](./trait.Config.html)
//! - [`Call`](./enum.Call.html)
//! - [`Module`](./struct.Module.html)
//! - [`Pallet`](./struct.Pallet.html)
//!
//! ## Overview
//!
//! The Timestamp module allows the validators to set and validate a timestamp with each block.
//! The Timestamp pallet allows the validators to set and validate a timestamp with each block.
//!
//! It uses inherents for timestamp data, which is provided by the block author and validated/verified
//! by other validators. The timestamp can be set only once per block and must be set each block.
//! There could be a constraint on how much time must pass before setting the new timestamp.
//!
//! **NOTE:** The Timestamp module is the recommended way to query the on-chain time instead of using
//! **NOTE:** The Timestamp pallet is the recommended way to query the on-chain time instead of using
//! an approach based on block numbers. The block number based time measurement can cause issues
//! because of cumulative calculation errors and hence should be avoided.
//!
Expand All @@ -52,11 +52,11 @@
//!
//! ## Usage
//!
//! The following example shows how to use the Timestamp module in your custom module to query the current timestamp.
//! The following example shows how to use the Timestamp pallet in your custom pallet to query the current timestamp.
//!
//! ### Prerequisites
//!
//! Import the Timestamp module into your custom module and derive the module configuration
//! Import the Timestamp pallet into your custom pallet and derive the pallet configuration
//! trait from the timestamp trait.
//!
//! ### Get current timestamp
Expand All @@ -83,10 +83,10 @@
//!
//! ### Example from the FRAME
//!
//! The [Session module](https://github.com/paritytech/substrate/blob/master/frame/session/src/lib.rs) uses
//! the Timestamp module for session management.
//! The [Session pallet](https://github.com/paritytech/substrate/blob/master/frame/session/src/lib.rs) uses
//! the Timestamp pallet for session management.
//!
//! ## Related Modules
//! ## Related Pallets
//!
//! * [Session](../pallet_session/index.html)

Expand All @@ -96,54 +96,83 @@ mod benchmarking;
pub mod weights;

use sp_std::{result, cmp};
use sp_inherents::{ProvideInherent, InherentData, InherentIdentifier};
use sp_inherents::InherentData;
#[cfg(feature = "std")]
use frame_support::debug;
use frame_support::{
Parameter, decl_storage, decl_module,
traits::{Time, UnixTime, Get},
weights::{DispatchClass, Weight},
};
use frame_support::traits::{Time, UnixTime};
use sp_runtime::{
RuntimeString,
traits::{
AtLeast32Bit, Zero, SaturatedConversion, Scale,
}
};
use frame_system::ensure_none;
use sp_timestamp::{
InherentError, INHERENT_IDENTIFIER, InherentType,
OnTimestampSet,
};
pub use weights::WeightInfo;

/// The module configuration trait
pub trait Config: frame_system::Config {
/// Type used for expressing timestamp.
type Moment: Parameter + Default + AtLeast32Bit
+ Scale<Self::BlockNumber, Output = Self::Moment> + Copy;
pub use pallet::*;

/// Something which can be notified when the timestamp is set. Set this to `()` if not needed.
type OnTimestampSet: OnTimestampSet<Self::Moment>;
#[frame_support::pallet]
pub mod pallet {
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
use super::*;

/// The minimum period between blocks. Beware that this is different to the *expected* period
/// that the block production apparatus provides. Your chosen consensus system will generally
/// work with this to determine a sensible block time. e.g. For Aura, it will be double this
/// period on default settings.
type MinimumPeriod: Get<Self::Moment>;
/// The pallet configuration trait
#[pallet::config]
pub trait Config: frame_system::Config {
/// Type used for expressing timestamp.
type Moment: Parameter + Default + AtLeast32Bit
+ Scale<Self::BlockNumber, Output = Self::Moment> + Copy;

/// Weight information for extrinsics in this pallet.
type WeightInfo: WeightInfo;
}
/// Something which can be notified when the timestamp is set. Set this to `()` if not needed.
type OnTimestampSet: OnTimestampSet<Self::Moment>;

decl_module! {
pub struct Module<T: Config> for enum Call where origin: T::Origin {
/// The minimum period between blocks. Beware that this is different to the *expected* period
/// that the block production apparatus provides. Your chosen consensus system will generally
/// work with this to determine a sensible block time. e.g. For Aura, it will be double this
/// period on default settings.
const MinimumPeriod: T::Moment = T::MinimumPeriod::get();
#[pallet::constant]
type MinimumPeriod: Get<Self::Moment>;

/// Weight information for extrinsics in this pallet.
type WeightInfo: WeightInfo;
}

#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
pub struct Pallet<T>(PhantomData<T>);

/// Current time for the current block.
#[pallet::storage]
#[pallet::getter(fn now)]
pub type Now<T: Config> = StorageValue<_, T::Moment, ValueQuery>;

/// Did the timestamp get updated in this block?
#[pallet::storage]
pub(super) type DidUpdate<T: Config> = StorageValue<_, bool, ValueQuery>;

#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
/// dummy `on_initialize` to return the weight used in `on_finalize`.
fn on_initialize(_n: BlockNumberFor<T>) -> Weight {
// weight of `on_finalize`
T::WeightInfo::on_finalize()
}

/// # <weight>
/// - `O(1)`
/// - 1 storage deletion (codec `O(1)`).
/// # </weight>
fn on_finalize(_n: BlockNumberFor<T>) {
assert!(DidUpdate::<T>::take(), "Timestamp must be updated once in the block");
}
}

#[pallet::call]
impl<T: Config> Pallet<T> {
/// Set the current time.
///
/// This call should be invoked exactly once per block. It will panic at the finalization
Expand All @@ -159,51 +188,65 @@ decl_module! {
/// - 1 storage read and 1 storage mutation (codec `O(1)`). (because of `DidUpdate::take` in `on_finalize`)
/// - 1 event handler `on_timestamp_set`. Must be `O(1)`.
/// # </weight>
#[weight = (
#[pallet::weight((
T::WeightInfo::set(),
DispatchClass::Mandatory
)]
fn set(origin, #[compact] now: T::Moment) {
))]
pub(super) fn set(origin: OriginFor<T>, #[pallet::compact] now: T::Moment) -> DispatchResultWithPostInfo {
ensure_none(origin)?;
assert!(!<Self as Store>::DidUpdate::exists(), "Timestamp must be updated only once in the block");
assert!(!DidUpdate::<T>::exists(), "Timestamp must be updated only once in the block");
let prev = Self::now();
assert!(
prev.is_zero() || now >= prev + T::MinimumPeriod::get(),
"Timestamp must increment by at least <MinimumPeriod> between sequential blocks"
);
<Self as Store>::Now::put(now);
<Self as Store>::DidUpdate::put(true);
Now::<T>::put(now);
DidUpdate::<T>::put(true);

<T::OnTimestampSet as OnTimestampSet<_>>::on_timestamp_set(now);
}

/// dummy `on_initialize` to return the weight used in `on_finalize`.
fn on_initialize() -> Weight {
// weight of `on_finalize`
T::WeightInfo::on_finalize()
Ok(().into())
}
}

/// # <weight>
/// - `O(1)`
/// - 1 storage deletion (codec `O(1)`).
/// # </weight>
fn on_finalize() {
assert!(<Self as Store>::DidUpdate::take(), "Timestamp must be updated once in the block");
#[pallet::inherent]
impl<T: Config> ProvideInherent for Pallet<T> {
type Call = Call<T>;
type Error = InherentError;
const INHERENT_IDENTIFIER: InherentIdentifier = INHERENT_IDENTIFIER;

fn create_inherent(data: &InherentData) -> Option<Self::Call> {
let data: T::Moment = extract_inherent_data(data)
.expect("Gets and decodes timestamp inherent data")
.saturated_into();

let next_time = cmp::max(data, Self::now() + T::MinimumPeriod::get());
Some(Call::set(next_time.into()))
}
}
}

decl_storage! {
trait Store for Module<T: Config> as Timestamp {
/// Current time for the current block.
pub Now get(fn now): T::Moment;
fn check_inherent(call: &Self::Call, data: &InherentData) -> result::Result<(), Self::Error> {
const MAX_TIMESTAMP_DRIFT_MILLIS: u64 = 30 * 1000;

/// Did the timestamp get updated in this block?
DidUpdate: bool;
let t: u64 = match call {
Call::set(ref t) => t.clone().saturated_into::<u64>(),
_ => return Ok(()),
};

let data = extract_inherent_data(data).map_err(|e| InherentError::Other(e))?;

let minimum = (Self::now() + T::MinimumPeriod::get()).saturated_into::<u64>();
if t > data + MAX_TIMESTAMP_DRIFT_MILLIS {
Err(InherentError::Other("Timestamp too far in future to accept".into()))
} else if t < minimum {
Err(InherentError::ValidAtTimestamp(minimum))
} else {
Ok(())
}
}
}
}

impl<T: Config> Module<T> {
impl<T: Config> Pallet<T> {
/// Get the current time for the current block.
///
/// NOTE: if this function is called prior to setting the timestamp,
Expand All @@ -215,7 +258,7 @@ impl<T: Config> Module<T> {
/// Set the timestamp to something in particular. Only used for tests.
#[cfg(feature = "std")]
pub fn set_timestamp(now: T::Moment) {
<Self as Store>::Now::put(now);
Now::<T>::put(now);
}
}

Expand All @@ -225,42 +268,7 @@ fn extract_inherent_data(data: &InherentData) -> Result<InherentType, RuntimeStr
.ok_or_else(|| "Timestamp inherent data is not provided.".into())
}

impl<T: Config> ProvideInherent for Module<T> {
type Call = Call<T>;
type Error = InherentError;
const INHERENT_IDENTIFIER: InherentIdentifier = INHERENT_IDENTIFIER;

fn create_inherent(data: &InherentData) -> Option<Self::Call> {
let data: T::Moment = extract_inherent_data(data)
.expect("Gets and decodes timestamp inherent data")
.saturated_into();

let next_time = cmp::max(data, Self::now() + T::MinimumPeriod::get());
Some(Call::set(next_time.into()))
}

fn check_inherent(call: &Self::Call, data: &InherentData) -> result::Result<(), Self::Error> {
const MAX_TIMESTAMP_DRIFT_MILLIS: u64 = 30 * 1000;

let t: u64 = match call {
Call::set(ref t) => t.clone().saturated_into::<u64>(),
_ => return Ok(()),
};

let data = extract_inherent_data(data).map_err(|e| InherentError::Other(e))?;

let minimum = (Self::now() + T::MinimumPeriod::get()).saturated_into::<u64>();
if t > data + MAX_TIMESTAMP_DRIFT_MILLIS {
Err(InherentError::Other("Timestamp too far in future to accept".into()))
} else if t < minimum {
Err(InherentError::ValidAtTimestamp(minimum))
} else {
Ok(())
}
}
}

impl<T: Config> Time for Module<T> {
impl<T: Config> Time for Pallet<T> {
type Moment = T::Moment;

/// Before the first set of now with inherent the value returned is zero.
Expand All @@ -272,7 +280,7 @@ impl<T: Config> Time for Module<T> {
/// Before the timestamp inherent is applied, it returns the time of previous block.
///
/// On genesis the time returned is not valid.
impl<T: Config> UnixTime for Module<T> {
impl<T: Config> UnixTime for Pallet<T> {
fn now() -> core::time::Duration {
// now is duration since unix epoch in millisecond as documented in
// `sp_timestamp::InherentDataProvider`.
Expand Down