| 326 | } |
| 327 | |
| 328 | void CTxMemPool::removeForFinalizedBlock( |
| 329 | const std::unordered_set<TxId, SaltedTxIdHasher> |
| 330 | &confirmedTxIdsInNonFinalizedBlocks) { |
| 331 | AssertLockHeld(cs); |
| 332 | |
| 333 | std::vector<CTxMemPoolEntryRef> finalizedTxsToKeep; |
| 334 | finalizedTxs.forEachLeaf( |
| 335 | [&](const CTxMemPoolEntryRef &entry) NO_THREAD_SAFETY_ANALYSIS { |
| 336 | if (mapTx.count(entry->GetTx().GetId()) > 0 || |
| 337 | confirmedTxIdsInNonFinalizedBlocks.count( |
| 338 | entry->GetTx().GetId()) > 0) { |
| 339 | // The transaction is either in the mempool (not confirmed) or |
| 340 | // confirmed in a non-finalized block (which might be rejeted by |
| 341 | // avalanche), so we keep it in the radix tree. |
| 342 | finalizedTxsToKeep.push_back(entry); |
| 343 | } |
| 344 | |
| 345 | // All the other transactions are either confirmed in the finalized |
| 346 | // block or in one of its ancestors. |
| 347 | return true; |
| 348 | }); |
| 349 | |
| 350 | // Clear the radix tree and add back the transactions that are not confirmed |
| 351 | decltype(finalizedTxs) empty; |
| 352 | std::swap(finalizedTxs, empty); |
| 353 | |
| 354 | m_finalizedTxsFitter.resetBlock(); |
| 355 | for (const auto &entry : finalizedTxsToKeep) { |
| 356 | // We don't need to proceed to all the checks that happen during |
| 357 | // finalization here so we only recompute the size and sigchecks. |
| 358 | if (finalizedTxs.insert(entry)) { |
| 359 | m_finalizedTxsFitter.addTx(entry->GetTxSize(), |
| 360 | entry->GetSigChecks(), entry->GetFee()); |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | nTransactionsUpdated++; |
| 365 | } |
| 366 | |
| 367 | void CTxMemPool::_clear() { |
| 368 | mapTx.clear(); |