diff --git a/src/rest.cpp b/src/rest.cpp --- a/src/rest.cpp +++ b/src/rest.cpp @@ -366,7 +366,7 @@ CTransactionRef tx; uint256 hashBlock = uint256(); - if (!GetTransaction(config, hash, tx, hashBlock, true)) { + if (!GetTransaction(config, hash, tx, hashBlock)) { return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not found"); } diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -232,7 +232,7 @@ CTransactionRef tx; uint256 hashBlock; - if (!GetTransaction(config, hash, tx, hashBlock, true)) { + if (!GetTransaction(config, hash, tx, hashBlock)) { throw JSONRPCError( RPC_INVALID_ADDRESS_OR_KEY, std::string(fTxIndex ? "No such mempool or blockchain transaction" @@ -261,14 +261,11 @@ "gettxoutproof [\"txid\",...] ( blockhash )\n" "\nReturns a hex-encoded proof that \"txid\" was included in a " "block.\n" - "\nNOTE: By default this function only works sometimes. This is " - "when there is an\n" - "unspent output in the utxo for this transaction. To make it " - "always work,\n" - "you need to maintain a transaction index, using the -txindex " - "command line option or\n" - "specify the block in which the transaction is included manually " - "(by blockhash).\n" + "\nNOTE: This function only works if a transaction index is " + "maintained using the\n" + "-txindex command line option or by specifying the block in " + "which the transaction\n" + "is included manually (by blockhash).\n" "\nArguments:\n" "1. \"txids\" (string) A json array of txids to filter\n" " [\n" @@ -314,17 +311,17 @@ if (!mapBlockIndex.count(hashBlock)) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); pblockindex = mapBlockIndex[hashBlock]; - } else { - const Coin &coin = AccessByTxid(*pcoinsTip, oneTxid); - if (!coin.IsSpent() && coin.GetHeight() > 0 && - int64_t(coin.GetHeight()) <= chainActive.Height()) { - pblockindex = chainActive[coin.GetHeight()]; - } } if (pblockindex == nullptr) { + + if (!fTxIndex) { + throw JSONRPCError(RPC_INVALID_PARAMETER, + "Missing blockhash parameter."); + } + CTransactionRef tx; - if (!GetTransaction(config, oneTxid, tx, hashBlock, false) || + if (!GetTransaction(config, oneTxid, tx, hashBlock) || hashBlock.IsNull()) { throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction not yet in block"); diff --git a/src/validation.h b/src/validation.h --- a/src/validation.h +++ b/src/validation.h @@ -316,8 +316,7 @@ std::string GetWarnings(const std::string &strFor); /** Retrieve a transaction (from memory pool, or from disk, if possible) */ bool GetTransaction(const Config &config, const uint256 &hash, - CTransactionRef &tx, uint256 &hashBlock, - bool fAllowSlow = false); + CTransactionRef &tx, uint256 &hashBlock); /** Find the best known block, and make it the tip of the block chain */ bool ActivateBestChain( const Config &config, CValidationState &state, diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -1034,9 +1034,7 @@ /** Return transaction in txOut, and if it was found inside a block, its hash is * placed in hashBlock */ bool GetTransaction(const Config &config, const uint256 &txid, - CTransactionRef &txOut, uint256 &hashBlock, - bool fAllowSlow) { - CBlockIndex *pindexSlow = nullptr; + CTransactionRef &txOut, uint256 &hashBlock) { LOCK(cs_main); @@ -1069,29 +1067,6 @@ } } - // use coin database to locate block that contains transaction, and scan it - if (fAllowSlow) { - const Coin &coin = AccessByTxid(*pcoinsTip, txid); - if (!coin.IsSpent()) { - pindexSlow = chainActive[coin.GetHeight()]; - } - } - - if (pindexSlow) { - auto ¶ms = config.GetChainParams().GetConsensus(); - - CBlock block; - if (ReadBlockFromDisk(block, pindexSlow, params)) { - for (const auto &tx : block.vtx) { - if (tx->GetId() == txid) { - txOut = tx; - hashBlock = pindexSlow->GetBlockHash(); - return true; - } - } - } - } - return false; }