As suggested here: #3220 (comment)
It is confusing, slow, and already deprecated.
As suggested here: #3220 (comment)
It is confusing, slow, and already deprecated.
<!--e57a25ab6845829454e8d69fc972939a-->Note to reviewers: This pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
1032 | - txOut = tx; 1033 | - hashBlock = pindexSlow->GetBlockHash(); 1034 | - return true; 1035 | - } 1036 | - } 1037 | - }
Accidental removal of this scope?
No, not accidental. Just wrong.
1002 | @@ -1003,10 +1003,8 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa 1003 | * Return transaction in txOut, and if it was found inside a block, its hash is placed in hashBlock. 1004 | * If blockIndex is provided, the transaction is fetched from the corresponding block. 1005 | */ 1006 | -bool GetTransaction(const uint256& hash, CTransactionRef& txOut, const Consensus::Params& consensusParams, uint256& hashBlock, bool fAllowSlow, CBlockIndex* blockIndex) 1007 | +bool GetTransaction(const uint256& hash, CTransactionRef& txOut, const Consensus::Params& consensusParams, uint256& hashBlock, CBlockIndex* blockIndex) 1008 | { 1009 | - CBlockIndex* pindexSlow = blockIndex;
After this removal, where do you still use blockIndex? It seems to me that "lookup by block index" is now also removed. Is that intentional?
Oops, no, fixing.
Nice to see this go, thanks for the clean up!
Some tests appear to rely on getrawtransaction working for confirmed transactions that still have unspent outputs which is causing travis to fail.
Would the removal need to go through an "-deprecatedrpc" cycle?
Or: How do you know no one is using this?
For getrawtransaction, I don't think so. It's already been marked deprecated, and I can't imagine anyone actually relying on it.
But perhaps for gettxoutproof/REST we should?
utACK 5e155e69e2fe4eae832874868e9e82577d07e495
The PR description/commit message seems misleading. The "search by block hash" option is still supported, as it should be.
utACK 5e155e69e2fe4eae832874868e9e82577d07e495
utACK 5e155e69e2fe4eae832874868e9e82577d07e495
aside from the misleading commit message, utACK https://github.com/bitcoin/bitcoin/pull/13931/commits/5e155e69e2fe4eae832874868e9e82577d07e495
Concept ACK, I agree that the condition "unspent output in the utxo for this transaction" is too confusing to be worth maintaining.
Hopefully we can also get #13014 merged (pruned -txindex support), so there's really no reason not to have use -txindex if you need getrawtransaction for confirmed txs; if you have enough storage for an unpruned node, the index shouldn't be a problem, if you have pruned node then the index will be very small.
Maybe add this line to the commit message: "If the transaction index is not enabled using the -txindex command, a blockhash must be specified"
for future PR maybe: note in the help that gettxout can suffice for most needs as a replacement?
41 | @@ -42,9 +42,9 @@ def set_test_params(self): 42 | self.setup_clean_chain = True 43 | self.num_nodes = 3 44 | # This test tests SegWit both pre and post-activation, so use the normal BIP9 activation. 45 | - self.extra_args = [["-rpcserialversion=0", "-vbparams=segwit:0:999999999999", "-addresstype=legacy", "-deprecatedrpc=addwitnessaddress"], 46 | - ["-blockversion=4", "-rpcserialversion=1", "-vbparams=segwit:0:999999999999", "-addresstype=legacy", "-deprecatedrpc=addwitnessaddress"], 47 | - ["-blockversion=536870915", "-vbparams=segwit:0:999999999999", "-addresstype=legacy", "-deprecatedrpc=addwitnessaddress"]] 48 | + self.extra_args = [["-rpcserialversion=0", "-vbparams=segwit:0:999999999999", "-addresstype=legacy", "-deprecatedrpc=addwitnessaddress", "-txindex"],
It's a shame that this PR adds -txindex to a bunch of tests (since running with txindex is not the standard way to run bitcoind, so the tests are no longer testing the mainline case).
I don't think it's a show-stopper, but it'd be preferable to update the tests to not have to use txindex, or perhaps add a TODO to remove txindex at some point in the future. We could also add a comment on why txindex is needed for these tests to pass.
what is the standard way to run bitcoind? seems like there is some confusion in the original conversation too: #3220 (comment)
my understanding is three use cases for this method (still supported after this change):
the use case removed by this PR is
I have to take a closer look at how the tests work, but is the predominant usage to pass in a blockhash, or to be searching the mempool?
my understanding is...
yes, that's correct, although I'd be more specific in 3: ~check all the things~ -> check mempool and tx index.
is the predominant usage to pass in a blockhash
It depends on whether you're trying to find a confirmed or unconfirmed tx. I expect both usages are common.
~check all the things~ -> check mempool and tx index.
is there somewhere a transaction could be other than the mempool or tx index?
if -txindex is enabled then no - the txindex contains all the confirmed transactions, and your mempool contains the unconfirmed txs that the node is aware of (obviously excluding conflicts, replaced txs, non-standard txs, expired txs, etc)
ok kewl. just confirming that the only qualm was with the imprecision of language :) thanks!
73 | @@ -74,7 +74,6 @@ static UniValue getrawtransaction(const JSONRPCRequest& request) 74 | "is known, its hash can be provided even for nodes without -txindex. Note that if a blockhash is\n" 75 | "provided, only that block will be searched and if the transaction is in the mempool or other\n" 76 | "blocks, or if this node does not have the given block available, the transaction will not be found.\n" 77 | - "DEPRECATED: for now, it also works for transactions with unspent outputs.\n"
I think this comment could be clearer now that the logic is more straigtforward. Something like:
I'd start without blockhash argument (mempool only), then blockhash, then say blockhash can be omitted if txindex.
I'd start without blockhash argument (mempool only), then blockhash, then say blockhash can be omitted if txindex.
I don't think this captures the logic. "without blockhash argument (mempool only)" is not correct, since we'll check the whole blockchain if txindex is enabled. This also doesn't communicate that if blockhash is provided, then txindex won't be used to check the entire blockchain.
207 | @@ -209,10 +208,8 @@ static UniValue gettxoutproof(const JSONRPCRequest& request) 208 | throw std::runtime_error( 209 | "gettxoutproof [\"txid\",...] ( blockhash )\n" 210 | "\nReturns a hex-encoded proof that \"txid\" was included in a block.\n" 211 | - "\nNOTE: By default this function only works sometimes. This is when there is an\n" 212 | - "unspent output in the utxo for this transaction. To make it always work,\n" 213 | - "you need to maintain a transaction index, using the -txindex command line option or\n" 214 | - "specify the block in which the transaction is included manually (by blockhash).\n" 215 | + "\nIf the transaction index is not enabled using the -txindex command, a blockhash\n"
-txindex is a command line option, not a command :)
207 | @@ -209,10 +208,8 @@ static UniValue gettxoutproof(const JSONRPCRequest& request)
208 | throw std::runtime_error(
209 | "gettxoutproof [\"txid\",...] ( blockhash )\n"
This function can be much simplified now that we're not looking for unspent coins in the UTXO set:
diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp
index 591943594..2d246e016 100644
--- a/src/rpc/rawtransaction.cpp
+++ b/src/rpc/rawtransaction.cpp
@@ -245,28 +245,17 @@ static UniValue gettxoutproof(const JSONRPCRequest& request)
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
}
} else {
- LOCK(cs_main);
-
- // Loop through txids and try to find which block they're in. Exit loop once a block is found.
- for (const auto& tx : setTxids) {
- const Coin& coin = AccessByTxid(*pcoinsTip, tx);
- if (!coin.IsSpent()) {
- pblockindex = chainActive[coin.nHeight];
- break;
- }
+ if (!g_txindex) {
+ throw JSONRPCError(RPC_INVALID_PARAMETER, "blockhash must be provided when txindex is disabled.");
}
- }
-
- // Allow txindex to catch up if we need to query it and before we acquire cs_main.
- if (g_txindex && !pblockindex) {
- g_txindex->BlockUntilSyncedToCurrentChain();
- }
+ // Allow txindex to catch up if we need to query it and before we acquire cs_main.
+ if (!pblockindex) {
+ g_txindex->BlockUntilSyncedToCurrentChain();
+ }
- LOCK(cs_main);
+ LOCK(cs_main);
- if (pblockindex == nullptr)
- {
CTransactionRef tx;
if (!GetTransaction(oneTxid, tx, Params().GetConsensus(), hashBlock) || hashBlock.IsNull())
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction not yet in block");
(also at https://github.com/jnewbery/bitcoin/tree/pr13931.1 / https://github.com/jnewbery/bitcoin/commit/eeef25bfb5470efddfb2bf3e998dfb124531e473)
This also improves error reporting if a blockhash is not provided and txindex is not enabled ("blockhash must be provided when txindex is disabled." instead of "Transaction not yet in block")
Tests also need to be updated with this change: https://github.com/jnewbery/bitcoin/commit/0ffbc2055908b2fa1797f92b4391c2bbbbec588a
That "blockhash must be provided" message is a very useful addition to gettxoutproof (I just got confused by it on another branch).
Concept ACK
<!--cf906140f33d8803c4a75a2196329ecb-->Needs rebase
<!--5fd3d806e98f4a0ca80977bb178665a0-->There hasn't been much activity lately and the patch still needs rebase, so I am closing this for now. Please let me know when you want to continue working on this, so the pull request can be re-opened.