Skip to content

Conversation

@maflcko
Copy link
Member

@maflcko maflcko commented May 6, 2025

Currently mocktime is written to a global, which may leak between sub-tests (albeit some tests try to reset the mocktime on a best-effort basis). Also, when advancing it, one has to keep a counter variable around.

Fix both issues by a new ElapseTime helper, which resets the mocktime once it goes out of scope. Also, it has a method to advance the mocktime by a delta.

@DrahtBot
Copy link
Contributor

DrahtBot commented May 6, 2025

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage & Benchmarks

For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/32430.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK l0rinc
Stale ACK w0xlt

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #33106 (policy: lower the default blockmintxfee, incrementalrelayfee, minrelaytxfee by glozow)
  • #32941 (p2p: TxOrphanage revamp cleanups by glozow)
  • #32414 (validation: periodically flush dbcache during reindex-chainstate by andrewtoth)
  • #29700 (kernel, refactor: return error status on all fatal errors by ryanofsky)
  • #28676 (Cluster mempool implementation by sdaftuar)
  • #17783 (common: Disallow calling IsArgSet() on ALLOW_LIST options by ryanofsky)
  • #17580 (refactor: Add ALLOW_LIST flags and enforce usage in CheckArgFlags by ryanofsky)
  • #16545 (refactor: Implement missing error checking for ArgsManager flags by ryanofsky)

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.

LLM Linter (✨ experimental)

Possible typos and grammar issues:

  • /// Helper to initialize the global MockableSteadyClock, elapse it, and reset -> /// Helper to initialize the global MockableSteadyClock, advance it, and reset [“elapse” is intransitive; you cannot “elapse it”. Use “advance” or “advance the clock” for clarity.]
  • /// Helper to initialize the global NodeClock, elapse it, and reset -> /// Helper to initialize the global NodeClock, advance it, and reset [same issue: “elapse” is intransitive; “advance” is grammatically correct here.]

2026-01-16

@DrahtBot
Copy link
Contributor

DrahtBot commented May 6, 2025

🚧 At least one of the CI tasks failed.
Task lint: https://github.com/bitcoin/bitcoin/runs/41759458930
LLM reason (✨ experimental): (empty)

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being
    incompatible with the current code in the target branch). If so, make sure to rebase on the latest
    commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

Leave a comment here, if you need help tracking down a confusing failure.

@maflcko maflcko force-pushed the 2505-elapse-time branch 5 times, most recently from fa123d4 to fae29c5 Compare May 7, 2025 09:27
Copy link
Contributor

@l0rinc l0rinc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK - was thinking of something similar when reviewing 41479ed (#32414)

@maflcko
Copy link
Member Author

maflcko commented May 7, 2025

Sorry for the force-pushes, but this uncovered pre-existing issues in the fuzz tests that were not using mocktime during init. So I went ahead and fixed those as well in a separate commit. Should be good now, hopefully 😅

Copy link
Contributor

@w0xlt w0xlt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK fae29c5

@DrahtBot
Copy link
Contributor

DrahtBot commented Jul 8, 2025

🚧 At least one of the CI tasks failed.
Task previous releases, depends DEBUG: https://github.com/bitcoin/bitcoin/runs/45588216821
LLM reason (✨ experimental): The CI failure is caused by a compilation error in src/util/time.cpp due to incorrect usage of std::chrono::duration, which prevents building.

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being
    incompatible with the current code in the target branch). If so, make sure to rebase on the latest
    commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

Leave a comment here, if you need help tracking down a confusing failure.

@maflcko
Copy link
Member Author

maflcko commented Jul 9, 2025

Sorry for the force-pushes, but this uncovered pre-existing issues in the fuzz tests that were not using mocktime during init. So I went ahead and fixed those as well in a separate commit. Should be good now, hopefully 😅

Went ahead and cherry-picked out the fuzz-fixes into #32927. Should be easy to (re-)review that one.

@maflcko maflcko requested a review from w0xlt July 18, 2025 12:43
@maflcko maflcko force-pushed the 2505-elapse-time branch 2 times, most recently from fa55137 to fafcff1 Compare July 24, 2025 14:19
@maflcko maflcko force-pushed the 2505-elapse-time branch from fafcff1 to faaaaac Compare July 25, 2025 11:09
Copy link
Contributor

@l0rinc l0rinc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing these, left quite a few comments, hope you'll find them useful

@maflcko
Copy link
Member Author

maflcko commented Jul 31, 2025

Force pushed with some minor doc-changes and small refactoring in src/test/util/time.h

Copy link
Contributor

@l0rinc l0rinc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code review ACK fa80e75

MarcoFalke added 6 commits January 16, 2026 11:00
This is less code and also required for the next commit.
This is a bit more type-safe than a raw i64.
This makes it easier to use mock-time in tests. Also, it resets the
global mocktime, so that no state is leaked between test cases.

Also, it resets the global steady mock-time for the same reason.
This is required in the next commit.
@maflcko
Copy link
Member Author

maflcko commented Jan 16, 2026

rebased. should be trivial to re-review via git range-diff bitcoin-core/master fa80e750e7 fa053c2e32. The only changes were (1) dropping hunks of deleted code, (2) two in-line conflicts, (3) some adjacent lines modified in unrelated changes.

Copy link
Contributor

@l0rinc l0rinc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

diff reACK fa053c2

mini_miner_selection and LimitOrphans fuzz targets were removed during rebase and the refactored chainstate_write_interval refactoring was adjusted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants