test: 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 −134
  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. A summary of reviews will appear here.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #32279 ([IBD] prevector: store P2WSH/P2TR/P2PK scripts inline by l0rinc)
    • #30214 (refactor: Improve assumeutxo state representation by ryanofsky)
    • #28531 (improve MallocUsage() accuracy by LarryRuane)

    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.

  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. 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)
    f20dbadc44
  8. 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
    3d7bc70b82
  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. OrangeDoro commented at 10:36 am on July 20, 2025: none

    Hi! I’m a grad student working on a research project about using large language models to automate code review. Based on your commit 966bbabbd69039a2c7a03429c783f7d6e6a7c2a7 and the changes in src/test/validation_flush_tests.cpp, my tool generated this comment:

    1. Dynamic Memory Usage Check: Ensure that the expected behavior of DynamicMemoryUsage() aligns with the assumptions made in this test.
    2. Dynamic Memory Usage Checks: The checks for view.DynamicMemoryUsage() are essential to ensure that memory usage does not exceed expected limits. Consider adding assertions or logging to capture any unexpected memory usage patterns during the tests.
    3. Error Handling: The patch does not include error handling for the view.Flush() operation. Ensure that there are checks after critical operations to handle potential failures gracefully.
    4. Testing Edge Cases: Ensure that edge cases (e.g., maximum memory limits, zero memory limits) are thoroughly tested to identify any potential vulnerabilities related to memory allocation and usage.
    5. Loop Iteration Limits: Ensure that the logic inside the loops does not inadvertently lead to a situation where the expected state is never reached.
    6. Memory Management: The patch does not introduce any explicit memory management issues such as memory leaks or data overflows. However, ensure that the AddTestCoin function properly manages memory to avoid unbounded memory growth, especially since it is called in loops.
    7. Use of constexpr with 8_MiB: Ensure that 8_MiB is defined correctly as a compile-time constant. If it is not defined, this will lead to a syntax error. Consider replacing it with a numeric literal, e.g., constexpr size_t MAX_COINS_BYTES{8 * 1024 * 1024};.
    8. Loop Iteration Count: Implement a break condition or a more efficient way to determine when to stop adding coins in the loop that adds coins.
    9. Dynamic Memory Usage Calculation: Store the result of view.DynamicMemoryUsage() in a variable to avoid redundant calculations.
    10. Commented Code: Ensure BOOST_TEST_MESSAGE calls marked with // TODO remove are removed or replaced with proper logging before finalizing the code.
    11. Comment Clarity: Expand comments like // PoolResource defaults to 256 KiB that will be allocated, so we'll take that and make it a bit larger. to explain why this is necessary.
    12. Commenting Style: Remove // TODO remove comments before finalizing the code to maintain a clean codebase.
    13. Magic Numbers: Replace magic numbers (e.g., 256, 1024, 3, 4, 1000) with named constants to improve readability and maintainability.
    14. Consistency in Naming Conventions: The identifier MAX_COINS_CACHE_BYTES is replaced with MAX_COINS_BYTES. If MAX_COINS_CACHE_BYTES was the established naming convention, it would be better to retain it for clarity and consistency.
    15. Use of Underscores vs. Camel Case: The identifiers MAX_COINS_BYTES, MAX_MEMPOOL_BYTES, and MAX_ATTEMPTS use an uppercase naming style with underscores, which is appropriate for constants. The identifier full_cap should be renamed to FULL_CAP for consistency.
    16. Parameter Naming: The parameter max_mempool_size_bytes could be shortened to max_mempool_bytes for better readability.
    17. Loop Variable Naming: Consider using a more descriptive name for the loop variable i, such as attempt or index, especially in the context of for (size_t i{0}; i < MAX_ATTEMPTS && int64_t(view.DynamicMemoryUsage()) < large_cap; ++i).
    18. Use of BOOST_TEST_MESSAGE: Reduce the frequency of BOOST_TEST_MESSAGE logging or use a more efficient logging mechanism that can be toggled based on a debug flag.
    19. Avoiding Redundant State Checks: Optimize state checks within loops by checking the state only after significant changes in memory usage or after a certain number of coins have been added.
    20. Code Performance Suggestions: Consider making MAX_COINS_BYTES and MAX_MEMPOOL_BYTES configurable or dynamically calculated based on the system’s available memory.
    21. Other Suggestions: (No specific suggestion provided)

    As part of my research, I’m trying to understand how useful these comments are in real-world development. If you have a moment, I’d be super grateful if you could quickly reply to these two yes/no questions:

    1. Does this comment provide suggestions from a dimension you hadn’t considered?

    2. Do you find this comment helpful?

    Thanks a lot for your time and feedback! And sorry again if this message is a bother.

  13. l0rinc force-pushed on Jul 20, 2025
  14. 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>
    b2d82668a5
  15. l0rinc force-pushed on Jul 20, 2025
  16. l0rinc marked this as ready for review on Jul 20, 2025
  17. DrahtBot removed the label CI failed on Jul 20, 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-07-23 00:13 UTC

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