Drop support for getrawtransaction for confirmed tx without txindex #13931

pull sipa wants to merge 1 commits into bitcoin:master from sipa:201808_noslowutxogetrawtx changing 11 files +20 −31
  1. sipa commented at 9:42 PM on August 9, 2018: member

    As suggested here: #3220 (comment)

    It is confusing, slow, and already deprecated.

  2. DrahtBot commented at 10:37 PM on August 9, 2018: member

    <!--e57a25ab6845829454e8d69fc972939a-->Note to reviewers: This pull request conflicts with the following ones:

    • #14180 (qa: Run all tests even if wallet is not compiled by MarcoFalke)
    • #13903 (Significantly reduce GetTransaction cs_main locking (TheBlueMatt) by MarcoFalke)
    • #13864 (validation: Document where we are intentionally ignoring bool return values from validation related functions by practicalswift)

    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.

  3. in src/validation.cpp:1039 in 41592d5259 outdated
    1032 | -                    txOut = tx;
    1033 | -                    hashBlock = pindexSlow->GetBlockHash();
    1034 | -                    return true;
    1035 | -                }
    1036 | -            }
    1037 | -        }
    


    MarcoFalke commented at 1:47 AM on August 10, 2018:

    Accidental removal of this scope?


    sipa commented at 10:57 PM on August 10, 2018:

    No, not accidental. Just wrong.

  4. in src/validation.cpp:1008 in 41592d5259 outdated
    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;
    


    domob1812 commented at 6:16 AM on August 10, 2018:

    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?


    sipa commented at 10:57 PM on August 10, 2018:

    Oops, no, fixing.

  5. domob1812 commented at 6:16 AM on August 10, 2018: contributor

    Nice to see this go, thanks for the clean up!

  6. sipa force-pushed on Aug 10, 2018
  7. achow101 commented at 1:06 AM on August 11, 2018: member

    Some tests appear to rely on getrawtransaction working for confirmed transactions that still have unspent outputs which is causing travis to fail.

  8. MarcoFalke commented at 3:46 PM on August 12, 2018: member

    Would the removal need to go through an "-deprecatedrpc" cycle?

    Or: How do you know no one is using this?

  9. sipa commented at 3:48 PM on August 12, 2018: member

    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?

  10. Drop support for getrawtransaction for confirmed tx without txindex 5e155e69e2
  11. sipa force-pushed on Aug 12, 2018
  12. kallewoof commented at 6:26 AM on August 13, 2018: member

    utACK 5e155e69e2fe4eae832874868e9e82577d07e495

  13. laanwj added the label RPC/REST/ZMQ on Aug 27, 2018
  14. instagibbs commented at 10:47 PM on September 5, 2018: member

    The PR description/commit message seems misleading. The "search by block hash" option is still supported, as it should be.

  15. jb55 commented at 6:51 AM on September 6, 2018: member

    utACK 5e155e69e2fe4eae832874868e9e82577d07e495

  16. achow101 commented at 1:25 PM on September 6, 2018: member

    utACK 5e155e69e2fe4eae832874868e9e82577d07e495

  17. instagibbs commented at 1:31 PM on September 6, 2018: member
  18. Sjors commented at 7:23 PM on September 7, 2018: member

    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"

  19. instagibbs commented at 8:35 PM on September 7, 2018: member

    for future PR maybe: note in the help that gettxout can suffice for most needs as a replacement?

  20. in test/functional/feature_segwit.py:45 in 5e155e69e2
      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"],
    


    jnewbery commented at 8:55 PM on September 7, 2018:

    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.


    amitiuttarwar commented at 6:19 AM on January 13, 2019:

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

    1. with blockhash -> search specific block for txn
    2. without blockhash, txindex not enabled -> check mempool
    3. without blockhash, txindex enabled -> check all the things

    the use case removed by this PR is

    • without blockhash, txindex not enabled -> check unspent UTXOs

    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?


    jnewbery commented at 2:53 PM on January 13, 2019:

    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.


    amitiuttarwar commented at 4:04 AM on January 24, 2019:

    ~check all the things~ -> check mempool and tx index.

    is there somewhere a transaction could be other than the mempool or tx index?


    jnewbery commented at 2:34 PM on January 24, 2019:

    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)


    amitiuttarwar commented at 12:57 AM on January 27, 2019:

    ok kewl. just confirming that the only qualm was with the imprecision of language :) thanks!

  21. in src/rpc/rawtransaction.cpp:77 in 5e155e69e2
      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"
    


    jnewbery commented at 8:59 PM on September 7, 2018:

    I think this comment could be clearer now that the logic is more straigtforward. Something like:

    • When called with a blockhash argument, getrawtransaction will return the transaction if the specified block is available and the transaction is found in that block.
    • When called without a blockhash argument, getrawtransaction will return the transaction if it is in the mempool, or if -txindex is enabled and the transaction is in a block in the blockchain.

    Sjors commented at 9:23 AM on September 8, 2018:

    I'd start without blockhash argument (mempool only), then blockhash, then say blockhash can be omitted if txindex.


    jnewbery commented at 1:52 PM on September 10, 2018:

    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.

  22. in src/rpc/rawtransaction.cpp:211 in 5e155e69e2
     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"
    


    jnewbery commented at 8:59 PM on September 7, 2018:

    -txindex is a command line option, not a command :)

  23. in src/rpc/rawtransaction.cpp:209 in 5e155e69e2
     207 | @@ -209,10 +208,8 @@ static UniValue gettxoutproof(const JSONRPCRequest& request)
     208 |          throw std::runtime_error(
     209 |              "gettxoutproof [\"txid\",...] ( blockhash )\n"
    


    jnewbery commented at 9:20 PM on September 7, 2018:

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


    jnewbery commented at 10:13 PM on September 7, 2018:

    Sjors commented at 1:08 PM on September 8, 2018:

    That "blockhash must be provided" message is a very useful addition to gettxoutproof (I just got confused by it on another branch).

  24. jnewbery commented at 9:21 PM on September 7, 2018: member

    Concept ACK

  25. DrahtBot commented at 11:33 AM on September 13, 2018: member

    <!--cf906140f33d8803c4a75a2196329ecb-->Needs rebase

  26. DrahtBot added the label Needs rebase on Sep 13, 2018
  27. DrahtBot added the label Up for grabs on Dec 12, 2018
  28. DrahtBot commented at 7:23 PM on December 12, 2018: member

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

  29. DrahtBot closed this on Dec 12, 2018

  30. laanwj removed the label Needs rebase on Oct 24, 2019
  31. MarcoFalke removed the label Up for grabs on Mar 23, 2020
  32. DrahtBot locked this on Feb 15, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-13 15:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me