Browse Source

Merge pull request #6688

131c23d Fix locking in GetTransaction. (Alex Morcos)
0.13
Wladimir J. van der Laan 9 years ago
parent
commit
4939eabb75
No known key found for this signature in database
GPG Key ID: 74810B012346C9A6
  1. 68
      src/main.cpp

68
src/main.cpp

@ -965,47 +965,45 @@ 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);
if (mempool.lookup(hash, txOut))
{ {
LOCK(cs_main); return true;
{ }
if (mempool.lookup(hash, txOut))
{
return true;
}
}
if (fTxIndex) { if (fTxIndex) {
CDiskTxPos postx; CDiskTxPos postx;
if (pblocktree->ReadTxIndex(hash, postx)) { if (pblocktree->ReadTxIndex(hash, postx)) {
CAutoFile file(OpenBlockFile(postx, true), SER_DISK, CLIENT_VERSION); CAutoFile file(OpenBlockFile(postx, true), SER_DISK, CLIENT_VERSION);
if (file.IsNull()) if (file.IsNull())
return error("%s: OpenBlockFile failed", __func__); return error("%s: OpenBlockFile failed", __func__);
CBlockHeader header; CBlockHeader header;
try { try {
file >> header; file >> header;
fseek(file.Get(), postx.nTxOffset, SEEK_CUR); fseek(file.Get(), postx.nTxOffset, SEEK_CUR);
file >> txOut; file >> txOut;
} catch (const std::exception& e) { } catch (const std::exception& e) {
return error("%s: Deserialize or I/O error - %s", __func__, e.what()); return error("%s: Deserialize or I/O error - %s", __func__, e.what());
}
hashBlock = header.GetHash();
if (txOut.GetHash() != hash)
return error("%s: txid mismatch", __func__);
return true;
} }
hashBlock = header.GetHash();
if (txOut.GetHash() != hash)
return error("%s: txid mismatch", __func__);
return true;
} }
}
if (fAllowSlow) { // use coin database to locate block that contains transaction, and scan it if (fAllowSlow) { // use coin database to locate block that contains transaction, and scan it
int nHeight = -1; int nHeight = -1;
{ {
CCoinsViewCache &view = *pcoinsTip; CCoinsViewCache &view = *pcoinsTip;
const CCoins* coins = view.AccessCoins(hash); const CCoins* coins = view.AccessCoins(hash);
if (coins) if (coins)
nHeight = coins->nHeight; nHeight = coins->nHeight;
}
if (nHeight > 0)
pindexSlow = chainActive[nHeight];
} }
if (nHeight > 0)
pindexSlow = chainActive[nHeight];
} }
if (pindexSlow) { if (pindexSlow) {

Loading…
Cancel
Save