Repository navigation
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. External sites
ReviewsSee the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste 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. |
janb84
left a comment
There was a problem hiding this comment.
Concept ACK 7bb44a4
I like the clarity / readability this changes gives. It will even provide less proficient in C++ users to read consensus code.
Maybe split commit in kernel/consensus touching and the rest. In that way it's easy to ACK / review the consensus relevant changes.
Some NIT suggestions to use std::chrono::<<duration>> can be done on more places but I have limited the NITS to hear the current thinking first :)
| constexpr int HOUR_IN_SECONDS{TicksSeconds(1h)}; | ||
| constexpr int DAY_IN_SECONDS{TicksSeconds(24h)}; | ||
| constexpr int WEEK_IN_SECONDS{TicksSeconds(7 * 24h)}; | ||
| constexpr int YEAR_IN_SECONDS{TicksSeconds(std::chrono::years{1})}; |
There was a problem hiding this comment.
Just to unify this section I would opt for using std::chrono for every line. (not Blocking bike-shedding NIT)
| constexpr int HOUR_IN_SECONDS{TicksSeconds(1h)}; | |
| constexpr int DAY_IN_SECONDS{TicksSeconds(24h)}; | |
| constexpr int WEEK_IN_SECONDS{TicksSeconds(7 * 24h)}; | |
| constexpr int YEAR_IN_SECONDS{TicksSeconds(std::chrono::years{1})}; | |
| constexpr int HOUR_IN_SECONDS{TicksSeconds(std::chrono::hours{1})}; | |
| constexpr int DAY_IN_SECONDS{TicksSeconds(std::chrono::days{1})}; | |
| constexpr int WEEK_IN_SECONDS{TicksSeconds(std::chrono::weeks{1})}; | |
| constexpr int YEAR_IN_SECONDS{TicksSeconds(std::chrono::years{1})}; |
| /// protection against fingerprinting. Set to one month, denominated in seconds. | ||
| static constexpr int STALE_RELAY_AGE_LIMIT = 30 * 24 * 60 * 60; | ||
| /// protection against fingerprinting. Set to one month. | ||
| static constexpr int STALE_RELAY_AGE_LIMIT{TicksSeconds(30 * 24h)}; |
There was a problem hiding this comment.
NIT: why not go one step further for even more clarity ?
| static constexpr int STALE_RELAY_AGE_LIMIT{TicksSeconds(30 * 24h)}; | |
| static constexpr int STALE_RELAY_AGE_LIMIT{TicksSeconds(std::chrono::days{30})}; |
Note: not to use std::chrono::month{1};
| /// limiting block relay. Set to one week, denominated in seconds. | ||
| static constexpr int HISTORICAL_BLOCK_AGE = 7 * 24 * 60 * 60; | ||
| /// limiting block relay. Set to one week. | ||
| static constexpr int HISTORICAL_BLOCK_AGE{TicksSeconds(7 * 24h)}; |
There was a problem hiding this comment.
| static constexpr int HISTORICAL_BLOCK_AGE{TicksSeconds(7 * 24h)}; | |
| static constexpr int HISTORICAL_BLOCK_AGE{TicksSeconds(std::chrono::weeks{1})}; |
|
~0, some minor clarity improvements here and there but for the most part I don't see the point as this doesn't add any actual type safety or clarity. I don't find |
7bb44a4 to
96f6453
Compare
|
Thanks for the review and feedback. I agree that E.g. Likewise, The branch is now split by risk, with exact-value coverage for the consensus-sensitive changes. |
96f6453 to
46fe617
Compare
|
🚧 At least one of the CI tasks failed. HintsTry to run the tests locally, according to the documentation. However, a CI failure may still
Leave a comment here, if you need help tracking down a confusing failure. |
46fe617 to
7104b41
Compare
maflcko
left a comment
There was a problem hiding this comment.
Tend to agree with stickies. The changes as-is also violate the util/time.h docs.
| * Ref: https://github.com/bitcoin/bitcoin/pull/1026 | ||
| */ | ||
| static constexpr int64_t MAX_BLOCK_TIME_GAP = 90 * 60; | ||
| static constexpr int64_t MAX_BLOCK_TIME_GAP{TicksSeconds(90min)}; |
There was a problem hiding this comment.
This seems like a step in the wrong direction. The docstring of TicksSeconds also says that it should be avoided in code.
the correct approach would be to write constexpr auto ...{90min}; and then use proper chrono types below: std::chrono::seconds secs{blockDate.secsTo(currentDate)};
Also, the pull description seems wrong. I fail to see how any of the changes here are related to ODR? |
7104b41 to
7baa431
Compare
They're not, I noticed these raw duration expressions while reviewing #35792's changes, which is why I originally described this as a follow-up.
Thanks for the suggestion, I reworked the branch so durations remain typed where the surrounding APIs already support chrono, and I like it a lot better this way. |
| m_animation.setTargetObject(this); | ||
| m_animation.setPropertyName("pos"); | ||
| m_animation.setDuration(300 /* ms */); | ||
| m_animation.setDuration(count_milliseconds(300ms)); |
There was a problem hiding this comment.
not sure what exactly this is trying to enforce or harden. A plain 300 /* ms */ seems more readable and direct than a count_milliseconds(300ms) or the alternative used in other parts of this pull: 300ms / 1ms.
I think the chrono types should only be used when the type adds some compile-time checks. And I don't think replacing a 300-raw-int literal with a 300-chrono-literal, and a cast to int is adding any checks.
There was a problem hiding this comment.
Sure, I’ve reverted the ones that were arguably noisier than the original code. Thanks for the pushback!
There was a problem hiding this comment.
think the chrono types should only be used when the type adds some compile-time checks.
I'd argue it's also valuable when we can remove comments that had to explain the values (e.g. 14 * 24 * 60 * 60; // two weeks) or when we can use the literals in range checks, e.g. if (delta_seconds <= 0 || delta_seconds > 3600) {.
7baa431 to
178eb28
Compare
178eb28 to
0716f3e
Compare
0716f3e to
cbaa16a
Compare
|
🚧 At least one of the CI tasks failed. HintsTry to run the tests locally, according to the documentation. However, a CI failure may still
Leave a comment here, if you need help tracking down a confusing failure. |
Parse the requested delta as seconds, compare it against typed limits, and pass it directly to the scheduler interfaces.
Make `formatNiceTimeOffset` accept seconds so its comparisons and divisions retain units.
Callers now construct durations from raw values provided by Qt or consensus code.
Co-authored-by: MarcoFalke <*~=`'#}+{/-|&$^[email protected]>
Pass typed durations from the peer menu to `banSelectedNode`, converting only at the integer `Node::ban` interface. Keep the one-year action exactly 365 days. Co-authored-by: janb84 <[email protected]>
Name the assumed blocks per day directly in the prune backup estimate.
Store the rolling fee halflife as `std::chrono::seconds` and convert it to a scalar only for the decay calculation. The existing decay test independently pins the duration to 43,200 seconds.
Use `Consensus::Params::PowTargetSpacing()` so the pruning and RPC calculations divide durations directly. This keeps their units visible and avoids converting either operand to raw seconds.
State fixed durations in their natural units while preserving integer interfaces and exact values.
Store relay age limits as durations and use typed block timestamps for the time arithmetic. Convert only where `GetBlockProofEquivalentTime` still returns integer seconds. Co-authored-by: janb84 <[email protected]>
Pin literal target timespan and spacing values for every built-in chain. These assertions provide a redundant units check before the following representation-only refactor.
Express each built-in chain’s target timespan and spacing in its natural duration unit. The preceding characterization pins the exact integer values consumed by consensus code. Co-authored-by: janb84 <[email protected]>
Store the two-hour allowance as a duration and use it directly in time-point comparisons. Convert it only where existing interfaces still operate on integer seconds. The `chain_tests/basic_tests` assertion pins the duration to 7,200 seconds.
Make the assumevalid test hit exactly two weeks of equivalent work and pin that scripts remain checked at the inclusive threshold. Split longer header sequences at `MAX_HEADERS_RESULTS`.
Express the inclusive two-week comparison directly in integer seconds. The preceding functional characterization pins the exact threshold.
cbaa16a to
261fff9
Compare
|
This has not received review for some time now and the response to the changes has been somewhat lukewarm. I'm also not entirely convinced that |
|
Yeah, I like the concept of moving toward chrono types, but if the casts are just "normalized" or "hidden" via So I think stuff like this is fine to use: int blockcount = std::chrono::days{30} / chainman.GetParams().GetConsensus().PowTargetSpacing();However, this is not: consensus.nPowTargetSpacing = 10min / 1s;I'd be happy to review a pull with the first type of changes, but the second one can be left for now as-is. |
|
Up for grabs |

Problem: Several fixed-duration calculations use raw integer time counts, leaving their units implicit and allowing unrelated integer values to be mixed.
Fix: Use
std::chronotypes through calculations where the surrounding APIs already support them, including GUI formatting, peer bans, scheduler forwarding, block timestamps, and target-spacing arithmetic.Where carrying chrono through an integer interface would broaden the change or make the result harder to read, this PR leaves the expression unchanged or keeps the conversion simply
duration / 1s.The remaining integer interfaces receive the same values, and characterization tests pin the PoW timing and inclusive assumevalid threshold.