Don’t return stale data from CCoinsViewCache::Cursor() #10550

pull ryanofsky wants to merge 2 commits into bitcoin:master from ryanofsky:pr/coins-stale changing 6 files +18 −10
  1. ryanofsky commented at 5:23 pm on June 7, 2017: member

    CCoinsViewCache doesn’t actually support cursor iteration returning the current contents of the cache, so raise an error when the cursor method is called instead of returning a cursor that iterates over stale data.

    Also update the gettxoutsetinfo RPC which was relying on the old behavior to be explicit about which view it is returning data about.

  2. Don't return stale data from CCoinsViewCache::Cursor()
    CCoinsViewCache doesn't actually support cursor iteration returning the
    current contents of the cache, so raise an error when the cursor method is
    called instead of returning a cursor that iterates over stale data.
    
    Also update the gettxoutsetinfo RPC which was relying on the old behavior to be
    explicit about which view it is returning data about.
    24e44c354d
  3. in src/coins.h:216 in c754fd11df outdated
    211@@ -212,6 +212,9 @@ class CCoinsViewCache : public CCoinsViewBacked
    212     uint256 GetBestBlock() const;
    213     void SetBestBlock(const uint256 &hashBlock);
    214     bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock);
    215+    CCoinsViewCursor* Cursor() const override {
    216+        throw std::logic_error("CCCoinsViewCache cursor iteration not supported.");
    


    sipa commented at 5:40 pm on June 7, 2017:
    CCC?

    ryanofsky commented at 8:22 pm on June 7, 2017:
    Fixed in fe76b30c838a4de4afb8382c4f11948d91536d22
  4. ryanofsky commented at 8:22 pm on June 7, 2017: member
    Squashed fe76b30c838a4de4afb8382c4f11948d91536d22 -> c9d5b100209988ae2ffe3339c8b30dea28449ac1 (pr/coins-stale.2 -> pr/coins-stale.3)
  5. ryanofsky force-pushed on Jun 7, 2017
  6. jonasschnelli commented at 6:23 am on June 8, 2017: contributor
    utACK c9d5b100209988ae2ffe3339c8b30dea28449ac1
  7. in src/coins.h:215 in c9d5b10020 outdated
    211@@ -212,6 +212,9 @@ class CCoinsViewCache : public CCoinsViewBacked
    212     uint256 GetBestBlock() const;
    213     void SetBestBlock(const uint256 &hashBlock);
    214     bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock);
    215+    CCoinsViewCursor* Cursor() const override {
    


    laanwj commented at 7:20 am on June 8, 2017:

    This ‘override’ is causing tons of warnings here (for every file that includes coins.h).

    0/home/orion/projects/bitcoin/bitcoin/src/coins.h:210:10: warning: 'GetCoin' overrides a member function but is not marked 'override' [-Winconsistent-missing-override]
    1    bool GetCoin(const COutPoint &outpoint, Coin &coin) const;
    

    Some compilers (clang5, in this case) demand that a whole class is annotated with it if it is used anywhere. So I’d argue against adding it here, or in a separate commit add it to all appropriate CCoinsViewCache methods.


    ryanofsky commented at 11:47 am on June 8, 2017:
    Removed in c2a7640d2ac5e6b1c8a238cfffa2b6f86fc9e490.

    ryanofsky commented at 1:54 pm on June 8, 2017:
    Added back overrides in a51ff25b6ea93ecb3dccbd37ca3a11c9d8fc0693
  8. laanwj commented at 7:20 am on June 8, 2017: member
    This makes a lot of sense, the use of API here has always bothered me but I wasn’t sure how to fix it. Seems a good stopgap until we need #9306. ACK (+ verified that gettxoutsetinfo fields that depend on this iteration display the same with and without this patch) apart from nit.
  9. in src/validation.h:487 in c9d5b10020 outdated
    482@@ -482,6 +483,9 @@ bool ResetBlockFailureFlags(CBlockIndex *pindex);
    483 /** The currently-connected chain of blocks (protected by cs_main). */
    484 extern CChain chainActive;
    485 
    486+/** Global variable that points to the coins database (protected by cs_main) */
    487+extern CCoinsViewDB *pcoinsdbview;
    


    paveljanik commented at 10:06 am on June 8, 2017:
    Coins View DB vs coins db view?

    ryanofsky commented at 11:44 am on June 8, 2017:

    Coins View DB vs coins db view?

    Are you suggesting to rename the variable? If so I would slightly prefer not to, because this is a preexisting variable which this PR is just making public.


    paveljanik commented at 11:52 am on June 8, 2017:
    Agreed. Thanks for clarification.
  10. ryanofsky force-pushed on Jun 8, 2017
  11. ryanofsky commented at 11:49 am on June 8, 2017: member
    Squashed c2a7640d2ac5e6b1c8a238cfffa2b6f86fc9e490 -> 24e44c354d5b9174cb9cb7d157a985e197aa7886 (pr/coins-stale.4 -> pr/coins-stale.6)
  12. ryanofsky renamed this:
    Don't return stale data from CCCoinsViewCache::Cursor()
    Don't return stale data from CCoinsViewCache::Cursor()
    on Jun 8, 2017
  13. Use override keyword on CCoinsView overrides 3ff1fa8c4a
  14. ryanofsky force-pushed on Jun 8, 2017
  15. ryanofsky referenced this in commit c2a7640d2a on Jun 8, 2017
  16. ryanofsky force-pushed on Jun 8, 2017
  17. in src/coins.h:217 in a51ff25b6e outdated
    215+    uint256 GetBestBlock() const override;
    216     void SetBestBlock(const uint256 &hashBlock);
    217     bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock);
    218+    CCoinsViewCursor* Cursor() const override {
    219+        throw std::logic_error("CCoinsViewCache cursor iteration not supported.");
    220+    }
    


    laanwj commented at 6:36 pm on June 8, 2017:

    Thanks! Though I’m still getting one warning after this:

    0In file included from /home/.../bitcoin/src/rpc/rawtransaction.cpp:8:
    1/home/.../bitcoin/src/coins.h:214:10: warning: 'BatchWrite' overrides a member function but is not marked 'override' [-Winconsistent-missing-override]
    2    bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock);
    3         ^
    4/home/.../bitcoin/src/coins.h:186:10: note: overridden virtual function is here
    5    bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) override;
    

    ryanofsky commented at 9:13 pm on June 8, 2017:
    Fixed 36a14a9bceeafd7f1565c10579f698ec135d8bc6
  18. ryanofsky force-pushed on Jun 8, 2017
  19. ryanofsky commented at 9:14 pm on June 8, 2017: member
    Squashed 36a14a9bceeafd7f1565c10579f698ec135d8bc6 -> 3ff1fa8c4a6198ebc277bbf814b4e07bf78eb98a (pr/coins-stale.8 -> pr/coins-stale.9)
  20. laanwj merged this on Jun 12, 2017
  21. laanwj closed this on Jun 12, 2017

  22. laanwj referenced this in commit b7296bcea0 on Jun 12, 2017
  23. codablock referenced this in commit df0b23c8b3 on Sep 27, 2017
  24. codablock referenced this in commit 51a2df7a7f on Oct 12, 2017
  25. codablock referenced this in commit 0fa267d3a2 on Oct 26, 2017
  26. codablock referenced this in commit 4c8eb3b2a4 on Oct 26, 2017
  27. codablock referenced this in commit ad5df400ba on Oct 26, 2017
  28. codablock referenced this in commit 81ffa5bc86 on Oct 30, 2017
  29. codablock referenced this in commit fad9fa5ce4 on Oct 31, 2017
  30. codablock referenced this in commit 358b399c45 on Oct 31, 2017
  31. codablock referenced this in commit 4f807422fa on Oct 31, 2017
  32. UdjinM6 referenced this in commit 57b50ffb51 on Nov 8, 2017
  33. DrahtBot 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-10-06 19:12 UTC

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