Simplify return values of GetCoin/HaveCoin(InCache) #10581

pull sipa wants to merge 1 commits into bitcoin:master from sipa:simplehavecoin changing 5 files +28 −19
  1. sipa commented at 7:21 pm on June 13, 2017: member

    Superset of #10559

    This removes the possibility for GetCoin/HaveCoin/HaveCoinInCache to return true while the respective coin is spent. By doing it across all calls, some extra checks can be eliminated.

    coins_tests is modified to call HaveCoin sometimes before and sometimes after AccessCoin. A further change is needed because the semantics for GetCoin slightly changed, causing a pruned entry in the parent cache to not be pulled into the child in FetchCoin.

  2. sipa force-pushed on Jun 13, 2017
  3. fanquake added the label UTXO Db and Indexes on Jun 14, 2017
  4. sipa commented at 5:23 pm on June 16, 2017: member
    @morcos @ryanofsky Feel like having a look at this?
  5. in src/test/coins_tests.cpp:151 in 6ba5394841 outdated
    146+            bool result_havecoin = test_havecoin ? stack.back()->HaveCoin(COutPoint(txid, 0)) : false;
    147             const Coin& entry = (InsecureRandRange(500) == 0) ? AccessByTxid(*stack.back(), txid) : stack.back()->AccessCoin(COutPoint(txid, 0));
    148             BOOST_CHECK(coin == entry);
    149+            if (test_havecoin) BOOST_CHECK(result_havecoin == !entry.IsSpent());
    150+
    151+            if (InsecureRandBits(4) == 0) {
    


    ryanofsky commented at 4:12 pm on June 22, 2017:
    What’s the point of the two InsecureRandBits calls skipping the new BOOST_CHECKs? It seems like the checks should always pass and aren’t very expensive. Is the point to avoid creating cache entries during the test? Maybe add a comment saying why this only randomly checks HaveCoin results.

    sipa commented at 10:23 pm on June 22, 2017:
    Added a comment, and shuffled the code a bit to make it clearer.
  6. ryanofsky commented at 4:19 pm on June 22, 2017: member
    utACK 6ba5394841172944082e0c7447f404d6609337f3. Nice change. I’d call it a superset of the change in #10559 though instead of an alternative.
  7. sipa force-pushed on Jun 22, 2017
  8. sipa commented at 1:33 am on June 23, 2017: member
    @ryanofsky Oh yes, indeed! Rebased on top of #10559.
  9. sipa force-pushed on Jun 23, 2017
  10. ryanofsky commented at 9:16 pm on June 23, 2017: member
    utACK 04087f7d83360482e031e9ecbcc97a29fb3b1b8a. Only new changes are test cleanup and rebase.
  11. in src/test/coins_tests.cpp:146 in 04087f7d83 outdated
    140@@ -147,8 +141,22 @@ BOOST_AUTO_TEST_CASE(coins_cache_simulation_test)
    141         {
    142             uint256 txid = txids[InsecureRandRange(txids.size())]; // txid we're going to modify in this iteration.
    143             Coin& coin = result[COutPoint(txid, 0)];
    144+
    145+            // Determine whether to test HaveCoin before or after Access* (or both). As these functions
    146+            // can influence eachother's behaviour by pulling things into the cache, all combinations
    


    paveljanik commented at 6:36 am on June 26, 2017:
    micro nit eachSPCother

    sipa commented at 11:16 pm on June 26, 2017:
    Fixed.
  12. paveljanik approved
  13. paveljanik commented at 7:06 am on June 26, 2017: contributor
    utACK 04087f7
  14. laanwj assigned laanwj on Jun 26, 2017
  15. sipa force-pushed on Jun 26, 2017
  16. sipa commented at 11:15 pm on June 26, 2017: member
    Rebased.
  17. Simplify return values of GetCoin/HaveCoin(InCache)
    This removes the possibility for GetCoin/HaveCoin/HaveCoinInCache to return
    true while the respective coin is spent. By doing it across all calls, some
    extra checks can be eliminated.
    
    coins_tests is modified to call HaveCoin sometimes before and sometimes
    after AccessCoin. A further change is needed because the semantics for
    GetCoin slightly changed, causing a pruned entry in the parent cache to not
    be pulled into the child in FetchCoin.
    21180ff734
  18. sipa force-pushed on Jun 26, 2017
  19. laanwj commented at 9:09 am on June 27, 2017: member
    utACK 21180ff, certainly makes the API better
  20. laanwj merged this on Jun 27, 2017
  21. laanwj closed this on Jun 27, 2017

  22. laanwj referenced this in commit 78783531b7 on Jun 27, 2017
  23. morcos commented at 5:57 pm on June 27, 2017: member
    posthumous utACK @sipa, I’d misinterpreted this #10559 (comment) to imply you wanted ViewMempool functions to include whether the mempool contains a spend. But now I think you didn’t want that and are happy with where we are now? If so, so am I.
  24. sipa commented at 6:01 pm on June 27, 2017: member
    @morcos Yes, the CCoinsViewMemPool view is internally consistent and follows all expectations of a CCoinsView. It just still contains outputs spent inside the mempool.
  25. TheBlueMatt commented at 7:59 pm on June 27, 2017: member
    Postumous utACK, there are a bunch of places that are only barely safe before this change, and this makes them much more clearly safe :+1: .
  26. codablock referenced this in commit 6e9c024fb6 on Sep 27, 2017
  27. codablock referenced this in commit 93eca4cfbe on Oct 12, 2017
  28. codablock referenced this in commit f1bacbf021 on Oct 26, 2017
  29. codablock referenced this in commit dc5f8d39cb on Oct 26, 2017
  30. codablock referenced this in commit 0c5defe188 on Oct 26, 2017
  31. codablock referenced this in commit be2c11a752 on Oct 30, 2017
  32. codablock referenced this in commit c367ff876e on Oct 31, 2017
  33. codablock referenced this in commit b006ec9a4b on Oct 31, 2017
  34. codablock referenced this in commit 549839a504 on Oct 31, 2017
  35. UdjinM6 referenced this in commit c4ab0995f9 on Nov 8, 2017
  36. schancel referenced this in commit bd9e256384 on Jul 18, 2019
  37. jonspock referenced this in commit 22a2ccca3c on Aug 29, 2019
  38. proteanx referenced this in commit f5276be6db on Sep 4, 2019
  39. MarcoFalke locked this on Sep 8, 2021

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-06-18 10:12 UTC

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