From 78f4c8b98eada337346ffb206339c3ebae4ff43b Mon Sep 17 00:00:00 2001 From: Jameson Lopp Date: Thu, 1 Jul 2021 10:17:28 -0400 Subject: prefer to use txindex if available for GetTransaction Fixes #22382 --- src/validation.cpp | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'src/validation.cpp') 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; } -- cgit v1.2.3