Skip to content

Commit

Permalink
pallet-timestamp: UnixTime::now implementation logs error only if c…
Browse files Browse the repository at this point in the history
…alled at genesis (paritytech#5055)

This PR reverts the removal of an [`if`
statement](paritytech@7ecf3f7#diff-8bf31ba8d9ebd6377983fd7ecc7f4e41cb1478a600db1a15a578d1ae0e8ed435L370)
merged recently, which affected test output verbosity of several pallets
(e.g. staking, EPM, and potentially others).

More generally, the `UnixTime::now` implementation of the timestamp
pallet should log an error *only* when called at the genesis block.
  • Loading branch information
gpestana authored and TarekkMA committed Aug 2, 2024
1 parent c557cb6 commit 7ae62e0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
11 changes: 11 additions & 0 deletions prdoc/pr_5055.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
title: Only log error in `UnixTime::now` call of the pallet-timestamp implementation if called at genesis

doc:
- audience: Runtime Dev
description: |
This minor patch re-introduces a check to ensure that the `UnixTime::now` implementation in the timestamp only
logs an error if called at the genesis block.

crates:
- name: pallet-timestamp
bump: minor
10 changes: 6 additions & 4 deletions substrate/frame/timestamp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,10 +368,12 @@ impl<T: Config> UnixTime for Pallet<T> {
// `sp_timestamp::InherentDataProvider`.
let now = Now::<T>::get();

log::error!(
target: "runtime::timestamp",
"`pallet_timestamp::UnixTime::now` is called at genesis, invalid value returned: 0",
);
if now == T::Moment::zero() {
log::error!(
target: "runtime::timestamp",
"`pallet_timestamp::UnixTime::now` is called at genesis, invalid value returned: 0",
);
}

core::time::Duration::from_millis(now.saturated_into::<u64>())
}
Expand Down

0 comments on commit 7ae62e0

Please sign in to comment.