RPC: Also serve txo from gettxout (not just utxo and mempool) #10822

pull jtimon wants to merge 1 commits into bitcoin:master from jtimon:b15-rpc-txo changing 5 files +82 −14
  1. jtimon commented at 7:59 am on July 14, 2017: contributor

    Expand gettxout to also serve spent txo if pruning or lack of -txindex don’t get in the way.

    If the output is spent, it will be slower to load, but there’s no reason not to serve this if the data is there.

    TODO (functional tests):

    • Test success (ideally more than one example)
    • Test error no txid
    • Test error no n for this txid
    • Test spent/unspent
    • Test txindex error
    • Test prunning error
  2. jtimon renamed this:
    TOTEST: Also server txo from gettxout (not just utxo and mempool)
    TOTEST: Also serve txo from gettxout (not just utxo and mempool)
    on Jul 14, 2017
  3. jtimon force-pushed on Jul 14, 2017
  4. fanquake added the label RPC/REST/ZMQ on Jul 15, 2017
  5. jtimon force-pushed on Jul 16, 2017
  6. jtimon force-pushed on Jul 16, 2017
  7. RPC: Also serve txo from gettxout (not just utxo and mempool) efb8b71c3b
  8. jtimon force-pushed on Jul 16, 2017
  9. jtimon renamed this:
    TOTEST: Also serve txo from gettxout (not just utxo and mempool)
    RPC: Also serve txo from gettxout (not just utxo and mempool)
    on Jul 16, 2017
  10. sipa commented at 7:25 pm on July 16, 2017: member
    I don’t think we should be expanding the impact of -txindex. This functionality is already available through getrawtransaction anyway.
  11. jtimon commented at 5:58 am on July 17, 2017: contributor

    I don’t think we should be expanding the impact of -txindex.

    Is there a problem with that? This is just RPC anyway. I also think making -txindex more useful may increase the incentives to run an archive full node.

    My reasoning (with some errors corrected below it) is here: #9806 (comment)

    This functionality is already available through getrawtransaction anyway.

    By that logic, shouldn’t we just fully remove gettxout? That would be bad for gettxoutbyscript and gettxoutbyaddress though, I think.

    gettxout is faster for utxo, so if one wants a txo (not knowing if stxo/utxo a priori), one could call gettxout first and only if it fails call getrawtransation. But I think a single call would be more convenient. If not, I guess we need getoutpointfromscript and getoupointfrom address call too to serve the full txo. One could, for example, call gettxoutbyaddress and if it fails, also call gettxoutbyaddress and getrawtransaction. It would be more cumbersome, but it would also work.

  12. in src/rpc/blockchain.cpp:1020 in efb8b71c3b
    1015@@ -987,6 +1016,12 @@ UniValue gettxout(const JSONRPCRequest& request)
    1016     if (request.params.size() > 2)
    1017         fMempool = request.params[2].get_bool();
    1018 
    1019+    bool include_spent = false;
    1020+    if (request.params.size() > 3) {
    


    promag commented at 10:49 pm on August 21, 2017:
    0if (!request.params[3].isNull()) {
    
  13. in src/rpc/blockchain.cpp:1051 in efb8b71c3b
    1047@@ -1013,6 +1048,7 @@ UniValue gettxout(const JSONRPCRequest& request)
    1048     ScriptPubKeyToUniv(coin.out.scriptPubKey, o, true);
    1049     ret.push_back(Pair("scriptPubKey", o));
    1050     ret.push_back(Pair("coinbase", (bool)coin.fCoinBase));
    1051+    ret.push_back(Pair("spent", (bool)is_spent));
    


    promag commented at 10:49 pm on August 21, 2017:
    Remove the cast?
  14. in src/rpc/blockchain.cpp:49 in efb8b71c3b
    45@@ -46,6 +46,33 @@ static CUpdatedBlock latestblock;
    46 
    47 extern void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry);
    48 
    49+static bool ReadTxoFromOutpoint(Coin& coin, bool& is_spent, const CBlockIndex* pindex, const COutPoint& out, bool include_spent)
    


    promag commented at 10:53 pm on August 21, 2017:
    pindex not used.
  15. in src/rpc/blockchain.cpp:977 in efb8b71c3b
    977-            "2. n              (numeric, required) vout number\n"
    978-            "3. include_mempool  (boolean, optional) Whether to include the mempool\n"
    979+            "1. \"txid\"             (string, required) The transaction id\n"
    980+            "2. \"n\"                (numeric, required) vout number\n"
    981+            "3. \"include_mempool\"  (boolean, optional) Only search in the mempool. Default: true\n"
    982+            "4. \"include_spent\"    (boolean, optional) Whether to include spent outputs. Default: false\n"
    


    promag commented at 10:58 pm on August 21, 2017:
    ATM only works if include_mempool is false.
  16. in src/rpc/blockchain.cpp:1024 in efb8b71c3b
    1015@@ -987,6 +1016,12 @@ UniValue gettxout(const JSONRPCRequest& request)
    1016     if (request.params.size() > 2)
    1017         fMempool = request.params[2].get_bool();
    1018 
    1019+    bool include_spent = false;
    1020+    if (request.params.size() > 3) {
    1021+        include_spent = request.params[3].get_bool();
    1022+    }
    1023+
    1024+    bool is_spent = false;
    


    promag commented at 10:59 pm on August 21, 2017:
    An output of a mempool transaction can be spent, right?
  17. in src/validation.cpp:960 in efb8b71c3b
    955+bool GetTransaction(const uint256 &hash, CTransactionRef &txOut, const Consensus::Params& consensusParams, uint256 &hashBlock, bool fAllowSlow)
    956+{
    957+    LOCK(cs_main);
    958+
    959+    CTransactionRef ptx = mempool.get(hash);
    960+    if (ptx)
    


    promag commented at 11:00 pm on August 21, 2017:
    0if (ptx) {
    
  18. in test/functional/wallet.py:22 in efb8b71c3b
    18@@ -19,6 +19,7 @@ def __init__(self):
    19         self.setup_clean_chain = True
    20         self.num_nodes = 4
    21         self.extra_args = [['-usehd={:d}'.format(i%2==0)] for i in range(4)]
    22+        self.extra_args[0].append('-txindex')
    


    promag commented at 11:05 pm on August 21, 2017:
    @jnewbery this is why I prefer isolated tests. This is unrelated to all these tests except the new.
  19. in src/rpc/blockchain.cpp:1022 in efb8b71c3b
    1015@@ -987,6 +1016,12 @@ UniValue gettxout(const JSONRPCRequest& request)
    1016     if (request.params.size() > 2)
    1017         fMempool = request.params[2].get_bool();
    1018 
    1019+    bool include_spent = false;
    1020+    if (request.params.size() > 3) {
    1021+        include_spent = request.params[3].get_bool();
    1022+    }
    


    promag commented at 11:09 pm on August 21, 2017:

    Disallow include_spent if include_mempool:

    0    if (fMempool && include_spent) {
    1        throw JSONRPCError(RPC_INVALID_PARAMETER, "...");
    2    }
    

    If you add this, update test below.

  20. in src/validation.cpp:955 in efb8b71c3b
    947@@ -955,6 +948,23 @@ bool GetTransaction(const uint256 &hash, CTransactionRef &txOut, const Consensus
    948     return false;
    949 }
    950 
    951+/**
    952+ * Return transaction in txOut, and if it was found inside a block,
    953+ * its hash is placed in hashBlock. Look in the mempool first.
    954+*/
    955+bool GetTransaction(const uint256 &hash, CTransactionRef &txOut, const Consensus::Params& consensusParams, uint256 &hashBlock, bool fAllowSlow)
    


    promag commented at 11:10 pm on August 21, 2017:
    snake_case.
  21. MarcoFalke referenced this in commit 91e49c51f1 on Aug 28, 2017
  22. jtimon commented at 0:05 am on September 6, 2017: contributor

    Needs rebase and has nits but since I didn’t heard any enthusiasm for more functionality regarding -txindex and @sipa was negative about it, I am closing this for now. @promag thanks for the review and your nits will be taken into account if I ever reopen this.

    EDIT: Happy to reopen if people want it (perhaps after/if there’s an index for scriptPubKey -> txid:n )

  23. jtimon closed this on Sep 6, 2017

  24. mempko referenced this in commit 7837a78256 on Sep 28, 2017
  25. PastaPastaPasta referenced this in commit 535d1985d8 on Sep 19, 2019
  26. PastaPastaPasta referenced this in commit 1e0a196127 on Sep 23, 2019
  27. PastaPastaPasta referenced this in commit bfbafdf29f on Sep 24, 2019
  28. codablock referenced this in commit 74325db11a on Sep 24, 2019
  29. charlesrocket referenced this in commit bb608d6c8b on Dec 14, 2019
  30. barrystyle referenced this in commit b5221c6846 on Jan 22, 2020
  31. DrahtBot locked this on Sep 8, 2021

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: 2024-12-19 00:12 UTC

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