| 1411 | } // namespace |
| 1412 | |
| 1413 | MempoolAcceptResult AcceptToMemoryPool(Chainstate &active_chainstate, |
| 1414 | const CTransactionRef &tx, |
| 1415 | int64_t accept_time, bool bypass_limits, |
| 1416 | bool test_accept, |
| 1417 | unsigned int heightOverride) { |
| 1418 | AssertLockHeld(::cs_main); |
| 1419 | assert(active_chainstate.GetMempool() != nullptr); |
| 1420 | CTxMemPool &pool{*active_chainstate.GetMempool()}; |
| 1421 | |
| 1422 | std::vector<COutPoint> coins_to_uncache; |
| 1423 | auto args = MemPoolAccept::ATMPArgs::SingleAccept( |
| 1424 | active_chainstate.m_chainman.GetConfig(), accept_time, bypass_limits, |
| 1425 | coins_to_uncache, test_accept, heightOverride); |
| 1426 | MempoolAcceptResult result = MemPoolAccept(pool, active_chainstate) |
| 1427 | .AcceptSingleTransaction(tx, args); |
| 1428 | if (result.m_result_type != MempoolAcceptResult::ResultType::VALID) { |
| 1429 | // Remove coins that were not present in the coins cache before calling |
| 1430 | // ATMPW; this is to prevent memory DoS in case we receive a large |
| 1431 | // number of invalid transactions that attempt to overrun the in-memory |
| 1432 | // coins cache |
| 1433 | // (`CCoinsViewCache::cacheCoins`). |
| 1434 | |
| 1435 | for (const COutPoint &outpoint : coins_to_uncache) { |
| 1436 | active_chainstate.CoinsTip().Uncache(outpoint); |
| 1437 | } |
| 1438 | } |
| 1439 | |
| 1440 | // After we've (potentially) uncached entries, ensure our coins cache is |
| 1441 | // still within its size limits |
| 1442 | BlockValidationState stateDummy; |
| 1443 | active_chainstate.FlushStateToDisk(stateDummy, FlushStateMode::PERIODIC); |
| 1444 | return result; |
| 1445 | } |
| 1446 | |
| 1447 | PackageMempoolAcceptResult ProcessNewPackage(Chainstate &active_chainstate, |
| 1448 | CTxMemPool &pool, |
no test coverage detected