RPC: Also serve txo from gettxout (not just utxo and mempool)#10822
RPC: Also serve txo from gettxout (not just utxo and mempool)#10822jtimon wants to merge 1 commit intobitcoin:masterfrom
Conversation
d983ccf to
ffa0def
Compare
|
I don't think we should be expanding the impact of |
Is there a problem with that? This is just RPC anyway. My reasoning (with some errors corrected below it) is here: #9806 (comment)
By that logic, shouldn't we just fully remove gettxout? 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. |
| fMempool = request.params[2].get_bool(); | ||
|
|
||
| bool include_spent = false; | ||
| if (request.params.size() > 3) { |
There was a problem hiding this comment.
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)); |
|
|
||
| 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) |
| "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" |
There was a problem hiding this comment.
ATM only works if include_mempool is false.
| include_spent = request.params[3].get_bool(); | ||
| } | ||
|
|
||
| bool is_spent = false; |
There was a problem hiding this comment.
An output of a mempool transaction can be spent, right?
| LOCK(cs_main); | ||
|
|
||
| CTransactionRef ptx = mempool.get(hash); | ||
| 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') |
There was a problem hiding this comment.
@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(); | ||
| } |
There was a problem hiding this comment.
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) |
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
|
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. EDIT: Happy to reopen if people want it (perhaps after/if there's an index for scriptPubKey -> txid:n ) |
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
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
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
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):