Skip to content

Commit

Permalink
Backport timestamp logging fix (#5459)
Browse files Browse the repository at this point in the history
03c45b9

---------

Co-authored-by: Gonçalo Pestana <[email protected]>
  • Loading branch information
bkchr and gpestana authored Aug 27, 2024
1 parent 16b0fd0 commit 4fb7eaa
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: patch
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 4fb7eaa

Please sign in to comment.