Skip to content

Conversation

laanwj
Copy link
Member

@laanwj laanwj commented Mar 28, 2016

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).

@laanwj
Copy link
Member Author

laanwj commented Mar 31, 2016

Travis fail is unrelated (#7470 (comment)), respinning.

@laanwj
Copy link
Member Author

laanwj commented Apr 6, 2016

Rebased

@@ -45,7 +45,7 @@ bool CCoinsView::GetCoins(const uint256 &txid, CCoins &coins) const { return fal
bool CCoinsView::HaveCoins(const uint256 &txid) const { return false; }
uint256 CCoinsView::GetBestBlock() const { return uint256(); }
bool CCoinsView::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) { return false; }
bool CCoinsView::GetStats(CCoinsStats &stats) const { return false; }
CCoinsViewCursor *CCoinsView::Cursor() const { return 0; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. Comment retracted.

@sipa
Copy link
Member

sipa commented Apr 6, 2016

  • rpc: Add method gettxoutsetinfo2 that uses new Cursor method

That seems outdated.

@laanwj
Copy link
Member Author

laanwj commented Apr 6, 2016

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.

@laanwj laanwj force-pushed the 2016_03_utxo_cursor branch from c1331de to eacf28c Compare April 6, 2016 12:08

void CCoinsViewDBCursor::Next()
{
while (true) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@laanwj
Copy link
Member Author

laanwj commented Apr 9, 2016

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

@laanwj laanwj force-pushed the 2016_03_utxo_cursor branch from 30b7efe to 299fad9 Compare April 9, 2016 08:16
@sipa
Copy link
Member

sipa commented Apr 12, 2016

utACK 299fad9

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.
@laanwj laanwj force-pushed the 2016_03_utxo_cursor branch from 299fad9 to 509cb00 Compare April 15, 2016 14:33
@laanwj
Copy link
Member Author

laanwj commented Apr 15, 2016

Squashed eacf28c 299fad9 into 509cb00

@laanwj laanwj merged commit 509cb00 into bitcoin:master Apr 15, 2016
laanwj added a commit that referenced this pull request Apr 15, 2016
…utsetinfo`

509cb00 txdb: Add Cursor() method to CCoinsView to iterate over UTXO set (Wladimir J. van der Laan)
laanwj added a commit to laanwj/bitcoin that referenced this pull request Apr 18, 2016
Remove the mistaken assumption that GetKey returning false signifies
an internal database issue. It will return false when the key cannot
be deserialized into the (char,uint256) stanza, which indicates
that the cursor has reached a different kind of key.

Fixes bug bitcoin#7890 introduced in bitcoin#7756.
laanwj added a commit to laanwj/bitcoin that referenced this pull request Sep 28, 2016
This builds on bitcoin#7756 and

- Adds a streaming API to the HTTP server. This allows streaming data to
  the client chunk by chunk, which is useful when not the entire data is
  available at once or it is huge and wouldn't fit (efficiently) in
  memory.

- Allows downloading the entire UTXO set through `/rest/utxoset`. This
  is a raw dump of all outputs, the state normally hashed by
  `gettxoutsetinfo`. The dump is performed in the background by making
  use of leveldb snapshotting, so without keeping cs_main locked.

    - This can be useful for analysis purposes if you don't want to mess
      with bitcoin core's database

    - Filename (via content-disposition) is
      `utxoset-<height>-<bestblockhash>.dat`. Also a custom
      `X-Best-Block` and `X-Block-Height` header is added.
codablock pushed a commit to codablock/dash that referenced this pull request Oct 19, 2017
…`gettxoutsetinfo`

509cb00 txdb: Add Cursor() method to CCoinsView to iterate over UTXO set (Wladimir J. van der Laan)
lateminer pushed a commit to lateminer/bitcoin that referenced this pull request Jan 12, 2018
Remove the mistaken assumption that GetKey returning false signifies
an internal database issue. It will return false when the key cannot
be deserialized into the (char,uint256) stanza, which indicates
that the cursor has reached a different kind of key.

Fixes bug bitcoin#7890 introduced in bitcoin#7756.
str4d pushed a commit to str4d/zcash that referenced this pull request Jan 27, 2018
Break the circular dependency between main and txdb by:

- Moving `CBlockFileInfo` from `main.h` to `chain.h`. I think this makes
  sense, as the other block-file stuff is there too.

- Moving `CDiskTxPos` from `main.h` to `txdb.h`. This type seems
  specific to txdb.

- Pass a functor `insertBlockIndex` to `LoadBlockIndexGuts`. This leaves
  it up to the caller how to insert block indices.

Zcash: This does not actually break the circular dependency for us yet, as we
still need to pull in bitcoin/bitcoin#7756 and bitcoin/bitcoin#7904.
str4d pushed a commit to str4d/zcash that referenced this pull request Mar 9, 2018
Break the circular dependency between main and txdb by:

- Moving `CBlockFileInfo` from `main.h` to `chain.h`. I think this makes
  sense, as the other block-file stuff is there too.

- Moving `CDiskTxPos` from `main.h` to `txdb.h`. This type seems
  specific to txdb.

- Pass a functor `insertBlockIndex` to `LoadBlockIndexGuts`. This leaves
  it up to the caller how to insert block indices.

Zcash: This does not actually break the circular dependency for us yet, as we
still need to pull in bitcoin/bitcoin#7756 and bitcoin/bitcoin#7904.
str4d pushed a commit to str4d/zcash that referenced this pull request Apr 4, 2018
Break the circular dependency between main and txdb by:

- Moving `CBlockFileInfo` from `main.h` to `chain.h`. I think this makes
  sense, as the other block-file stuff is there too.

- Moving `CDiskTxPos` from `main.h` to `txdb.h`. This type seems
  specific to txdb.

- Pass a functor `insertBlockIndex` to `LoadBlockIndexGuts`. This leaves
  it up to the caller how to insert block indices.

Zcash: This does not actually break the circular dependency for us yet, as we
still need to pull in bitcoin/bitcoin#7756 and bitcoin/bitcoin#7904.
str4d pushed a commit to str4d/zcash that referenced this pull request May 31, 2018
Break the circular dependency between main and txdb by:

- Moving `CBlockFileInfo` from `main.h` to `chain.h`. I think this makes
  sense, as the other block-file stuff is there too.

- Moving `CDiskTxPos` from `main.h` to `txdb.h`. This type seems
  specific to txdb.

- Pass a functor `insertBlockIndex` to `LoadBlockIndexGuts`. This leaves
  it up to the caller how to insert block indices.

Zcash: This does not actually break the circular dependency for us yet, as we
still need to pull in bitcoin/bitcoin#7756 and bitcoin/bitcoin#7904.
str4d pushed a commit to str4d/zcash that referenced this pull request Oct 24, 2018
Break the circular dependency between main and txdb by:

- Moving `CBlockFileInfo` from `main.h` to `chain.h`. I think this makes
  sense, as the other block-file stuff is there too.

- Moving `CDiskTxPos` from `main.h` to `txdb.h`. This type seems
  specific to txdb.

- Pass a functor `insertBlockIndex` to `LoadBlockIndexGuts`. This leaves
  it up to the caller how to insert block indices.

Zcash: This does not actually break the circular dependency for us yet, as we
still need to pull in bitcoin/bitcoin#7756 and bitcoin/bitcoin#7904.
str4d pushed a commit to str4d/zcash that referenced this pull request Apr 5, 2019
Break the circular dependency between main and txdb by:

- Moving `CBlockFileInfo` from `main.h` to `chain.h`. I think this makes
  sense, as the other block-file stuff is there too.

- Moving `CDiskTxPos` from `main.h` to `txdb.h`. This type seems
  specific to txdb.

- Pass a functor `insertBlockIndex` to `LoadBlockIndexGuts`. This leaves
  it up to the caller how to insert block indices.

Zcash: This does not actually break the circular dependency for us yet, as we
still need to pull in bitcoin/bitcoin#7756 and bitcoin/bitcoin#7904.
str4d pushed a commit to str4d/zcash that referenced this pull request May 23, 2019
Break the circular dependency between main and txdb by:

- Moving `CBlockFileInfo` from `main.h` to `chain.h`. I think this makes
  sense, as the other block-file stuff is there too.

- Moving `CDiskTxPos` from `main.h` to `txdb.h`. This type seems
  specific to txdb.

- Pass a functor `insertBlockIndex` to `LoadBlockIndexGuts`. This leaves
  it up to the caller how to insert block indices.

Zcash: This does not actually break the circular dependency for us yet, as we
still need to pull in bitcoin/bitcoin#7756 and bitcoin/bitcoin#7904.
milesmanley pushed a commit to milesmanley/zel that referenced this pull request Jun 22, 2019
Break the circular dependency between main and txdb by:

- Moving `CBlockFileInfo` from `main.h` to `chain.h`. I think this makes
  sense, as the other block-file stuff is there too.

- Moving `CDiskTxPos` from `main.h` to `txdb.h`. This type seems
  specific to txdb.

- Pass a functor `insertBlockIndex` to `LoadBlockIndexGuts`. This leaves
  it up to the caller how to insert block indices.

Zcash: This does not actually break the circular dependency for us yet, as we
still need to pull in bitcoin/bitcoin#7756 and bitcoin/bitcoin#7904.
blondfrogs pushed a commit to blondfrogs/zelcash that referenced this pull request Jun 28, 2019
Break the circular dependency between main and txdb by:

- Moving `CBlockFileInfo` from `main.h` to `chain.h`. I think this makes
  sense, as the other block-file stuff is there too.

- Moving `CDiskTxPos` from `main.h` to `txdb.h`. This type seems
  specific to txdb.

- Pass a functor `insertBlockIndex` to `LoadBlockIndexGuts`. This leaves
  it up to the caller how to insert block indices.

Zcash: This does not actually break the circular dependency for us yet, as we
still need to pull in bitcoin/bitcoin#7756 and bitcoin/bitcoin#7904.
milesmanley pushed a commit to milesmanley/zel that referenced this pull request Aug 27, 2019
Break the circular dependency between main and txdb by:

- Moving `CBlockFileInfo` from `main.h` to `chain.h`. I think this makes
  sense, as the other block-file stuff is there too.

- Moving `CDiskTxPos` from `main.h` to `txdb.h`. This type seems
  specific to txdb.

- Pass a functor `insertBlockIndex` to `LoadBlockIndexGuts`. This leaves
  it up to the caller how to insert block indices.

Zcash: This does not actually break the circular dependency for us yet, as we
still need to pull in bitcoin/bitcoin#7756 and bitcoin/bitcoin#7904.
TheTrunk pushed a commit to RunOnFlux/fluxd that referenced this pull request Aug 27, 2019
Break the circular dependency between main and txdb by:

- Moving `CBlockFileInfo` from `main.h` to `chain.h`. I think this makes
  sense, as the other block-file stuff is there too.

- Moving `CDiskTxPos` from `main.h` to `txdb.h`. This type seems
  specific to txdb.

- Pass a functor `insertBlockIndex` to `LoadBlockIndexGuts`. This leaves
  it up to the caller how to insert block indices.

Zcash: This does not actually break the circular dependency for us yet, as we
still need to pull in bitcoin/bitcoin#7756 and bitcoin/bitcoin#7904.
random-zebra added a commit to PIVX-Project/PIVX that referenced this pull request Aug 12, 2020
5147571 Break circular dependency main ↔ txdb (random-zebra)
2725fac txdb: Add Cursor() method to CCoinsView to iterate over UTXO set (random-zebra)

Pull request description:

  Other two quick backports needed for the upcoming per-txout model.

  - bitcoin#7756 - Add cursor to iterate over utxo set, use this in `gettxoutsetinfo`
    > - 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.

  - bitcoin#7815 - Break circular dependency main ↔ txdb (part of this was done already in #1302 and #1319)
    > - Moving `CBlockFileInfo` from main.h to chain.h. I think this makes sense, as the other block-file stuff is there too.
    > - Moving `CDiskTxPos` from main.h to txdb.h. This type, used for `-txindex` seems specific to txdb.
    > - Pass a functor `insertBlockIndex` to `LoadBlockIndexGuts`. This leaves it up to the caller how to insert block indices.

ACKs for top commit:
  furszy:
    ACK 5147571
  Fuzzbawls:
    ACK 5147571

Tree-SHA512: 166f5d797fac68667c59e002a3596af65596cd6ebee5e8b4bee538e6f66ec5f6365e4dd0bbb44be2226ebb51411d4db01f9f2417660841ed7a5125b3c8a7ad97
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants