-
Notifications
You must be signed in to change notification settings - Fork 37.7k
refactor: Make adjusted time type safe #25786
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
The head ref may contain hidden characters: "2208-time-type-\u{1F4B7}"
Conversation
To be used in the next commit
fa8a30b
to
eeee5ad
Compare
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept ACK
@@ -275,6 +276,11 @@ class CBlockIndex | |||
*/ | |||
bool HaveTxsDownloaded() const { return nChainTx != 0; } | |||
|
|||
NodeSeconds Time() const |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: This will end up renaming GetBlockTime()
, right? (assuming that in the long run GetBlockTime()
would be entirely replaced by Time()
)
we could avoid that with something like the following:
template <typename T = int64_t>
auto GetBlockTime() const -> T
{
static_assert(std::is_same<T, int64_t>::value || std::is_same<T, NodeSeconds>::value);
if constexpr (std::is_same<T, int64_t>::value) {
return (T)nTime;
} else {
return NodeSeconds{std::chrono::seconds{nTime}};
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I picked a different name because it felt weird to repeat the class type in the method again. That is, calling block.GetBlockTime()
seems better replaced by block.GetTime()
or block.Time()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code review ACK eeee5ad. Confirmed type changes and equivalent code changes only.
It's pretty hard to keep tract of all the different time functions. I think it would be really nice if all of the deprecated time functions could just be eliminated. Also if there are time functions that are never used (like ::Now()
?) or only infrequently used I think it would be nice to drop them from util/time.h
and just declare them locally close to where they are used to avoid having so many confusing similarly named util functions.
I am doing this in other pull requests. For example, |
This makes follow-ups easier to review. Also, it makes sense by itself.