MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / UpdateMempoolForReorg

Function UpdateMempoolForReorg

src/validation.cpp:510–547  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

508 */
509
510static void UpdateMempoolForReorg(DisconnectedBlockTransactions &disconnectpool, bool fAddToMempool)
511{
512 AssertLockHeld(cs_main);
513 std::vector<uint256> vHashUpdate;
514 // disconnectpool's insertion_order index sorts the entries from
515 // oldest to newest, but the oldest entry will be the last tx from the
516 // latest mined block that was disconnected.
517 // Iterate disconnectpool in reverse, so that we add transactions
518 // back to the mempool starting with the earliest transaction that had
519 // been previously seen in a block.
520 auto it = disconnectpool.queuedTx.get<insertion_order>().rbegin();
521 while (it != disconnectpool.queuedTx.get<insertion_order>().rend()) {
522 // ignore validation errors in resurrected transactions
523 CValidationState stateDummy;
524 if (!fAddToMempool || (*it)->IsCoinBase() ||
525 !AcceptToMemoryPool(mempool, stateDummy, *it, nullptr /* pfMissingInputs */,
526 nullptr /* plTxnReplaced */, true /* bypass_limits */, 0 /* nAbsurdFee */)) {
527 // If the transaction doesn't make it in to the mempool, remove any
528 // transactions that depend on it (which would now be orphans).
529 mempool.removeRecursive(**it, MemPoolRemovalReason::REORG);
530 } else if (mempool.exists((*it)->GetHash())) {
531 vHashUpdate.push_back((*it)->GetHash());
532 }
533 ++it;
534 }
535 disconnectpool.queuedTx.clear();
536 // AcceptToMemoryPool/addUnchecked all assume that new mempool entries have
537 // no in-mempool children, which is generally not true when adding
538 // previously-confirmed transactions back to the mempool.
539 // UpdateTransactionsFromBlock finds descendants of any transactions in
540 // the disconnectpool that were added back and cleans up the mempool state.
541 mempool.UpdateTransactionsFromBlock(vHashUpdate);
542
543 // We also need to remove any now-immature transactions
544 mempool.removeForReorg(pcoinsTip.get(), chainActive.Tip()->nHeight + 1, STANDARD_LOCKTIME_VERIFY_FLAGS);
545 // Re-limit mempool size, in case we added any transactions
546 LimitMempoolSize(mempool, gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000, gArgs.GetArg("-mempoolexpiry", DEFAULT_MEMPOOL_EXPIRY) * 60 * 60);
547}
548
549// Used to avoid mempool polluting consensus critical paths if CCoinsViewMempool
550// were somehow broken and returning the wrong scriptPubKeys

Callers 2

ActivateBestChainStepMethod · 0.85
InvalidateBlockMethod · 0.85

Calls 15

AcceptToMemoryPoolFunction · 0.85
LimitMempoolSizeFunction · 0.85
rbeginMethod · 0.80
rendMethod · 0.80
removeRecursiveMethod · 0.80
removeForReorgMethod · 0.80
getMethod · 0.80
IsCoinBaseMethod · 0.45
existsMethod · 0.45
GetHashMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected