test/refactor: revive test verifying that GetCoinsCacheSizeState switches from OK→LARGE→CRITICAL #33021

pull l0rinc wants to merge 3 commits into bitcoin:master from l0rinc:l0rinc/validation_flush_tests changing 3 files +49 −133
  1. l0rinc commented at 1:02 am on July 20, 2025: contributor

    After the changes in #25325 getcoinscachesizestate always ended the test early:

    File Line Rate Line Total Line Hit Branch Rate Branch Total Branch Hit
    validation_flush_tests.cpp 31.5 % 54 17 22.3 % 242 54

    The test revival was extracted from a related PR where it was discovered.

  2. DrahtBot added the label Tests on Jul 20, 2025
  3. DrahtBot commented at 1:02 am on July 20, 2025: contributor

    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/33021.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK LarryRuane, w0xlt, achow101

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

    Conflicts

    No conflicts as of last run.

  4. DrahtBot added the label CI failed on Jul 20, 2025
  5. DrahtBot commented at 2:03 am on July 20, 2025: contributor

    🚧 At least one of the CI tasks failed. Task previous releases, depends DEBUG: https://github.com/bitcoin/bitcoin/runs/46324900666 LLM reason (✨ experimental): The CI failure is caused by a compilation error due to an intentional narrowing conversion that is rejected as an error, breaking the build.

    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.

  6. l0rinc force-pushed on Jul 20, 2025
  7. l0rinc force-pushed on Jul 20, 2025
  8. l0rinc force-pushed on Jul 20, 2025
  9. l0rinc force-pushed on Jul 20, 2025
  10. l0rinc force-pushed on Jul 20, 2025
  11. l0rinc force-pushed on Jul 20, 2025
  12. l0rinc marked this as ready for review on Jul 20, 2025
  13. DrahtBot removed the label CI failed on Jul 20, 2025
  14. LarryRuane commented at 5:36 pm on July 25, 2025: contributor

    tACK b2d82668a57d4ab4eef310c25a2aebda18563677 I thoroughly reviewed and understand all code changes. This test perfectly tests GetCoinsCacheSizeState() and is much simpler and less fragile. (Also, I learned a few C++ tricks, very nice.)

    I ran the modified test using the debugger (on Ubuntu), and it behaves as designed. The only very minor suggestion if you need to retouch is to consider adding a comment explaining why it’s not necessary to verify that the loops didn’t exceed MAX_ATTEMPTS (I had to think about that for a bit; the answer is that if we exceed the attempts, the subsequent state check will fail).

    By the way, MAX_ATTEMPTS is defined well; the loop iterator never exceeds 35k.

  15. DrahtBot added the label Needs rebase on Jul 28, 2025
  16. refactor: extract `LargeCoinsCacheThreshold` from `GetCoinsCacheSizeState`
    Move-only commit, enabled reusing the large cache size calculation logic later. The only difference is the removal of the `static` keyword  (since in a constexpr function it's a C++23 extension)
    1b40dc02a6
  17. refactor: modernize `LargeCoinsCacheThreshold`
    * parameter name uses underscores
    * commit message typo fixed and compacted
    * used `10_MiB` to avoid having to comment
    * swapped order of operands in (9 * x / 10) to make it obvious that we're calculating 90%
    * inlined return value
    64ed0fa6b7
  18. test: revive `getcoinscachesizestate`
    After the changes in https://github.com/bitcoin/bitcoin/pull/25325 `getcoinscachesizestate` always end the test early, see:
    https://maflcko.github.io/b-c-cov/test_bitcoin.coverage/src/test/validation_flush_tests.cpp.gcov.html
    
    The test revival was extracted from a related PR where it was discovered, see: https://github.com/bitcoin/bitcoin/pull/28531#discussion_r2109417797
    
    Co-authored-by: Larry Ruane <larryruane@gmail.com>
    554befd873
  19. l0rinc force-pushed on Jul 28, 2025
  20. l0rinc commented at 8:18 pm on July 28, 2025: contributor
    Rebased, no other change needed, ready for review
  21. l0rinc requested review from LarryRuane on Jul 28, 2025
  22. DrahtBot removed the label Needs rebase on Jul 28, 2025
  23. LarryRuane commented at 3:48 pm on July 30, 2025: contributor
    ACK 554befd8738ea993b3b555e7366558a9c32c915c
  24. achow101 added this to the milestone 30.0 on Aug 7, 2025
  25. in src/validation.h:511 in 554befd873
    504@@ -503,6 +505,14 @@ enum class CoinsCacheSizeState
    505     OK = 0
    506 };
    507 
    508+constexpr int64_t LargeCoinsCacheThreshold(int64_t total_space) noexcept
    509+{
    510+    // No periodic flush needed if at least this much space is free
    511+    constexpr int64_t MAX_BLOCK_COINSDB_USAGE_BYTES{int64_t(10_MiB)};
    


    w0xlt commented at 6:41 pm on August 7, 2025:

    Brace initialization will convert size_t to int64_t

    0    constexpr int64_t MAX_BLOCK_COINSDB_USAGE_BYTES{10_MiB};
    

    l0rinc commented at 7:33 pm on August 7, 2025:
    I don’t think this works on every platform (e.g. 32 bits) - I probably had a version like this before
  26. w0xlt commented at 10:43 pm on August 7, 2025: contributor

    ACK https://github.com/bitcoin/bitcoin/pull/33021/commits/554befd8738ea993b3b555e7366558a9c32c915c

    • Most of the master branch src/test/validation_flush_tests.cpp also ends early in my setup.
    • This PR revives (and simplifies) that test, making it robust across all platforms.
    • The MAX_ATTEMPTS is good safeguard to keep CI from hanging due to initial map sizes (libc++/libstdc++/arch differences).
  27. l0rinc renamed this:
    test: revive test verifying that `GetCoinsCacheSizeState` switches from OK→LARGE→CRITICAL
    test/refactor: revive test verifying that `GetCoinsCacheSizeState` switches from OK→LARGE→CRITICAL
    on Aug 8, 2025
  28. achow101 commented at 9:46 pm on August 11, 2025: member
    ACK 554befd8738ea993b3b555e7366558a9c32c915c
  29. achow101 merged this on Aug 11, 2025
  30. achow101 closed this on Aug 11, 2025

  31. l0rinc deleted the branch on Aug 11, 2025

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2025-08-12 09:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me