refactor: introduce CChainState::GetCoinsCacheSizeState #16945

pull jamesob wants to merge 2 commits into bitcoin:master from jamesob:2019-09-au-shouldflush changing 5 files +230 −8
  1. jamesob commented at 7:33 pm on September 23, 2019: member

    This is part of the assumeutxo project:

    Parent PR: #15606 Issue: #15605 Specification: https://github.com/jamesob/assumeutxo-docs/tree/master/proposal


    This pulls out the routine for detection of how full the coins cache is from FlushStateToDisk. We use this logic independently when deciding when to flush the coins cache during UTXO snapshot activation (see here).

  2. jamesob renamed this:
    refactoring: introduce CChainState::GetCoinsCacheSizeState
    refactor: introduce CChainState::GetCoinsCacheSizeState
    on Sep 23, 2019
  3. DrahtBot commented at 8:01 pm on September 23, 2019: member

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

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #17737 (Add ChainstateManager, remove BlockManager global by jamesob)
    • #15606 ([experimental] UTXO snapshots by jamesob)

    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 Refactoring on Sep 23, 2019
  5. DrahtBot added the label Validation on Sep 23, 2019
  6. in src/validation.cpp:2211 in e3ac4ebeeb outdated
    2205@@ -2206,13 +2206,30 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl
    2206     return true;
    2207 }
    2208 
    2209+CoinsCacheSizeState CChainState::GetCoinsCacheSizeState()
    2210+{
    2211+    static int64_t nMempoolSizeMax = gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000;
    


    ryanofsky commented at 3:04 pm on September 24, 2019:
    Maybe avoid introducing static here since there was no static previously, and in general this isn’t a pattern we use with other GetArg calls, and and it makes this code harder to test with different sizes, or allow updating the size without restarting.

    jamesob commented at 3:45 pm on September 24, 2019:
    Good points, will fix. Can’t remember why I added that.
  7. ryanofsky approved
  8. ryanofsky commented at 3:07 pm on September 24, 2019: member
    utACK e3ac4ebeeb64b9fc9752384177474a53d8bf75c3. Verified refactoring seems equivalent to current code
  9. in src/validation.cpp:2212 in e3ac4ebeeb outdated
    2205@@ -2206,13 +2206,30 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl
    2206     return true;
    2207 }
    2208 
    2209+CoinsCacheSizeState CChainState::GetCoinsCacheSizeState()
    2210+{
    2211+    static int64_t nMempoolSizeMax = gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000;
    2212+    int64_t nMempoolUsage = mempool.DynamicMemoryUsage();
    


    MarcoFalke commented at 3:24 pm on September 24, 2019:
    Would it make sense to pass in the mempool as a tx_pool argument instead of using the global in this function?

    jamesob commented at 3:45 pm on September 24, 2019:
    Yep, good idea.
  10. jamesob commented at 3:46 pm on September 24, 2019: member
    I’ll see about writing some tests as well.
  11. jamesob force-pushed on Sep 24, 2019
  12. jamesob force-pushed on Sep 24, 2019
  13. jamesob commented at 6:16 pm on September 24, 2019: member
    Thanks for the looks so far @ryanofsky @MarcoFalke. I’ve taken all proposed advice, as well as going further to parameterize the maximum coins cache and mempool target sizes. I’ve also added a unittest exercising this.
  14. in src/test/validation_flush_tests.cpp:55 in 3c66fb4e58 outdated
    50+    BOOST_CHECK_EQUAL(
    51+        chainstate.GetCoinsCacheSizeState(tx_pool, MAX_COINS_CACHE_BYTES, /*max_mempool_size_bytes*/ 0),
    52+        CoinsCacheSizeState::OK);
    53+
    54+    print_view_mem_usage(view);
    55+    BOOST_CHECK_EQUAL(view.DynamicMemoryUsage(), 32);
    


    MarcoFalke commented at 7:18 pm on September 24, 2019:

    Looks like this fails:

     0Running tests: validation_flush_tests from test/validation_flush_tests.cpp
     1
     2Running 1 test case...
     3
     4Test cases order is shuffled using seed: 1589090245
     5
     6Entering test module "Bitcoin Core Test Suite"
     7
     8test/validation_flush_tests.cpp(12): Entering test suite "validation_flush_tests"
     9
    10test/validation_flush_tests.cpp(19): Entering test case "getcoinscachesizestate"
    11
    12CCoinsViewCache memory usage: 16
    13
    14test/validation_flush_tests.cpp(55): error: in "validation_flush_tests/getcoinscachesizestate": check view.DynamicMemoryUsage() == 32 has failed [16 != 32]
    

    jamesob commented at 7:31 pm on September 24, 2019:
    Ah right, forgot to account for 32 bit platforms.
  15. jamesob force-pushed on Sep 24, 2019
  16. jamesob force-pushed on Sep 25, 2019
  17. in src/test/validation_flush_tests.cpp:119 in 4708fcbf99 outdated
    101+    COutPoint res = add_coin(view);
    102+    print_view_mem_usage(view);
    103+
    104+    BOOST_CHECK_EQUAL(
    105+        chainstate.GetCoinsCacheSizeState(tx_pool, MAX_COINS_CACHE_BYTES, /*max_mempool_size_bytes*/ 0),
    106+        CoinsCacheSizeState::CRITICAL);
    


    MarcoFalke commented at 5:06 pm on September 25, 2019:
    0test/validation_flush_tests.cpp(106): error: in "validation_flush_tests/getcoinscachesizestate": check chainstate.GetCoinsCacheSizeState(tx_pool, MAX_COINS_CACHE_BYTES, 0) == CoinsCacheSizeState::CRITICAL has failed [1 != 2]
    

    https://travis-ci.org/bitcoin/bitcoin/jobs/589530820#L2957

  18. jamesob force-pushed on Sep 25, 2019
  19. jamesob force-pushed on Sep 25, 2019
  20. jamesob force-pushed on Sep 25, 2019
  21. jamesob commented at 7:39 pm on September 25, 2019: member
    Okay, after some fiddling the unittests are passing.
  22. in src/test/validation_flush_tests.cpp:62 in d780c6a3ef outdated
    54+    // Without any coins in the cache, we shouldn't need to flush.
    55+    BOOST_CHECK_EQUAL(
    56+        chainstate.GetCoinsCacheSizeState(tx_pool, MAX_COINS_CACHE_BYTES, /*max_mempool_size_bytes*/ 0),
    57+        CoinsCacheSizeState::OK);
    58+
    59+    // If the initial memory allocations of cacheCoins don't match these common
    


    ryanofsky commented at 5:25 pm on September 30, 2019:
    It’s not clear from the comment when this is expected to happen, like whether it happens on a certain type of plaform. Also it’s not clear how if DynamicMemoryUsage() is just using sizeof internally, the test couldn’t take this into account using the same sizeof expressions. Would at least extend comment to explain the issue.

    jamesob commented at 6:52 am on October 17, 2019:
    I wanted to avoid duplicating the DynamicMemoryUsage() calculations explicitly because they’re not totally trivial and it seemed like something that’d be bad to copy/paste. To be honest I don’t understand why some 64-bit Travis platforms didn’t slot into these initial allocations and so I can’t think of what else to say here.
  23. in src/test/validation_flush_tests.cpp:66 in d780c6a3ef outdated
    58+
    59+    // If the initial memory allocations of cacheCoins don't match these common
    60+    // cases, we can't really continue to make assertions about memory usage.
    61+    // End the test early.
    62+    if (view.DynamicMemoryUsage() != 32 && view.DynamicMemoryUsage() != 16) {
    63+        // Add a bunch of coins to see that we at least flip over to CRITICAL.
    


    ryanofsky commented at 5:28 pm on September 30, 2019:
    It might be clearer to move these fallback checks into a basic test and have the checks below be an extended test, running the basic test on all platforms and the extended test only on supported platforms. This would make the basic test more robust and easier to debug since it would run everywhere, and improve the extended test by making it shorter.

    jamesob commented at 6:45 am on October 17, 2019:
    I tried breaking the extended tests out but the two end up sharing so much data that it’s a pain to pass it all into the extended function. If you really think this is worthwhile I can think harder about how to break it up cleanly but in the meantime I don’t think it’s too egregious to leave as-is.

    Sjors commented at 1:14 pm on November 27, 2019:

    It should probably report when these tests are skipped, which seems to be the case on native 32 bit machines.

    Why not inspect the value of view.DynamicMemoryUsage() to infer how many coins you need to add to reach CRITICAL? Alternatively, why not just keep adding coins until you do reach CRITICAL (with some upper bound to prevent an infinite loop if there’s a serious bug)?


    jamesob commented at 5:23 pm on December 5, 2019:

    It should probably report when these tests are skipped

    What are you thinking, BOOST_TEST_MESSAGE?

    Why not inspect the value of view.DynamicMemoryUsage() to infer how many coins you need to add to reach CRITICAL?

    I don’t think it’s that simple - different platforms/std::unordered_map implementations allocate differently, and so the current memory usage doesn’t tell us enough about how memory usage will change as individual coins are added.

    Alternatively, why not just keep adding coins until you do reach CRITICAL (with some upper bound to prevent an infinite loop if there’s a serious bug)?

    That’s basically what I do below: https://github.com/bitcoin/bitcoin/pull/16945/files#diff-1c02ab3ed49056a4df577f3db9b53d30R64-R71

  24. in src/validation.cpp:2214 in d780c6a3ef outdated
    2205@@ -2206,13 +2206,42 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl
    2206     return true;
    2207 }
    2208 
    2209+CoinsCacheSizeState CChainState::GetCoinsCacheSizeState(
    2210+    const CTxMemPool& tx_pool,
    2211+    size_t max_coins_cache_size_bytes,
    2212+    int64_t max_mempool_size_bytes)
    2213+{
    2214+    if (max_coins_cache_size_bytes == -1) {
    


    ryanofsky commented at 5:42 pm on September 30, 2019:

    These magic -1 values do not seem like the best thing. They aren’t explicitly documented, assign a negative number to an unsigned type, add a runtime condition for something that is known at compile time, and cause the function to be linked against global variables that it doesn’t always need.

    Would suggest using an overload instead of default values:

    0CoinsCacheSizeState GetCoinsCacheSizeState(const CTxMemPool& tx_pool, size_t max_coins_cache_size_bytes, int64_t max_mempool_size_bytes);
    1CoinsCacheSizeState GetCoinsCacheSizeState(const CTxMemPool& tx_pool) {
    2    return GetCoinsCacheSizeState(tx_pool, ::nCoinCacheUsage, gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000);
    3}
    

    jamesob commented at 6:45 am on October 17, 2019:
    Good points, will fix.
  25. ryanofsky approved
  26. ryanofsky commented at 5:48 pm on September 30, 2019: member
    utACK d780c6a3ef07715330edec21fcf2882db75d9166. Changes since last review: adding test, getting rid of cached static size limit value. I left some suggestions, but think this is fine in it’s current form.
  27. jamesob force-pushed on Oct 17, 2019
  28. ryanofsky approved
  29. ryanofsky commented at 8:08 pm on October 21, 2019: member
    Code review ACK 028778a75f03a866b557a463bcee810a454e5404. Changes since last review were getting rid of special -1 defaults values, tweaking the 64-bit test check.
  30. in src/validation.h:736 in b1f69a3126 outdated
    728@@ -720,6 +729,17 @@ class CChainState {
    729     /** Update the chain tip based on database information, i.e. CoinsTip()'s best block. */
    730     bool LoadChainTip(const CChainParams& chainparams) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
    731 
    732+    //! Dictates whether we need to flush the cache to disk or not.
    733+    //!
    734+    //! @return the state of the size of the coins cache.
    735+    CoinsCacheSizeState GetCoinsCacheSizeState(const CTxMemPool& tx_pool)
    


    ariard commented at 8:18 pm on October 30, 2019:

    Even if mempool is passed as a const reference can’t we go further and pass only mempool memory usage ?

    Also if wrapper is for test-only or convenience for its further usage inside PopulateAndValidateSnapshot add reason in function comment

  31. in src/validation.cpp:2208 in b1f69a3126 outdated
    2224+    int64_t nTotalSpace =
    2225+        max_coins_cache_size_bytes + std::max<int64_t>(max_mempool_size_bytes - nMempoolUsage, 0);
    2226+
    2227+    //! No need to periodic flush if at least this much space still available.
    2228+    static constexpr int64_t MAX_BLOCK_COINSDB_USAGE_BYTES = 10 * 1024 * 1024;  // 10MB
    2229+    int64_t large_threshold =
    


    ariard commented at 8:21 pm on October 30, 2019:
    nit: nLargeThreshold (naming conv shouldn’t be same with nTotalSpace?)

    jamesob commented at 8:34 pm on November 5, 2019:
    Snake case is preferred in new code per the styleguide (https://github.com/bitcoin/bitcoin/blob/master/doc/developer-notes.md#coding-style-c) – I don’t think naming new variables to match the naming convention of old ones is something we’ve asked for previously.

    ariard commented at 4:45 pm on November 7, 2019:
    Ah thanks and so snaking case nTotalSpace?

    Sjors commented at 3:14 pm on November 19, 2019:
    total_space, cache_size and mempool_usage would make sense.
  32. in src/validation.h:741 in b1f69a3126 outdated
    736+        EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
    737+
    738+    CoinsCacheSizeState GetCoinsCacheSizeState(
    739+        const CTxMemPool& tx_pool,
    740+        size_t max_coins_cache_size_bytes,
    741+        int64_t max_mempool_size_bytes) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
    


    ariard commented at 9:06 pm on October 30, 2019:
    Could we use size_t instead of int64_t? DynamicUsage is already returning a size_t?

    jamesob commented at 8:34 pm on November 5, 2019:
    done
  33. in src/test/validation_flush_tests.cpp:140 in 028778a75f outdated
    130+    // but not yet critical.
    131+    add_coin(view);
    132+    print_view_mem_usage(view);
    133+
    134+    // Only perform these checks on 64 bit hosts; I haven't done the math for 32.
    135+    if (is_64_bit) {
    


    ariard commented at 10:19 pm on October 30, 2019:

    Hmmm I spent some time trying to do the math for 32 but without a 32-bit platform it’s quite hard so I’ve tried to observe some allocation patterns thanks to print_view_mem_usage on 64-bit, but given there are allocation threshold effects on how std::unordered_map is behaving (common practices for allocators to multiply some magic numbers by 2 after being full) we can’t do hard assumptions…

    Anyway I think this test is really dependent on how the standard library is implemented to get the right max_coins_cache_bytes/max_mempool_size_bytes.

    Have you tried to run this part of the test as it is on 32-bit platform ?


    mzumsande commented at 0:05 am on October 31, 2019:
    Just noting that the test fails on ARM (travis-log) because CoinsCacheSizeState::LARGE is not hit.

    jamesob commented at 7:07 pm on November 5, 2019:
    Yeah I’m beginning to think that this test is a fool’s errand. I might early-exit if the first map expansion doesn’t match some pattern, but in general everything feels a little flaky here.
  34. in src/test/validation_flush_tests.cpp:123 in 028778a75f outdated
    113+        chainstate.GetCoinsCacheSizeState(tx_pool, MAX_COINS_CACHE_BYTES, /*max_mempool_size_bytes*/ 0),
    114+        CoinsCacheSizeState::CRITICAL);
    115+
    116+    // Passing non-zero max mempool usage should allow us more headroom.
    117+    BOOST_CHECK_EQUAL(
    118+        chainstate.GetCoinsCacheSizeState(tx_pool, MAX_COINS_CACHE_BYTES, /*max_mempool_size_bytes*/ 1 << 10),
    


    ariard commented at 10:22 pm on October 30, 2019:
    nit: could use MAX_MEMPOOL_SIZE_BYTES = 1024, I like bitwise but maybe not everyone :p

    jamesob commented at 7:10 pm on November 6, 2019:
    I think this is fine as-is for tests.
  35. ariard approved
  36. ariard commented at 10:23 pm on October 30, 2019: member

    Code review ACK 028778a, tested validation_flush_tests on a 64-bit Linux platform.

    Not sure about robustness of new test on all platforms…

  37. jamesob force-pushed on Nov 5, 2019
  38. jamesob commented at 6:31 pm on November 6, 2019: member
    I’ve revised the new unittest so that it passes on Travis. I don’t really follow the AppVeyor failure, so would appreciate any hints there.
  39. ryanofsky commented at 6:37 pm on November 6, 2019: member

    I’ve revised the new unittest so that it passes on Travis. I don’t really follow the AppVeyor failure, so would appreciate any hints there.

    Appveyor failure is a known issue and should be fixed by #17384 (comment)

  40. ryanofsky approved
  41. ryanofsky commented at 7:07 pm on November 6, 2019: member
    Code review ACK 513981fe733564eddfb13de59a0e59a5c10736f9. Changes since last review: replacing int64_t with size_t argument (not actually sure why, since it’s called with an int64_t in the commit and only ever passed to std::max<int64_t>). Also: tweaking the !is_64_bit test case to make it pass on travis. I lost track of the size calculations in the test a while ago, but they seem reasonable, and we can always scale back the test later if they turn out to be not stable.
  42. jamesob commented at 7:11 pm on November 6, 2019: member

    Thanks for the review, Russ.

    replacing int64_t with size_t argument

    I did this to appease @ariard without thinking too hard about it but you’re right, I think it doesn’t make too much sense. Can revert if preferable.

  43. ariard commented at 5:04 pm on November 7, 2019: member

    Code review ACK 513981f.

    Changes since last review: replacing int64_t with size_t argument (not actually sure why, since it’s called with an int64_t in the commit and only ever passed to std::max<int64_t>).

    I think more variable types need to be updated in GetCoinsCacheSizeState to be size_t to make sense. IIRC, it’s better to use size_t as it let more flexibility to the compiler to optimize for the platform addresses size.

  44. fanquake added this to the "To do" column in a project

  45. laanwj added this to the "Blockers" column in a project

  46. ryanofsky commented at 7:53 pm on November 18, 2019: member
    Status of this PR? I guess it needs a little more review. Hopefully it shouldn’t take much. The code change is simple even though the test is complicated.
  47. jamesob commented at 8:31 pm on November 18, 2019: member
    Happy to make (or at least investigate) the size_t change if reviewers want, but also not eager to invalidate ACKs.
  48. ryanofsky commented at 9:02 pm on November 18, 2019: member

    Happy to make (or at least investigate) the size_t change if reviewers want, but also not eager to invalidate ACKs.

    I’m not at all concerned about the size_t thing, so feel to just push for merge or more review

  49. in src/validation.cpp:2207 in 73e6503a6c outdated
    2223+    int64_t cacheSize = CoinsTip().DynamicMemoryUsage();
    2224+    int64_t nTotalSpace =
    2225+        max_coins_cache_size_bytes + std::max<int64_t>(max_mempool_size_bytes - nMempoolUsage, 0);
    2226+
    2227+    //! No need to periodic flush if at least this much space still available.
    2228+    static constexpr int64_t MAX_BLOCK_COINSDB_USAGE_BYTES = 10 * 1024 * 1024;  // 10MB
    


    Sjors commented at 3:15 pm on November 19, 2019:
    This is an odd place for a constant.
  50. Sjors commented at 3:19 pm on November 19, 2019: member
    Code review ACK for the refactor 73e6503a6c96f2909a766ca464e96826b560e600; I did not review the test commit. Nits are probably not worth losing acks.
  51. ariard commented at 4:43 pm on November 19, 2019: member

    Happy to make (or at least investigate) the size_t change if reviewers want, but also not eager to invalidate ACKs.

    Don’t bother for the size_t, not worth invalidating ACKs.

  52. ryanofsky commented at 2:34 pm on November 21, 2019: member
    Is this ready to be merged? It’s a simple change that’s had reviews it looks like from 5 people, including 3 reviews of the latest 513981f (Sjors ACK is for the latest code but has a different hash because he skipped the test-only commit).
  53. promag commented at 10:13 pm on November 24, 2019: member
    Concept ACK. @jamesob are you going to do something about https://github.com/bitcoin/bitcoin/pull/16945/files#r342743813?
  54. jamesob commented at 4:54 pm on November 26, 2019: member
    @promag the tests have been fixed to be stable on CI (see the changes). I agree with @ryanofsky that this seems ready for merge, but if anyone else has any feedback they feel is blocking the PR, I’m happy to address.
  55. in src/test/validation_flush_tests.cpp:49 in 513981fe73 outdated
    40+        coins_view.AddCoin(outp, std::move(newcoin), false);
    41+
    42+        return outp;
    43+    };
    44+
    45+    constexpr int COIN_SIZE = is_64_bit ? 80 : 64;
    


    Sjors commented at 1:12 pm on November 27, 2019:
    Some explanation would be useful here.

    jamesob commented at 9:18 pm on December 17, 2019:
    Is that change good or would you prefer to see something else?
  56. Sjors commented at 1:28 pm on November 27, 2019: member
    Having these tests just for 64 bit platforms is a good start. Making them work on different platforms goes beyond the scope of whats being refactored here, so can be done later.
  57. in src/validation.h:536 in 73e6503a6c outdated
    528@@ -529,6 +529,15 @@ class CoinsViews {
    529     void InitCache() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
    530 };
    531 
    532+enum class CoinsCacheSizeState
    533+{
    534+    //! The coins cache is in immediate need of a flush.
    535+    CRITICAL = 2,
    


    promag commented at 0:49 am on December 9, 2019:
    Why you choose this order (2,1,0)?


    promag commented at 7:15 pm on January 9, 2020:
    Ok.
  58. promag commented at 0:52 am on December 9, 2019: member
    Code review ACK, could as well address @Sjors comments.
  59. jamesob force-pushed on Dec 11, 2019
  60. jamesob commented at 8:40 pm on December 11, 2019: member

    I’ve pushed changes addressing @Sjors’ feedback.

    So far the ACK tally for the previous HEAD (and current HEAD, less comment changes) is @promag - code review ACK @Sjors - code review ACK @ryanofsky - code review ACK @ariard - code review ACK

  61. Sjors commented at 9:00 am on December 12, 2019: member
    Travis bloodbath :-(
  62. refactoring: introduce CChainState::GetCoinsCacheSizeState
    This separates out some logic for detecting how full the coins cache is from
    FlushStateToDisk. We'll want to reuse this logic when deciding when to flush
    the coins cache during UTXO snapshot activation.
    b17e91d842
  63. jamesob force-pushed on Dec 12, 2019
  64. jamesob commented at 4:30 pm on December 12, 2019: member

    Travis bloodbath :-(

    Rebased to avoid carnage by fixing a silent merge conflict.

  65. tests: add tests for GetCoinsCacheSizeState 02b9511d6b
  66. jamesob force-pushed on Dec 12, 2019
  67. ryanofsky approved
  68. ryanofsky commented at 7:09 pm on December 16, 2019: member
    Code review ACK 02b9511d6bace5711e454d2b685b2fee0d65e341. Just rebase, new COIN_SIZE comment, and new test message since last review
  69. ryanofsky commented at 4:59 pm on December 17, 2019: member

    Saw this in IRC:

    it’s discouraging to think that #16945 probably just would’ve sailed through review if I hadn’t bothered to add a unittest

    I understand the sentiment, but I also do think the unit test is hard to understand, and I would not like to have to debug it in the future. I’m comfortable acking it now with the hope that maybe it is the type of thing that’s a little complicated to put in place, but once there will be reliable and useful. But if it started breaking in the future and the fix wasn’t obvious I could see wanting to drop it instead of update it.

    The basic problem is that is that instead of being a test of the just GetCoinsCacheSizeState function, it is a test of that function plus all the DynamicMemoryUsage functions which are very platform specific. I think a more ideal unit test would either mock or wrap the the DynamicMemoryUsage functions to be independent of the implementations of those functions.

  70. jamesob commented at 9:16 pm on December 17, 2019: member

    The basic problem is that is that instead of being a test of the just GetCoinsCacheSizeState function, it is a test of that function plus all the DynamicMemoryUsage functions which are very platform specific. I think a more ideal unit test would either mock or wrap the the DynamicMemoryUsage functions to be independent of the implementations of those functions.

    Personally I think it’s more desirable to have wider/incidental coverage (at the expense of lower specificity in terms of what failed) because the coins cache is a critically important part of the system. We should be alerted if e.g. the size of the coins cache entries changes, since that has pretty drastic effects on performance. Our unittest coverage is paltry as it stands, and when that’s the case I tend more towards adding integration- rather than strict unit-tests to get as much coverage out of what few tests we do have.

    I’d much prefer to be hyper-aware of what’s going on with the coins cache and have to update a few tests once in a while than risk being unaware of even a small change to such an important part of the system. If there are ways I can make the test clearer or better, I’m all ears, but I am very hesitant to look to mocks - not only because that will probably require substantive changes to code purely for the sake of testing, but because for a system like Bitcoin it seems preferable have overzealous test coverage than the illusion of it thanks to a constellation of mocks.

    There is an argument to be made that a test about when to flush the cache isn’t an appropriate place to make assertions about the size of its contents, but it was convenient and this stuff wasn’t tested so I figured better have it somewhere than not at all.

  71. fanquake moved this from the "To do" to the "In progress" column in a project

  72. ryanofsky commented at 9:57 pm on January 8, 2020: member
    It seems like this has had enough review, but some of the previous reviews are out of date. @promag, @Sjors, @ariard maybe you could reack?
  73. ariard commented at 4:54 pm on January 9, 2020: member

    Code review ACK 02b9511.

    Changes since 513981f, documenting better new test and printing an exit message in case of exotic archs.

  74. laanwj referenced this in commit 2ed74a43a0 on Jan 13, 2020
  75. laanwj removed this from the "Blockers" column in a project

  76. laanwj merged this on Jan 13, 2020
  77. laanwj closed this on Jan 13, 2020

  78. fanquake moved this from the "In progress" to the "Done" column in a project

  79. sidhujag referenced this in commit ab2fb60cfa on Jan 14, 2020
  80. sidhujag referenced this in commit 8e75779f0e on Nov 10, 2020
  81. Fabcien referenced this in commit 7680ec0096 on Jan 18, 2021
  82. kittywhiskers referenced this in commit e49fbf5351 on Oct 10, 2021
  83. kittywhiskers referenced this in commit d035cd7d47 on Oct 10, 2021
  84. kittywhiskers referenced this in commit fa1762b156 on Oct 16, 2021
  85. kittywhiskers referenced this in commit fc54e2a53c on Oct 16, 2021
  86. kittywhiskers referenced this in commit 0f909118c6 on Oct 16, 2021
  87. kittywhiskers referenced this in commit 2015b5cada on Oct 21, 2021
  88. kittywhiskers referenced this in commit f9c4b85575 on Oct 22, 2021
  89. pravblockc referenced this in commit c4e0adfc10 on Nov 18, 2021
  90. DrahtBot locked this on Feb 15, 2022

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: 2024-07-03 10:13 UTC

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