prefer to use txindex if available for GetTransaction

Fixes #22382
This commit is contained in:
Jameson Lopp
2021-07-01 10:17:28 -04:00
committed by Jameson Lopp
parent 2749613020
commit 78f4c8b98e
3 changed files with 24 additions and 20 deletions

View File

@@ -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;
}