Fix locking in GetTransaction.

GetTransaction needs to lock cs_main until ReadBlockFromDisk completes, the data inside CBlockIndex's can change since pruning.  This lock was held by all calls to GetTransaction except rest_tx.
This commit is contained in:
Alex Morcos 2015-09-17 17:43:34 -04:00 committed by Luke Dashjr
parent 9b9acc27d2
commit 01878c9c3f
1 changed files with 36 additions and 38 deletions

View File

@ -1092,14 +1092,13 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
bool GetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock, bool fAllowSlow) bool GetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock, bool fAllowSlow)
{ {
CBlockIndex *pindexSlow = NULL; CBlockIndex *pindexSlow = NULL;
{
LOCK(cs_main); LOCK(cs_main);
{
if (mempool.lookup(hash, txOut)) if (mempool.lookup(hash, txOut))
{ {
return true; return true;
} }
}
if (fTxIndex) { if (fTxIndex) {
CDiskTxPos postx; CDiskTxPos postx;
@ -1133,7 +1132,6 @@ bool GetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock
if (nHeight > 0) if (nHeight > 0)
pindexSlow = chainActive[nHeight]; pindexSlow = chainActive[nHeight];
} }
}
if (pindexSlow) { if (pindexSlow) {
CBlock block; CBlock block;