MCPcopy Create free account
hub / github.com/Bitcoin-ABC/bitcoin-abc / removeForFinalizedBlock

Method removeForFinalizedBlock

src/txmempool.cpp:328–365  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

326}
327
328void 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
367void CTxMemPool::_clear() {
368 mapTx.clear();

Callers 2

ProcessMessageMethod · 0.80
BOOST_AUTO_TEST_CASEFunction · 0.80

Calls 11

forEachLeafMethod · 0.80
GetTxMethod · 0.80
resetBlockMethod · 0.80
addTxMethod · 0.80
GetTxSizeMethod · 0.80
GetSigChecksMethod · 0.80
countMethod · 0.45
GetIdMethod · 0.45
push_backMethod · 0.45
insertMethod · 0.45
GetFeeMethod · 0.45

Tested by 1

BOOST_AUTO_TEST_CASEFunction · 0.64