Skip to content
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

Getrawtransaction working partially without -txindex is confusing #3220

Closed
sipa opened this issue Nov 7, 2013 · 29 comments
Closed

Getrawtransaction working partially without -txindex is confusing #3220

sipa opened this issue Nov 7, 2013 · 29 comments

Comments

@sipa
Copy link
Member

sipa commented Nov 7, 2013

I think we should make getrawtransaction fail entirely if no txindex is enabled, instead of only working on not-fully-spent transactions, with a confusing error message otherwise.

@sipa
Copy link
Member Author

sipa commented Nov 7, 2013

And a stretch goal: there should be some functionality to query a raw transaction from the wallet rather than the blockchain.

@jgarzik
Copy link
Contributor

jgarzik commented Nov 7, 2013

More than a stretch goal, IMO, a requirement. I know of several softwares used internally that rely on 'getrawtransaction' working without txindex=1.

At a minimum, there must be a compatible replacement.

I get the confusion angle and agree -- but people are using this feature actively, even with txindex=0.

@laanwj
Copy link
Member

laanwj commented Nov 7, 2013

I understand the confusion but I don't think removing functionality is a good response, wouldn't it be better to improve the error message to be less confusing? (maybe even mention -txindex in the message...)

Making it possible to query raw transactions from the wallet sounds like a good idea. Maybe as a new RPC command getwallettransaction to not confuse wallet and blockchain functionality?

@sipa
Copy link
Member Author

sipa commented Nov 7, 2013

@jgarzik I think you may be misinformed. getrawtransaction currently does not work for wallet transactions. It works for transactions that are either in the mempool or not entirely spent (=in the UTXO set). This may overlap with wallet transactions of course, but is not guaranteed. I think that funtionality doesn't maatch many use cases, and is inefficient. I'd rather have it work under very clear conditions.

@laanwj I'm in favor of both improving the error message and a getwallettransaction command (though gettransaction is also a wallet RPC, but one that fetches ledger-level information, not transaction-level information).

@luke-jr
Copy link
Member

luke-jr commented Nov 7, 2013

@sipa No reason it couldn't work for wallet transactions - the raw data is all in the wallet too, IIRC.

@gmaxwell
Copy link
Contributor

gmaxwell commented Nov 7, 2013

We could just have another RPC that works on wallet transactions. I have had people pull txn that they have stuck many times using get rawtransactions, so I think we need to at least preserve the wallet behavior.

Any opinion on adding a getblockrawtransaction ? which would replace the non-determinstic behavior we have for txindex=0 now?

@sipa
Copy link
Member Author

sipa commented Nov 7, 2013

@luke-jr Sure, my main concern is not further confusing wallet operations with blockchain operations.

We could of course extend getrawtransaction with wallet functionality, and at the same time deprecate it in favor of a getwalletrawtransaction and getblockchainrawtransaction (the latter name may be confusing, as i suppose it would also do mempool fetching).

@laanwj
Copy link
Member

laanwj commented Nov 8, 2013

If we're going to deprecate getrawtransaction let's not make it more powerful first :)

Maybe even split it into three commands:

  • getwalletrawtransaction -> only active of not in nowallet mode
  • getblockchainrawtransaction -> only active when txindex=1
  • getmempoolrawtransaction -> always active

Edit: alternatively, make it one command, then add flags what sources to query. This makes it possible to query multiple or all sources at once if desired.

laanwj added a commit to laanwj/bitcoin that referenced this issue Feb 13, 2014
This allows getting raw transaction data from the wallet even if the
transaction is no longer in the blockchain / mempool (for example if it
got orphaned due to malleability abuse).

Was also proposed in bitcoin#3220, but is urgently useful now.
@laanwj
Copy link
Member

laanwj commented May 6, 2014

gettransaction shows the raw hex of a wallet transaction since pull #3668. That's at least one of the points in this issue.

@sipa
Copy link
Member Author

sipa commented May 6, 2014

Is there really any evidence of people using getrawtransaction without -txindex? I can't imagine how the current behaviour could be reliable for them.

@laanwj
Copy link
Member

laanwj commented May 9, 2014

@sipa One usage scenario would be together with getrawmempool, to get transaction data for mempool transactions. If getrawtransaction were to only work with -txindex we'd have to do something like #3256 to get the tx...

@sipa
Copy link
Member Author

sipa commented May 9, 2014

@laanwj Perhaps. Though if your transaction suddenly confirms between getrawmempool and getrawtransaction, you won't get it either.

@laanwj
Copy link
Member

laanwj commented May 9, 2014

Yes, but if it confirms in that time, it may not be interesting anymore for a process monitoring the mempool.

@promag
Copy link
Contributor

promag commented Dec 7, 2017

With the new deprecation mechanism we could mark it deprecated if -txindex is not set in 0.16 and make it available only if -txindexin 0.17?

@Sjors
Copy link
Member

Sjors commented Dec 28, 2017

Rather than deprecating, why not make it work without -txindex, albeit slow? As I suggested in #10609 (comment) we could add since argument which would specify how far to look back. In addition there could be a timeout argument with some sane default, after which it will give up with an error.

The use case I have in mind here is e.g. a Lightning node that's looking for fairly recent transactions, really doesn't need a full transaction index and can probably live with some delay in response time.

@sipa
Copy link
Member Author

sipa commented Dec 28, 2017

I don't think that's really a good approach. If people have needs to index transactions in the chain, there should be better other projects for that.

@Sjors
Copy link
Member

Sjors commented Dec 28, 2017

@sipa what are your thoughts on a partial index through -txindex=SOME_MIN_HEIGHT? Or a rolling index down to the prune height?

