Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate pallet-timestamp to umbrella crate #6523

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 1 addition & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 4 additions & 27 deletions substrate/frame/timestamp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,46 +20,23 @@ targets = ["x86_64-unknown-linux-gnu"]
codec = { features = ["derive", "max-encoded-len"], workspace = true }
log = { workspace = true }
scale-info = { features = ["derive"], workspace = true }
frame-benchmarking = { optional = true, workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
sp-inherents = { workspace = true }
sp-io = { optional = true, workspace = true }
sp-runtime = { workspace = true }
sp-storage = { workspace = true }
frame = { workspace = true, features = ["experimental", "runtime"] }
sp-timestamp = { workspace = true }

docify = { workspace = true }

[dev-dependencies]
sp-core = { workspace = true, default-features = true }
sp-io = { workspace = true, default-features = true }

[features]
default = ["std"]
std = [
"codec/std",
"frame-benchmarking?/std",
"frame-support/std",
"frame-system/std",
"frame/std",
"log/std",
"scale-info/std",
"sp-core/std",
"sp-inherents/std",
"sp-io?/std",
"sp-runtime/std",
"sp-storage/std",
"sp-timestamp/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"sp-io",
"sp-runtime/runtime-benchmarks",
"frame/runtime-benchmarks",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"sp-runtime/try-runtime",
"frame/try-runtime",
]
9 changes: 2 additions & 7 deletions substrate/frame/timestamp/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,8 @@
//! Timestamp pallet benchmarking.

#![cfg(feature = "runtime-benchmarks")]

use frame_benchmarking::{benchmarking::add_to_whitelist, v2::*};
use frame_support::traits::OnFinalize;
use frame_system::RawOrigin;
use sp_storage::TrackedStorageKey;

use crate::*;
use frame::benchmarking::prelude::*;

const MAX_TIME: u32 = 100;

Expand All @@ -37,7 +32,7 @@ mod benchmarks {
let t = MAX_TIME;
// Ignore write to `DidUpdate` since it transient.
let did_update_key = DidUpdate::<T>::hashed_key().to_vec();
add_to_whitelist(TrackedStorageKey {
add_to_whitelist(frame::traits::TrackedStorageKey {
key: did_update_key,
reads: 0,
writes: 1,
Expand Down
19 changes: 9 additions & 10 deletions substrate/frame/timestamp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,11 @@
//!
//! ```
//! use pallet_timestamp::{self as timestamp};
//! use frame::prelude::*;
//!
//! #[frame_support::pallet]
//! #[frame::pallet]
//! pub mod pallet {
//! use super::*;
//! use frame_support::pallet_prelude::*;
//! use frame_system::pallet_prelude::*;
//!
//! #[pallet::pallet]
//! pub struct Pallet<T>(_);
Expand Down Expand Up @@ -134,18 +133,18 @@ mod tests;
pub mod weights;

use core::{cmp, result};
use frame_support::traits::{OnTimestampSet, Time, UnixTime};
use sp_runtime::traits::{AtLeast32Bit, SaturatedConversion, Scale, Zero};
use frame::{
runtime::prelude::*,
traits::{AtLeast32Bit, OnTimestampSet, Scale, Time, UnixTime},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AtLeast32Bit appears in many pallets, we should add it to the umbrella crate.

};
use sp_timestamp::{InherentError, InherentType, INHERENT_IDENTIFIER};
pub use weights::WeightInfo;

pub use pallet::*;

#[frame_support::pallet]
#[frame::pallet]
pub mod pallet {
use super::*;
use frame_support::{derive_impl, pallet_prelude::*};
use frame_system::pallet_prelude::*;

/// Default preludes for [`Config`].
pub mod config_preludes {
Expand All @@ -157,7 +156,7 @@ pub mod pallet {
#[derive_impl(frame_system::config_preludes::TestDefaultConfig, no_aggregated_types)]
impl frame_system::DefaultConfig for TestDefaultConfig {}

#[frame_support::register_default_impl(TestDefaultConfig)]
#[register_default_impl(TestDefaultConfig)]
impl DefaultConfig for TestDefaultConfig {
type Moment = u64;
type OnTimestampSet = ();
Expand Down Expand Up @@ -354,7 +353,7 @@ impl<T: Config> Time for Pallet<T> {
/// A type that represents a unit of time.
type Moment = T::Moment;

fn now() -> Self::Moment {
fn now() -> <pallet::Pallet<T> as Time>::Moment {
Now::<T>::get()
}
}
Expand Down
8 changes: 2 additions & 6 deletions substrate/frame/timestamp/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,11 @@

use super::*;
use crate as pallet_timestamp;

use frame_support::{derive_impl, parameter_types, traits::ConstU64};
use sp_io::TestExternalities;
use sp_runtime::BuildStorage;

use frame::testing_prelude::*;
type Block = frame_system::mocking::MockBlock<Test>;
type Moment = u64;

frame_support::construct_runtime!(
construct_runtime!(
pub enum Test
{
System: frame_system,
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/timestamp/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
//! Tests for the Timestamp module.

use crate::mock::*;
use frame_support::assert_ok;
use frame::testing_prelude::*;

#[test]
fn timestamp_works() {
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/timestamp/src/weights.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading