Add cursor to iterate over utxo set, use this in `gettxoutsetinfo` #7756

pull laanwj wants to merge 1 commits into bitcoin:master from laanwj:2016_03_utxo_cursor changing 6 files +148 −57
  1. laanwj commented at 4:48 PM on March 28, 2016: member

    I need this for something else, but I think this is simply a better API. I also vaguely remember this has been discussed before.

    • Add a method Cursor() to CCoinsView that returns a cursor which can be used to iterate over the whole UTXO set.
    • Implement GetUTXOStats in terms of this, remove GetStats() method on CCoinsView.
    • Change gettxoutsetinfo RPC to use new GetUTXOStats function.

    This is not yet enough to break the dependency of txdb.cpp/h on main (there's CDiskTxPos to cope with, for example), but it is a step toward that (see #7815).

  2. laanwj added the label UTXO Db and Indexes on Mar 28, 2016
  3. laanwj added the label RPC on Mar 28, 2016
  4. laanwj cross-referenced this on Mar 28, 2016 from issue [WIP] rest: Stream entire utxo set by laanwj
  5. laanwj force-pushed on Mar 30, 2016
  6. laanwj commented at 9:12 AM on March 31, 2016: member
  7. laanwj cross-referenced this on Apr 5, 2016 from issue Break circular dependency main ↔ txdb by laanwj
  8. laanwj force-pushed on Apr 6, 2016
  9. laanwj commented at 11:05 AM on April 6, 2016: member

    Rebased

  10. in src/coins.cpp:None in c1331def20 outdated
      44 | @@ -45,7 +45,7 @@ bool CCoinsView::GetCoins(const uint256 &txid, CCoins &coins) const { return fal
      45 |  bool CCoinsView::HaveCoins(const uint256 &txid) const { return false; }
      46 |  uint256 CCoinsView::GetBestBlock() const { return uint256(); }
      47 |  bool CCoinsView::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) { return false; }
      48 | -bool CCoinsView::GetStats(CCoinsStats &stats) const { return false; }
      49 | +CCoinsViewCursor *CCoinsView::Cursor() const { return 0; }
    


    sipa commented at 11:10 AM on April 6, 2016:

    Using NULL would be clearer as it's a pointer.


    laanwj commented at 12:05 PM on April 6, 2016:

    Bjarne Stroustrup taught me not to use NULL in c++ code: http://www.stroustrup.com/bs_faq2.html#null I don't care deeply about this though.


    sipa commented at 2:49 PM on April 6, 2016:

    Interesting. Comment retracted.

  11. sipa commented at 11:28 AM on April 6, 2016: member
    • rpc: Add method gettxoutsetinfo2 that uses new Cursor method

    That seems outdated.

  12. laanwj commented at 12:02 PM on April 6, 2016: member

    That seems outdated.

    Yes, I've removed that in the rebase, I had multiple commits with two getutxosetinfo in an intermediate step but that was annoying to rebase over #7766.

  13. laanwj force-pushed on Apr 6, 2016
  14. in src/txdb.cpp:None in eacf28cb38 outdated
     166 | +    return pcursor->Valid();
     167 | +}
     168 | +
     169 | +void CCoinsViewDBCursor::Next()
     170 | +{
     171 | +    while (true) {
    


    sipa commented at 2:52 PM on April 6, 2016:

    This should never loop more than once, I think? Seems that the loop here could hide potential problems.


    laanwj commented at 11:42 AM on April 8, 2016:

    Right, there can't be holes between DB_COINS records, will change this loop.

  15. in src/txdb.cpp:None in eacf28cb38 outdated
     176 | +            return;
     177 |      }
     178 | -    stats.hashSerialized = ss.GetHash();
     179 | -    stats.nTotalAmount = nTotalAmount;
     180 | -    return true;
     181 | +    keyTmp.first = 0; // Invalidate cached key after last record so that GetKey() returns false
    


    sipa commented at 2:53 PM on April 6, 2016:

    Unreachable code?

  16. laanwj commented at 8:14 AM on April 9, 2016: member

    Pushed a commit that should address @sipa's comment: get rid of loop, no more chance of hiding failures.

  17. laanwj force-pushed on Apr 9, 2016
  18. sipa commented at 5:59 PM on April 12, 2016: member

    utACK 299fad9

  19. txdb: Add Cursor() method to CCoinsView to iterate over UTXO set
    Add a method Cursor() to CCoinsView that returns a cursor which can be
    used to iterate over the whole UTXO set.
    
    - rpc: Change gettxoutsetinfo to use new Cursor method
    
    - txdb: Remove GetStats method - Now that GetStats is implemented in
      terms of Cursor, remove it.
    509cb006d5
  20. laanwj force-pushed on Apr 15, 2016
  21. laanwj commented at 2:33 PM on April 15, 2016: member

    Squashed eacf28c 299fad9 into 509cb00

  22. laanwj merged this on Apr 15, 2016
  23. laanwj closed this on Apr 15, 2016

  24. laanwj referenced this in commit 9e47fcec17 on Apr 15, 2016
  25. laanwj referenced this in commit a3310b4d48 on Apr 18, 2016
  26. laanwj cross-referenced this on Apr 18, 2016 from issue txdb: Fix assert crash in new UTXO set cursor by laanwj
  27. laanwj cross-referenced this on May 10, 2016 from issue Periodic automatic UTXO database backup by laanwj
  28. laanwj referenced this in commit 2498324ff9 on Sep 28, 2016
  29. codablock referenced this in commit 3a12fd5395 on Sep 16, 2017
  30. codablock referenced this in commit a6435a56a4 on Sep 19, 2017
  31. codablock referenced this in commit e0e44d0e45 on Sep 27, 2017
  32. ptschip cross-referenced this on Oct 3, 2017 from issue dbcache phase 3 enhancements by ptschip
  33. codablock referenced this in commit 61a7485aae on Oct 12, 2017
  34. codablock referenced this in commit 23fe35a18a on Oct 19, 2017
  35. UdjinM6 referenced this in commit 7d9edd9d15 on Nov 8, 2017
  36. lateminer referenced this in commit 17d8ea7041 on Jan 12, 2018
  37. str4d referenced this in commit 4f3d6245d5 on Jan 27, 2018
  38. dagurval cross-referenced this on Mar 5, 2018 from issue Add cursor to iterate over utxo set by dagurval
  39. str4d referenced this in commit 9b1958bf06 on Mar 9, 2018
  40. str4d referenced this in commit 18752ec0ce on Mar 12, 2018
  41. str4d referenced this in commit 8b4e86b6d3 on Mar 15, 2018
  42. str4d referenced this in commit 9160285eea on Mar 30, 2018
  43. str4d referenced this in commit c602b06475 on Apr 4, 2018
  44. str4d referenced this in commit 06f21492d5 on May 31, 2018
  45. str4d referenced this in commit 9d3c1a7098 on Oct 24, 2018
  46. str4d referenced this in commit 06f3023ac1 on Jan 4, 2019
  47. str4d referenced this in commit 2705fea323 on Mar 14, 2019
  48. str4d referenced this in commit 9e893790c3 on Apr 2, 2019
  49. str4d referenced this in commit ffc99bbf49 on Apr 5, 2019
  50. str4d referenced this in commit 3647f0a7b1 on May 23, 2019
  51. milesmanley referenced this in commit aad9246f47 on Jun 22, 2019
  52. blondfrogs referenced this in commit 8156c70d30 on Jun 28, 2019
  53. milesmanley referenced this in commit 6ffd55e6b6 on Aug 27, 2019
  54. TheTrunk referenced this in commit 0d20c51843 on Aug 27, 2019
  55. random-zebra cross-referenced this on Aug 9, 2020 from issue [Refactoring] Break circular dependency main ↔ txdb by random-zebra
  56. random-zebra referenced this in commit b909e96121 on Aug 12, 2020
  57. bitcoin 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: 2026-05-20 06:55 UTC