message: Uncache input txn in utxo cache if a tx is not accepted to mempool
  >>> backports bitcoin/bitcoin@bde953e2818ecf44727da128c2aa2ec7667cf7e7
diff: @@ -842,8 +842,9 @@ std::string FormatStateMessage(const CValidationState &state)
  state.GetRejectCode());
  }
  -bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState& state, const CTransaction& tx, bool fLimitFree,
  - bool* pfMissingInputs, bool fOverrideMempoolLimit, bool fRejectInsaneFee, bool ignoreFees)
  +bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState &state, const CTransaction &tx, bool fLimitFree,
  + bool* pfMissingInputs, bool fOverrideMempoolLimit, bool fRejectAbsurdFee, bool ignoreFees,
  + std::vector<uint256>& vHashTxnToUncache)
  {
  AssertLockHeld(cs_main);
  if (pfMissingInputs)
  @@ -927,13 +928,19 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState& state, const CTransa
  view.SetBackend(viewMemPool);
  // do we already have it?
  - if (view.HaveCoins(hash))
  + bool fHadTxInCache = pcoinsTip->HaveCoinsInCache(hash);
  + if (view.HaveCoins(hash)) {
  + if (!fHadTxInCache)
  + vHashTxnToUncache.push_back(hash);
  return state.Invalid(false, REJECT_ALREADY_KNOWN, "txn-already-known");
  + }
  // do all inputs exist?
  // Note that this does not check for the presence of actual outputs (see the next check for that),
  // only helps filling in pfMissingInputs (to determine missing vs spent).
  for (const CTxIn& txin : tx.vin) {
  + if (!pcoinsTip->HaveCoinsInCache(txin.prevout.hash))
  + vHashTxnToUncache.push_back(txin.prevout.hash);
  if (!view.HaveCoins(txin.prevout.hash)) {
  if (pfMissingInputs)
  *pfMissingInputs = true;
  @@ -1038,7 +1045,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState& state, const CTransa
  }
  }
  - if (fRejectInsaneFee && nFees > ::minRelayTxFee.GetFee(nSize) * 10000)
  + if (fRejectAbsurdFee && nFees > ::minRelayTxFee.GetFee(nSize) * 10000)
  return state.Invalid(false,
  REJECT_HIGHFEE, "absurdly-high-fee",
  strprintf("%d > %d", nFees, ::minRelayTxFee.GetFee(nSize) * 10000));
  @@ -1112,6 +1119,18 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState& state, const CTransa
  return true;
  }
  +bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransaction &tx, bool fLimitFree,
  + bool* pfMissingInputs, bool fOverrideMempoolLimit, bool fRejectAbsurdFee, bool fIgnoreFees)
  +{
  + std::vector<uint256> vHashTxToUncache;
  + bool res = AcceptToMemoryPoolWorker(pool, state, tx, fLimitFree, pfMissingInputs, fOverrideMempoolLimit, fRejectAbsurdFee, fIgnoreFees, vHashTxToUncache);
  + if (!res) {
  + for (const uint256& hashTx: vHashTxToUncache)
  + pcoinsTip->Uncache(hashTx);
  + }
  + return res;
  +}
  +
  bool AcceptableInputs(CTxMemPool& pool, CValidationState& state, const CTransaction& tx, bool fLimitFree, bool* pfMissingInputs, bool fRejectInsaneFee, bool isDSTX)
  {
  AssertLockHeld(cs_main);
  