Skip to content

Conversation

@droark
Copy link
Contributor

@droark droark commented Feb 20, 2017

This is an attempt to revive PR #8660 (and, by extension, PR #5048). For now, this PR simply compiles without fresh warnings or errors. Once it is confirmed that no more conflicts exist, the remaining comments/requests from #8660 will be fully addressed.

@paveljanik
Copy link
Contributor

Wshadow statistics:
1 coinsbyscript.cpp:180:2200: warning: declaration shadows a local variable [-Wshadow]

@droark droark force-pushed the gettxoutsbyaddress branch from 89293d7 to bd92c93 Compare February 20, 2017 21:21
@droark
Copy link
Contributor Author

droark commented Feb 20, 2017

@paveljanik - Thanks! Fixed that up. Looks like that's the only shadow warning.

@droark droark force-pushed the gettxoutsbyaddress branch 2 times, most recently from d828eaa to 51de4fa Compare February 20, 2017 21:56
@laanwj
Copy link
Member

laanwj commented Feb 22, 2017

Thanks for reviving this. IMO this is important.

@laanwj laanwj added this to the 0.15.0 milestone Feb 22, 2017
@sidhujag
Copy link

sidhujag commented Mar 14, 2017

Concept ACK, are there any statistics on how much extra burden this places on an ordinary node with the index off?

@instagibbs
Copy link
Member

needs rebase

@droark
Copy link
Contributor Author

droark commented Mar 17, 2017

@instagibbs - Rebased. Thanks for the heads up. (Side note: Is there any way to have GH tell you when a conflict occurs? That would be really handy.)

@sidhujag - Good question. I don't know offhand. I'm happy to do some benchmarking. I may need some help with that. If anybody would like to make some suggestions, I'm all ears.

All - Will get more movement on this. Life intervened for awhile and has finally slowed down enough to where I can dedicate more time to this.

@droark droark force-pushed the gettxoutsbyaddress branch from b9ac7b4 to eab6e67 Compare March 17, 2017 23:05
@sidhujag
Copy link

Thanks droark great feature btw.. this makes walletless spending very easy

@droark droark force-pushed the gettxoutsbyaddress branch from eab6e67 to 8ec71e0 Compare March 18, 2017 15:59
@droark
Copy link
Contributor Author

droark commented Mar 18, 2017

Am placing a to-do list here to remind myself of what I need to do, and solicit feedback on anything people might think is missing.

  • Remove all Boost code from the PR.
  • Address feedback from txoutsbyaddress index (take 2) #8660 (primarily @ryanofsky). (Mostly done but I want to double check a couple of things before proceeding.)
  • Add some C++ tests for CCoinsView classes.
  • Probably switch names of this & that per the suggestion of @gmaxwell. ("utxoindex" is my current choice but I'm not attached to it.)
  • Add a default constructor value for CTxMemPool. (A recently merged PR, combined with this PR, inadvertently nukes the default constructor.)
  • Check in once a day to see if a rebase is needed. (Ongoing task.)

@btcdrak
Copy link
Contributor

btcdrak commented Mar 22, 2017

needs rebase.

@droark droark force-pushed the gettxoutsbyaddress branch from ab345ad to fcc0caa Compare March 22, 2017 01:36
@droark
Copy link
Contributor Author

droark commented Mar 22, 2017

@btcdrak - Thanks. Rebased.

@droark droark force-pushed the gettxoutsbyaddress branch from 6ca6511 to 72b72a8 Compare March 22, 2017 20:58
@weex
Copy link

weex commented Mar 23, 2017

Running this on a .bitcoin/ folder that was last used with 0.13 and was run pruned to 2000. It seems 1GB of ram is too low for this enabled as I got an out of memory error. Now on restarting I get the following after/during the "Rescanning..." step:

~/.bitcoin# bitcoind: coinsbyscript.cpp:53: CCoinsByScript& CCoinsViewByScript::GetCoinsByScript(const CScript&, bool): Assertion `it != cacheCoinsByScript.end()' failed.

@droark droark force-pushed the gettxoutsbyaddress branch 7 times, most recently from b804b2f to 6c96fc9 Compare March 29, 2017 16:33
djpnewton and others added 6 commits April 27, 2017 16:21
- Switched getutxosbyaddress to getutxoindex, and altered the files as needed to reflect this change.
- Switched CCoinsMapByScript key from uint160 to CScriptID.
- Various C++11-related changes.
- Removed a try/catch case from CCoinsViewDB::CountCoins().
- Changed a const ref in CTxMemPool to a const copy to prevent a possible subtle error.
- Added a default value (false) for UTXO indexing under CTxMemPool.
@dexX7
Copy link
Contributor

dexX7 commented May 25, 2017

Thanks for preparing this @droark. Is this PR still alive?

@droark
Copy link
Contributor Author

droark commented May 30, 2017

@dexX7 - Thanks for checking in. Some family-related issues came up recently that I had to deal with for awhile. I'm almost done rebasing the PR and will catch up with the remaining feedback ASAP, along with some test harness changes that probably need to be folded in. The path forward looks pretty clear to me, IMO. I just need to wrap up the work.

@laanwj laanwj removed this from the 0.15.0 milestone Jul 6, 2017
@jtimon
Copy link
Contributor

jtimon commented Jul 7, 2017

I still need to read more, but...

Regarding searching by address , by scriptPubKey, or by COutPoint (tx_id, output_pos), I'm not sure whether I want them all or a subset of them.
The later doesn't require any further index.
Searching by scriptPubKey only requires an additional scriptPubKey -> COutPoint index but not much logic.
Searching by address on the other hand...there's many types of addresses and people still propose new better ones...I wonder if perhaps the translation address -> scriptPubKey (which shouldn't require an extra index on top of the scriptPubKey one) belongs to an upper layer like the wallet and/or ui that the users of this feature implement. I'm like supporting it here, but maybe script/standard needs to be extended for the address -> scriptPubKey translator (sorry to reiterate, but I don't think we want an address index, just a one way translation function [the other way is for wallets and relay policies, or higher level protocols ala coinjoin and whatnot]).

