Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RPC: Improve error messages on RPC endpoints that use GetTransaction #13144

Closed
wants to merge 5 commits into from

Conversation

jimpo
Copy link
Contributor

@jimpo jimpo commented May 1, 2018

This contains some follow up items from #13033.

The PR refactors the GetTransaction function and moves it from validation to rpc/rawtransaction. This breaks a cyclic dependency between validation and index/txindex pointed out by @sipa. Also, the REST transaction API and gettxoutproof RPC now have more clear error messages when the txindex is not available, as requested by @TheBlueMatt.

This would also be a good opportunity to drop the slow tx lookup through the unspent coins view if people are for it, as proposed in #3220.

@@ -176,6 +176,28 @@ def run_test(self):
self.nodes[0].reconsiderblock(block1)
assert_equal(self.nodes[0].getbestblockhash(), block2)

# Create new transaction and don't broadcast.
to_address = self.nodes[0].getnewaddress()
prevout_index = [i for i, out in enumerate(gottx['vout']) if out['value'] == 1][0]
Copy link
Member

Choose a reason for hiding this comment

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

F841 local variable 'prevout_index' is assigned to but never used

@fanquake
Copy link
Member

fanquake commented May 2, 2018

Same error on two of the linux builds:

2018-05-02T00:14:12.349000Z TestFramework (INFO): sendrawtransaction with missing input
2018-05-02T00:14:13.011000Z TestFramework (ERROR): JSONRPC error
Traceback (most recent call last):
  File "/home/travis/build/bitcoin/bitcoin/build/bitcoin-i686-pc-linux-gnu/test/functional/test_framework/test_framework.py", line 154, in main
    self.run_test()
  File "/home/travis/build/bitcoin/bitcoin/build/bitcoin-i686-pc-linux-gnu/test/functional/rpc_rawtransaction.py", line 195, in run_test
    self.nodes[0].sendrawtransaction(spending_tx)
  File "/home/travis/build/bitcoin/bitcoin/build/bitcoin-i686-pc-linux-gnu/test/functional/test_framework/coverage.py", line 47, in __call__
    return_val = self.auth_service_proxy_instance.__call__(*args, **kwargs)
  File "/home/travis/build/bitcoin/bitcoin/build/bitcoin-i686-pc-linux-gnu/test/functional/test_framework/authproxy.py", line 138, in __call__
    raise JSONRPCException(response['error'])
test_framework.authproxy.JSONRPCException: absurdly-high-fee, 4800006160 > 10000000 (code 256) (-26)
2018-05-02T00:14:13.012000Z TestFramework (INFO): Stopping nodes

@jimpo jimpo force-pushed the gettransaction-refactor branch from c060157 to 0453681 Compare May 2, 2018 02:59
if (blockindex) {
if (GetTransactionInBlock(hash, blockindex, tx)) {
hash_block = blockindex->GetBlockHash();
} else if (!(blockindex->nStatus & BLOCK_HAVE_DATA)) {
Copy link
Member

Choose a reason for hiding this comment

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

nStatus requires cs_main lock?

Copy link
Member

@promag promag left a comment

Choose a reason for hiding this comment

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

Some comments.

spending_tx = self.nodes[1].signrawtransactionwithwallet(spending_rawtx)['hex']
spending_txid = bytes_to_hex_str(hash256(hex_str_to_bytes(spending_tx)))

# Searching unknown transaction with out txindex.
Copy link
Member

Choose a reason for hiding this comment

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

... without -txindex.?

assert_raises_rpc_error(-5, "No such mempool or blockchain transaction.", self.nodes[2].getrawtransaction, spending_txid)

# Broadcast transaction to mempool.
self.nodes[0].sendrawtransaction(spending_tx)
Copy link
Member

Choose a reason for hiding this comment

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

IMO this could be removed (lines 193 to 200), does't test error messages.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The purpose of the assertion on line 199 is to test that the error received on 192 goes away after transaction is in the mempool.

Copy link
Member

Choose a reason for hiding this comment

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

Right, a comment there would be nice then, like:

# No error should be raised now that the transaction is known.

@@ -36,7 +36,8 @@

#include <univalue.h>

bool GetTransaction(const uint256& tx_hash, CTransactionRef& tx, uint256& block_hash, bool allow_slow)
bool GetTransaction(const uint256& tx_hash, CTransactionRef& tx, uint256& block_hash,
Copy link
Member

Choose a reason for hiding this comment

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

nit, could put allow_slow after tx_hash.

@@ -57,6 +57,7 @@ enum RPCErrorCode
RPC_VERIFY_ALREADY_IN_CHAIN = -27, //!< Transaction already in chain
RPC_IN_WARMUP = -28, //!< Client still warming up
RPC_METHOD_DEPRECATED = -32, //!< RPC method is deprecated
RPC_DATA_UNAVAILABLE = -33, //!< Requested data is unavailable due to application configuration or status
Copy link
Member

Choose a reason for hiding this comment

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

nit s/status/state.

@DrahtBot
Copy link
Contributor

Needs rebase

@DrahtBot
Copy link
Contributor

DrahtBot commented Jul 7, 2018

Needs rebase

@jb55
Copy link
Contributor

jb55 commented Jul 15, 2018

Concept ACK, checked and it rebases cleanly

Jim Posen added 5 commits July 16, 2018 09:27
The error messages now indicate the status of the txindex.
This breaks a circular dependency between validation and txindex.
Break out GetTransactionInBlock into a separate method.
Since both the REST and RPC APIs use GetTransaction, there is no need
to duplicate the error handling logic.
@DrahtBot
Copy link
Contributor

Needs rebase

@DrahtBot
Copy link
Contributor

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.

@DrahtBot DrahtBot closed this Oct 28, 2018
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
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.

None yet

6 participants