Skip to content

Conversation

@jtimon
Copy link
Contributor

@jtimon jtimon commented Jul 14, 2017

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

@jtimon jtimon changed the title TOTEST: Also server txo from gettxout (not just utxo and mempool) TOTEST: Also serve txo from gettxout (not just utxo and mempool) Jul 14, 2017
@jtimon jtimon force-pushed the b15-rpc-txo branch 2 times, most recently from d983ccf to ffa0def Compare July 16, 2017 09:10
@jtimon jtimon changed the title TOTEST: Also serve txo from gettxout (not just utxo and mempool) RPC: Also serve txo from gettxout (not just utxo and mempool) Jul 16, 2017
@sipa
Copy link
Member

sipa commented Jul 16, 2017

I don't think we should be expanding the impact of -txindex. This functionality is already available through getrawtransaction anyway.

@jtimon
Copy link
Contributor Author

jtimon commented Jul 17, 2017

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.

fMempool = request.params[2].get_bool();

bool include_spent = false;
if (request.params.size() > 3) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (!request.params[3].isNull()) {

ScriptPubKeyToUniv(coin.out.scriptPubKey, o, true);
ret.push_back(Pair("scriptPubKey", o));
ret.push_back(Pair("coinbase", (bool)coin.fCoinBase));
ret.push_back(Pair("spent", (bool)is_spent));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the cast?


extern void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry);

static bool ReadTxoFromOutpoint(Coin& coin, bool& is_spent, const CBlockIndex* pindex, const COutPoint& out, bool include_spent)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pindex not used.

"1. \"txid\" (string, required) The transaction id\n"
"2. \"n\" (numeric, required) vout number\n"
"3. \"include_mempool\" (boolean, optional) Only search in the mempool. Default: true\n"
"4. \"include_spent\" (boolean, optional) Whether to include spent outputs. Default: false\n"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ATM only works if include_mempool is false.

include_spent = request.params[3].get_bool();
}

bool is_spent = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An output of a mempool transaction can be spent, right?

LOCK(cs_main);

CTransactionRef ptx = mempool.get(hash);
if (ptx)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (ptx) {

self.setup_clean_chain = True
self.num_nodes = 4
self.extra_args = [['-usehd={:d}'.format(i%2==0)] for i in range(4)]
self.extra_args[0].append('-txindex')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jnewbery this is why I prefer isolated tests. This is unrelated to all these tests except the new.

bool include_spent = false;
if (request.params.size() > 3) {
include_spent = request.params[3].get_bool();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disallow include_spent if include_mempool:

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

If you add this, update test below.

* Return transaction in txOut, and if it was found inside a block,
* its hash is placed in hashBlock. Look in the mempool first.
*/
bool GetTransaction(const uint256 &hash, CTransactionRef &txOut, const Consensus::Params& consensusParams, uint256 &hashBlock, bool fAllowSlow)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

snake_case.

maflcko pushed a commit that referenced this pull request Aug 28, 2017
6d2d2eb RPC: gettxout: Slightly improve doc and tests (Jorge Timón)

Pull request description:

  Slightly related to #10822 in the sense that I felt the documentation and testing wasn't as good as it could be while writing it.

  Ping @sipa since we discussed this on IRC.

Tree-SHA512: a0b3ffdac65245a0429e772fc2d8bcc1e829b02c70fb2af6ee0b7578cae46683f6c51a824b4d703d4dc3f99b6f03a658d6bbc818bf32981516f24124249a211d
@jtimon
Copy link
Contributor Author

jtimon commented Sep 6, 2017

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 )

@jtimon jtimon closed this Sep 6, 2017
mempko pushed a commit to meritlabs/merit that referenced this pull request Sep 28, 2017
6d2d2eb RPC: gettxout: Slightly improve doc and tests (Jorge Timón)

Pull request description:

  Slightly related to bitcoin/bitcoin#10822 in the sense that I felt the documentation and testing wasn't as good as it could be while writing it.

  Ping @sipa since we discussed this on IRC.

Tree-SHA512: a0b3ffdac65245a0429e772fc2d8bcc1e829b02c70fb2af6ee0b7578cae46683f6c51a824b4d703d4dc3f99b6f03a658d6bbc818bf32981516f24124249a211d
codablock pushed a commit to codablock/dash that referenced this pull request Sep 24, 2019
6d2d2eb RPC: gettxout: Slightly improve doc and tests (Jorge Timón)

Pull request description:

  Slightly related to bitcoin#10822 in the sense that I felt the documentation and testing wasn't as good as it could be while writing it.

  Ping @sipa since we discussed this on IRC.

Tree-SHA512: a0b3ffdac65245a0429e772fc2d8bcc1e829b02c70fb2af6ee0b7578cae46683f6c51a824b4d703d4dc3f99b6f03a658d6bbc818bf32981516f24124249a211d
charlesrocket pushed a commit to AXErunners/axe that referenced this pull request Dec 14, 2019
6d2d2eb49 RPC: gettxout: Slightly improve doc and tests (Jorge Timón)

Pull request description:

  Slightly related to bitcoin/bitcoin#10822 in the sense that I felt the documentation and testing wasn't as good as it could be while writing it.

  Ping @sipa since we discussed this on IRC.

Tree-SHA512: a0b3ffdac65245a0429e772fc2d8bcc1e829b02c70fb2af6ee0b7578cae46683f6c51a824b4d703d4dc3f99b6f03a658d6bbc818bf32981516f24124249a211d
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
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.

4 participants