It doesn't seem ideal having to install some middleware app in order to use second layer stuff, nor does it seem ideal for this second layer software to worry about such a basic feature as checking if a transaction is known (including all the reorg related bookkeeping). I'm not proposing a complete overhaul, but some sort of low hanging fruit compromise would be useful.

@sipa
Copy link
Member Author

sipa commented Dec 28, 2017

@Sjors I don't think this is really needed. If you need to watch for a certain txid, you can add one of its output addresses to a watch-only wallet or so, rather than relying on full indexing of the chain (even if it's just the last few blocks).

@promag
Copy link
Contributor

promag commented Feb 22, 2018

If we're going to deprecate getrawtransaction let's not make it more powerful first :)

@laanwj for reference getrawtransaction was improved in #10275.

If the goal is to "force" getrawtransaction to work only with -txindex then we could make getrawtransaction only available if:

  1. -txindex is set; or
  2. -txindex is not set but -deprecatedrpc=getrawtransaction is set.

@jimpo
Copy link
Contributor

jimpo commented Mar 30, 2018

I'd be in favor of dropping the coins view cache check because it is not reliable and confusing. The remaining behavior would be:

  • If block_hash argument is set, check only that block, and error if not found
  • Otherwise
    • Check the mempool and return if tx is found
    • If txindex is enabled and up to date (see Build tx index in parallel with validation #11857), check it and conclusively return tx or "Not found"
    • If txindex is disabled, error with "No such mempool transaction. Use -txindex to enable blockchain transaction queries"

@promag
Copy link
Contributor

promag commented Mar 30, 2018

Check the mempool and return if tx is found

There is getmempoolentry for this so we could also drop that check from getrawtransaction.

@vengat90
Copy link

vengat90 commented Aug 8, 2018

How to get receive from an address in the transaction, which command used in http://chainquery.com site?

@Sjors
Copy link
Member

Sjors commented Aug 8, 2018

I'd rather have this feature work partially, with clear documentation and error codes, than to make it conditional on a full txindex. That's because getrawtransaction can be quite useful to lightning nodes and perhaps even lightweight wallets, that need to occasionally fetch historical stuff (not just monitor new transactions).

I think the feature can be made complete in the longer run without txindex.

@promag wrote:

@laanwj for reference getrawtransaction was improved in #10275.

I.e. it can now take a blockhash hint.

In addition, we could build on top of #10794 to allow getrawtransaction to work even if that block is pruned, by fetching it from the network if needed.

Perhaps a future txindex light feature could use Compact Block Filter (BIP-158 style), so that we can very quickly scan all blocks, which would return a bunch of false positives that are then searched brute-force.

@sipa
Copy link
Member Author

sipa commented Aug 8, 2018

@Sjors Elsewhere I have suggested splitting the feature up into separate RPCs; for example txindexgetrawtransaction (which only works when -txindex is enabled) and mempoolgetrawtransaction (which always works, but only for unspent transactions). Support for the it-works-when-not-pruned-and-only-for-transactions-which-have-at-least-one-unspent-output-but-very-slowly feature would only remain in the deprecated getrawtransaction RPC, as I don't think there is much use for it, and its conditions are too obscure to explain.

EDIT: Actually an RPC already exists for the mempool version, called getmempoolentry.

@sipa
Copy link
Member Author

sipa commented Aug 8, 2018

I like @jimpo's suggested above.

@maflcko
Copy link
Member

maflcko commented Aug 8, 2018

So how would removing the txout check play with races, where a tx leaves the mempool right when mempoolgetrawtransaction or getrawtransaction is called?

Also mentioned earlier #3220 (comment) by @sipa.

@maflcko
Copy link
Member

maflcko commented Aug 8, 2018

I think the current documentation is quite clear, and there is no pressing need to change the logic right now. Also note the issue is about 5 years old and most of the discussion no longer apply to the code in master. I suggest closing it.

documentation on current master for reference:

NOTE: By default this function only works for mempool transactions. If the -txindex option is
enabled, it also works for blockchain transactions. If the block which contains the transaction
is known, its hash can be provided even for nodes without -txindex....

@jimpo
Copy link
Contributor

jimpo commented Aug 9, 2018

@MarcoFalke The documentation at the end says "DEPRECATED: for now, it also works for transactions with unspent outputs.\n" I propose fully removing support for that because it is confusing, deprecated, and slow.

I'm not in favor of changing getrawtransaction to stop returning mempool txs.

@maflcko
Copy link
Member

maflcko commented Aug 9, 2018

I'm not in favor of changing getrawtransaction to stop returning mempool txs.

If you do the step and remove the utxo lookup, you might as well remove the mempool lookup and make it explicit that the interface was changed for txes that recently moved from the mempool to the utxo set. (Tell users to use getmempoolentry, after adding a rawtx key to the returned dict.)

maflcko pushed a commit to maflcko/bitcoin-core that referenced this issue Jan 30, 2019
04da9f4 [RPC] Update getrawtransaction interface (Amiti Uttarwar)

Pull request description:

  - stop checking unspent UTXOs for a transaction when txindex is not enabled, as per conversation here: bitcoin#3220 (comment)
  - code contributed by sipa

Tree-SHA512: aa07353bccc14b81b7803992a25d076d6bc06d15ec7c1b85828dc10aea7e0498d9b49f71783e352ab8a14b0bb2010cfb7835de3dfd1bc6f2323f460449348e66
@maflcko maflcko closed this as completed Feb 12, 2019
Bushstar pushed a commit to Bushstar/omnicore that referenced this issue Apr 8, 2020
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Dec 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

11 participants