Skip to content

Commit

Permalink
Get the block timestamp using the Time trait
Browse files Browse the repository at this point in the history
  • Loading branch information
teor2345 committed Dec 19, 2024
1 parent ff07a65 commit 797ab57
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
14 changes: 11 additions & 3 deletions crates/pallet-domains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ mod pallet {
use frame_support::pallet_prelude::*;
use frame_support::traits::fungible::{Inspect, InspectHold, Mutate, MutateHold};
use frame_support::traits::tokens::Preservation;
use frame_support::traits::Randomness as RandomnessT;
use frame_support::traits::{Randomness as RandomnessT, Time};
use frame_support::weights::Weight;
use frame_support::{Identity, PalletError};
use frame_system::pallet_prelude::*;
Expand All @@ -248,7 +248,7 @@ mod pallet {
use sp_std::fmt::Debug;
use sp_subspace_mmr::MmrProofVerifier;
use subspace_core_primitives::{Randomness, U256};
use subspace_runtime_primitives::{Moment, StorageFee};
use subspace_runtime_primitives::StorageFee;

#[pallet::config]
pub trait Config: frame_system::Config<Hash: Into<H256>> {
Expand Down Expand Up @@ -390,6 +390,9 @@ mod pallet {
/// Storage fee interface used to deal with bundle storage fee
type StorageFee: StorageFee<BalanceOf<Self>>;

/// The block timestamp
type BlockTimestamp: Time;

/// The block slot
type BlockSlot: BlockSlot<Self>;

Expand Down Expand Up @@ -1913,7 +1916,12 @@ mod pallet {
Into::<H256>::into(Self::extrinsics_shuffling_seed()).to_fixed_bytes(),
);

let timestamp = Moment::default();
// There is no actual conversion here, but the trait bounds required to prove that
// (and debug-print the error in expect()) are very verbose.
let timestamp = T::BlockTimestamp::now()
.try_into()
.map_err(|_| ())
.expect("Moment is the same type in both pallets; qed");

let invalid_inherent_extrinsic_data = InvalidInherentExtrinsicData {
extrinsics_shuffling_seed,
Expand Down
1 change: 1 addition & 0 deletions crates/pallet-domains/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ impl pallet_domains::Config for Test {
type Randomness = MockRandomness;
type PalletId = DomainsPalletId;
type StorageFee = DummyStorageFee;
type BlockTimestamp = pallet_timestamp::Pallet<Test>;
type BlockSlot = DummyBlockSlot;
type DomainsTransfersTracker = MockDomainsTransfersTracker;
type MaxInitialDomainAccounts = MaxInitialDomainAccounts;
Expand Down
1 change: 1 addition & 0 deletions crates/subspace-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,7 @@ impl pallet_domains::Config for Runtime {
type Randomness = Subspace;
type PalletId = DomainsPalletId;
type StorageFee = TransactionFees;
type BlockTimestamp = pallet_timestamp::Pallet<Runtime>;
type BlockSlot = BlockSlot;
type BundleLongevity = BundleLongevity;
type DomainsTransfersTracker = Transporter;
Expand Down
1 change: 1 addition & 0 deletions test/subspace-test-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,7 @@ impl pallet_domains::Config for Runtime {
type MinNominatorStake = MinNominatorStake;
type PalletId = DomainsPalletId;
type StorageFee = TransactionFees;
type BlockTimestamp = pallet_timestamp::Pallet<Runtime>;
type BlockSlot = BlockSlot;
type BundleLongevity = BundleLongevity;
type DomainsTransfersTracker = Transporter;
Expand Down

0 comments on commit 797ab57

Please sign in to comment.