@@ -835,8 +835,9 @@ std::string FormatStateMessage(const CValidationState &state)
835
835
state.GetRejectCode ());
836
836
}
837
837
838
- bool AcceptToMemoryPool (CTxMemPool& pool, CValidationState &state, const CTransaction &tx, bool fLimitFree ,
839
- bool * pfMissingInputs, bool fOverrideMempoolLimit , bool fRejectAbsurdFee )
838
+ bool AcceptToMemoryPoolWorker (CTxMemPool& pool, CValidationState &state, const CTransaction &tx, bool fLimitFree ,
839
+ bool * pfMissingInputs, bool fOverrideMempoolLimit , bool fRejectAbsurdFee ,
840
+ std::vector<uint256>& vHashTxnToUncache)
840
841
{
841
842
AssertLockHeld (cs_main);
842
843
if (pfMissingInputs)
@@ -917,13 +918,19 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
917
918
view.SetBackend (viewMemPool);
918
919
919
920
// do we already have it?
920
- if (view.HaveCoins (hash))
921
+ bool fHadTxInCache = pcoinsTip->HaveCoinsInCache (hash);
922
+ if (view.HaveCoins (hash)) {
923
+ if (!fHadTxInCache )
924
+ vHashTxnToUncache.push_back (hash);
921
925
return state.Invalid (false , REJECT_ALREADY_KNOWN, " txn-already-known" );
926
+ }
922
927
923
928
// do all inputs exist?
924
929
// Note that this does not check for the presence of actual outputs (see the next check for that),
925
930
// and only helps with filling in pfMissingInputs (to determine missing vs spent).
926
931
BOOST_FOREACH (const CTxIn txin, tx.vin ) {
932
+ if (!pcoinsTip->HaveCoinsInCache (txin.prevout .hash ))
933
+ vHashTxnToUncache.push_back (txin.prevout .hash );
927
934
if (!view.HaveCoins (txin.prevout .hash )) {
928
935
if (pfMissingInputs)
929
936
*pfMissingInputs = true ;
@@ -1232,6 +1239,18 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
1232
1239
return true ;
1233
1240
}
1234
1241
1242
+ bool AcceptToMemoryPool (CTxMemPool& pool, CValidationState &state, const CTransaction &tx, bool fLimitFree ,
1243
+ bool * pfMissingInputs, bool fOverrideMempoolLimit , bool fRejectAbsurdFee )
1244
+ {
1245
+ std::vector<uint256> vHashTxToUncache;
1246
+ bool res = AcceptToMemoryPoolWorker (pool, state, tx, fLimitFree , pfMissingInputs, fOverrideMempoolLimit , fRejectAbsurdFee , vHashTxToUncache);
1247
+ if (!res) {
1248
+ BOOST_FOREACH (const uint256& hashTx, vHashTxToUncache)
1249
+ pcoinsTip->Uncache (hashTx);
1250
+ }
1251
+ return res;
1252
+ }
1253
+
1235
1254
/* * Return transaction in tx, and if it was found inside a block, its hash is placed in hashBlock */
1236
1255
bool GetTransaction (const uint256 &hash, CTransaction &txOut, const Consensus::Params& consensusParams, uint256 &hashBlock, bool fAllowSlow )
1237
1256
{
0 commit comments