This all assumes you create a new scriptPubKey -> COutPoint index.

Regarding utxo vs stxo vs txo...
You can easily serve both utxo and stxo (that is, the whole txo) by just calling GetTransaction() (in validation.o) like getrawtransaction does, without needing any consideration on whether the the output is spent or not while getting the better performance if the COutPoint happens to be in the current utxo, which is very nice.
That will just complain if you search when you are pruning or not using -txindex and thus you cannot serve certain outputs unless you do a rescan which is completely out of the question.
You probably want a couple of options -utxoscriptindex and -txoscriptindex or something of the sort.
Having -utxoscriptindex but not -txoscriptindex maybe should force the error when searching for spent txo's. Having both is just reduntant. Having -txoscriptindex implies having the full historic scriptPubKey -> COutPoint index.
You don't even need to remove the spent entries from the index if you only have -utxoscriptindex if you make sure the outputs fail when -utxoscriptindex is set but -txoscriptindex is not. In that case, garbage collecting or "is spent reference counting" or "worrying about reorgs" or "adding a spent bool to the index" would probably be nice additions to have since that selection could prune them and otherwise they will accumulate over running time, even if they're just entries on an index and not the outputs themselves. That seems like it could be an important distraction in the short term.

So although I'm not against gettxoutsbyaddress and I celebrate concept ACK it, but I think it would be nicer to get gettxoutsbyoutpoint and gettxoutsbyscript reviewed and merged in that order first. But I think some other people don't like chained PRs all that much, so just take it as "if we're offering gettxoutsbyaddress, we should be able to offer gettxoutsbyoutpoint and gettxoutsbyscript 'almost for free'(tm) too".

It may seem contradictory: I'm asking you to do more with respect to utxo/stxo, but I'm suggesting to do less with respect to addresses and properly removing things for the users that want this feature but don't want to be full archives, which is something we can optimize further later after leveraging the easy important one, which is just looking in the utxo first.
The way I see it, the utxo is just the subset of the txo that can't be pruned, we happen to cache very efficiently, so it is nice to always search there first just in case and well, people usually care less about stxo because it is already spent...but is simple to also serve it or just complain when you can't or you are not expected to, sorry to reiterate.

Anyway, feel free to note the parts of my long post you like in whatever order you like best and ignore the rest. I plan to have a deeper look either way beyond this concept ack.

All the best but needs rebase.

@jtimon
Copy link
Contributor

jtimon commented Jul 7, 2017

Sorry, no, using GetTransaction doesn't leverage the utxo index we maintain...One would need to search in the utxo (with CCoinsViewCache::AccessCoin) first and then try with GetTransaction only if we want to also serve stxo, which should perhaps be left out of scope for this PR as a later improvement.

@jtimon
Copy link
Contributor

jtimon commented Jul 14, 2017

Sorry for the long post, not for being long but for being incorrect.

There's not need for a gettxobyoutpoint or similar because it already exists and is named gettxout!
That means everything I said about "optimize later, it shouldn't be hard" turns into "it's already done".

Only the slower parts were missing, which I plan to serve in #10822 which is just a draft that needs lots of testing.

To reiterate, the important parts of my previous fedback:

  1. I'm more than happy to extend whatever you do for utxo for txo too, ideallly almost transparently
  2. Don't do an address index, do a more generic script (that means binary or lower level, hex strings on rpc) to outpoint index, and once you have the outpoint you have the whole txo (unless you don't tcindex or you prune).
  3. Create a function to translate "an address" into a script so that it can be easily searched for in the outpoint -> script index. There will always be new address types your index doesn't explicitly support yet, make them support your index instead.

The PR that should help extend whatever is done for utxo to txo if you do the index: outpoint -> script; is the following:

#10822

As said it needs testing, but there's no need to wait, let's expose utxo if we can first and then txo "almost for free"(tm).

Sorry again for invading the pr in a distractive way, but this needs rebase.

@braydonf
Copy link

braydonf commented Apr 17, 2018

What's the status of this PR, needs more review and testing? General concept ok?

I think it would be useful to have an index on the UTXO set for the purposes of supporting external and hardware wallets.

@jnewbery
Copy link
Contributor

Closing as 'up for grabs'. PR author hasn't checked in for about a year.

@droark - if you still want this, feel free to re-open and rebase!

@maflcko
Copy link
Member

maflcko commented Mar 5, 2019

Picked up in " Add address-based index (attempt 4?) #14053 "

@laanwj
Copy link
Member

laanwj commented Aug 20, 2020

Picked up in " Add address-based index (attempt 4?) #14053 "

I think those are different, right? this an indeex over the UTXO set, while that is an index over all addresses in the block chain? Or do I get this wrong.

@maflcko
Copy link
Member

maflcko commented Aug 20, 2020

Indeed looks like it. I wonder why it is called take 4 then.

Though, scanning the utxo set can already be done with scantxoutset, no?

@laanwj
Copy link
Member

laanwj commented Aug 20, 2020

Though, scanning the utxo set can already be done with scantxoutset, no?

Absolutely, that does the same thing. Though it can be pretty slow, which can be awkward if it's part of some user flow, so UTXO indexing is not completely out of the picture probably.

@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
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.