-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Add cursor to iterate over utxo set, use this in gettxoutsetinfo
#7756
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
ab53441
to
47d25a8
Compare
Travis fail is unrelated (#7470 (comment)), respinning. |
47d25a8
to
c1331de
Compare
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; } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. Comment retracted.
That seems outdated. |
Yes, I've removed that in the rebase, I had multiple commits with two |
c1331de
to
eacf28c
Compare
|
||
void CCoinsViewDBCursor::Next() | ||
{ | ||
while (true) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Pushed a commit that should address @sipa's comment: get rid of loop, no more chance of hiding failures. |
30b7efe
to
299fad9
Compare
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.
299fad9
to
509cb00
Compare
Squashed eacf28c 299fad9 into 509cb00 |
…utsetinfo` 509cb00 txdb: Add Cursor() method to CCoinsView to iterate over UTXO set (Wladimir J. van der Laan)
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.
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.
…`gettxoutsetinfo` 509cb00 txdb: Add Cursor() method to CCoinsView to iterate over UTXO set (Wladimir J. van der Laan)
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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
I need this for something else, but I think this is simply a better API. I also vaguely remember this has been discussed before.
Cursor()
toCCoinsView
that returns a cursor which can be used to iterate over the whole UTXO set.GetUTXOStats
in terms of this, removeGetStats()
method onCCoinsView
.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).