@@ -965,47 +965,45 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
965965bool GetTransaction (const uint256 &hash, CTransaction &txOut, uint256 &hashBlock, bool fAllowSlow )
966966{
967967 CBlockIndex *pindexSlow = NULL ;
968+
969+ LOCK (cs_main);
970+
971+ if (mempool.lookup (hash, txOut))
968972 {
969- LOCK (cs_main);
970- {
971- if (mempool.lookup (hash, txOut))
972- {
973- return true ;
974- }
975- }
973+ return true ;
974+ }
976975
977- if (fTxIndex ) {
978- CDiskTxPos postx;
979- if (pblocktree->ReadTxIndex (hash, postx)) {
980- CAutoFile file (OpenBlockFile (postx, true ), SER_DISK, CLIENT_VERSION);
981- if (file.IsNull ())
982- return error (" %s: OpenBlockFile failed" , __func__);
983- CBlockHeader header;
984- try {
985- file >> header;
986- fseek (file.Get (), postx.nTxOffset , SEEK_CUR);
987- file >> txOut;
988- } catch (const std::exception& e) {
989- return error (" %s: Deserialize or I/O error - %s" , __func__, e.what ());
990- }
991- hashBlock = header.GetHash ();
992- if (txOut.GetHash () != hash)
993- return error (" %s: txid mismatch" , __func__);
994- return true ;
976+ if (fTxIndex ) {
977+ CDiskTxPos postx;
978+ if (pblocktree->ReadTxIndex (hash, postx)) {
979+ CAutoFile file (OpenBlockFile (postx, true ), SER_DISK, CLIENT_VERSION);
980+ if (file.IsNull ())
981+ return error (" %s: OpenBlockFile failed" , __func__);
982+ CBlockHeader header;
983+ try {
984+ file >> header;
985+ fseek (file.Get (), postx.nTxOffset , SEEK_CUR);
986+ file >> txOut;
987+ } catch (const std::exception& e) {
988+ return error (" %s: Deserialize or I/O error - %s" , __func__, e.what ());
995989 }
990+ hashBlock = header.GetHash ();
991+ if (txOut.GetHash () != hash)
992+ return error (" %s: txid mismatch" , __func__);
993+ return true ;
996994 }
995+ }
997996
998- if (fAllowSlow ) { // use coin database to locate block that contains transaction, and scan it
999- int nHeight = -1 ;
1000- {
1001- CCoinsViewCache &view = *pcoinsTip;
1002- const CCoins* coins = view.AccessCoins (hash);
1003- if (coins)
1004- nHeight = coins->nHeight ;
1005- }
1006- if (nHeight > 0 )
1007- pindexSlow = chainActive[nHeight];
997+ if (fAllowSlow ) { // use coin database to locate block that contains transaction, and scan it
998+ int nHeight = -1 ;
999+ {
1000+ CCoinsViewCache &view = *pcoinsTip;
1001+ const CCoins* coins = view.AccessCoins (hash);
1002+ if (coins)
1003+ nHeight = coins->nHeight ;
10081004 }
1005+ if (nHeight > 0 )
1006+ pindexSlow = chainActive[nHeight];
10091007 }
10101008
10111009 if (pindexSlow) {
0 commit comments