aboutsummaryrefslogtreecommitdiff
path: root/src/validation.cpp
diff options
context:
space:
mode:
authorJameson Lopp <jameson@team.casa>2021-07-01 10:17:28 -0400
committerJameson Lopp <jameson.lopp@gmail.com>2021-07-03 07:31:27 -0400
commit78f4c8b98eada337346ffb206339c3ebae4ff43b (patch)
tree5f08795aaacdf50ee7cf7d5481d5f0173fbaab20 /src/validation.cpp
parent2749613020ed96a4e9204f8b98c44524b0a62d0d (diff)
downloadbitcoin-78f4c8b98eada337346ffb206339c3ebae4ff43b.tar.xz
prefer to use txindex if available for GetTransaction
Fixes #22382
Diffstat (limited to 'src/validation.cpp')
-rw-r--r--src/validation.cpp23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/validation.cpp b/src/validation.cpp
index df0ec3bd4f..6a145a088a 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -1159,6 +1159,20 @@ CTransactionRef GetTransaction(const CBlockIndex* const block_index, const CTxMe
{
LOCK(cs_main);
+ if (mempool && !block_index) {
+ CTransactionRef ptx = mempool->get(hash);
+ if (ptx) return ptx;
+ }
+ if (g_txindex) {
+ CTransactionRef tx;
+ uint256 block_hash;
+ if (g_txindex->FindTx(hash, 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)) {
@@ -1169,15 +1183,6 @@ CTransactionRef GetTransaction(const CBlockIndex* const block_index, const CTxMe
}
}
}
- return nullptr;
- }
- if (mempool) {
- CTransactionRef ptx = mempool->get(hash);
- if (ptx) return ptx;
- }
- if (g_txindex) {
- CTransactionRef tx;
- if (g_txindex->FindTx(hash, hashBlock, tx)) return tx;
}
return nullptr;
}