Page MenuHomePhabricator

D12208.diff
No OneTemporary

D12208.diff

diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp
--- a/src/rpc/rawtransaction.cpp
+++ b/src/rpc/rawtransaction.cpp
@@ -78,17 +78,15 @@
static RPCHelpMan getrawtransaction() {
return RPCHelpMan{
"getrawtransaction",
- "By default this function only works for mempool transactions. When "
- "called with a blockhash\n"
- "argument, getrawtransaction will return the transaction if the "
- "specified block is available and\n"
- "the transaction is found in that block. When called without a "
- "blockhash argument, getrawtransaction\n"
- "will return the transaction if it is in the mempool, or if -txindex "
- "is enabled and the transaction\n"
- "is in a block in the blockchain.\n"
-
"\nReturn the raw transaction data.\n"
+ "\nBy default, this call only returns a transaction if it is in the "
+ "mempool. If -txindex is enabled\n"
+ "and no blockhash argument is passed, it will return the transaction "
+ "if it is in the mempool or any block.\n"
+ "If -txindex is not enabled and a blockhash argument is passed, it "
+ "will return the transaction if\n"
+ "the specified block is available and the transaction is found in that "
+ "block.\n"
"\nIf verbose is 'true', returns an Object with information about "
"'txid'.\n"
"If verbose is 'false' or omitted, returns a string that is "
diff --git a/src/validation.h b/src/validation.h
--- a/src/validation.h
+++ b/src/validation.h
@@ -223,18 +223,19 @@
void StopScriptCheckWorkerThreads();
/**
- * Return transaction from the block at block_index.
- * If block_index is not provided, fall back to mempool.
- * If mempool is not provided or the tx couldn't be found in mempool, fall back
- * to g_txindex.
+ * Return transaction with a given txid.
+ * If mempool is provided and block_index is not provided, check it first for
+ * the tx.
+ * If -txindex is available, check it next for the tx.
+ * Finally, if block_index is provided, check for tx by reading entire block
+ * from disk.
*
* @param[in] block_index The block to read from disk, or nullptr
- * @param[in] mempool If block_index is not provided, look in the
- * mempool, if provided
+ * @param[in] mempool If provided, check mempool for tx
* @param[in] txid The txid
* @param[in] consensusParams The params
- * @param[out] hashBlock The hash of block_index, if the tx was found via
- * block_index
+ * @param[out] hashBlock The block hash, if the tx was found via -txindex
+ * or block_index
* @returns The tx if found, otherwise nullptr
*/
CTransactionRef GetTransaction(const CBlockIndex *const block_index,
diff --git a/src/validation.cpp b/src/validation.cpp
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -875,6 +875,22 @@
BlockHash &hashBlock) {
LOCK(cs_main);
+ if (mempool && !block_index) {
+ CTransactionRef ptx = mempool->get(txid);
+ if (ptx) {
+ return ptx;
+ }
+ }
+ if (g_txindex) {
+ CTransactionRef tx;
+ BlockHash block_hash;
+ if (g_txindex->FindTx(txid, block_hash, tx)) {
+ if (!block_index || block_index->GetBlockHash() == block_hash) {
+ hashBlock = block_hash;
+ return tx;
+ }
+ }
+ }
if (block_index) {
CBlock block;
if (ReadBlockFromDisk(block, block_index, consensusParams)) {
@@ -885,19 +901,6 @@
}
}
}
- return nullptr;
- }
- if (mempool) {
- CTransactionRef ptx = mempool->get(txid);
- if (ptx) {
- return ptx;
- }
- }
- if (g_txindex) {
- CTransactionRef tx;
- if (g_txindex->FindTx(txid, hashBlock, tx)) {
- return tx;
- }
}
return nullptr;
}

File Metadata

Mime Type
text/plain
Expires
Sat, Apr 26, 10:10 (34 s ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5573203
Default Alt Text
D12208.diff (3 KB)

Event Timeline