| 300 | } |
| 301 | |
| 302 | void Chainstate::MaybeUpdateMempoolForReorg( |
| 303 | DisconnectedBlockTransactions& disconnectpool, |
| 304 | bool fAddToMempool) |
| 305 | { |
| 306 | if (!m_mempool) return; |
| 307 | |
| 308 | AssertLockHeld(cs_main); |
| 309 | AssertLockHeld(m_mempool->cs); |
| 310 | std::vector<Txid> vHashUpdate; |
| 311 | { |
| 312 | // disconnectpool is ordered so that the front is the most recently-confirmed |
| 313 | // transaction (the last tx of the block at the tip) in the disconnected chain. |
| 314 | // Iterate disconnectpool in reverse, so that we add transactions |
| 315 | // back to the mempool starting with the earliest transaction that had |
| 316 | // been previously seen in a block. |
| 317 | const auto queuedTx = disconnectpool.take(); |
| 318 | auto it = queuedTx.rbegin(); |
| 319 | while (it != queuedTx.rend()) { |
| 320 | // ignore validation errors in resurrected transactions |
| 321 | if (!fAddToMempool || (*it)->IsCoinBase() || |
| 322 | AcceptToMemoryPool(*this, *it, GetTime(), |
| 323 | /*bypass_limits=*/true, /*test_accept=*/false).m_result_type != |
| 324 | MempoolAcceptResult::ResultType::VALID) { |
| 325 | // If the transaction doesn't make it in to the mempool, remove any |
| 326 | // transactions that depend on it (which would now be orphans). |
| 327 | m_mempool->removeRecursive(**it, MemPoolRemovalReason::REORG); |
| 328 | } else if (m_mempool->exists((*it)->GetHash())) { |
| 329 | vHashUpdate.push_back((*it)->GetHash()); |
| 330 | } |
| 331 | ++it; |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | // AcceptToMemoryPool/addNewTransaction all assume that new mempool entries have |
| 336 | // no in-mempool children, which is generally not true when adding |
| 337 | // previously-confirmed transactions back to the mempool. |
| 338 | // UpdateTransactionsFromBlock finds descendants of any transactions in |
| 339 | // the disconnectpool that were added back and cleans up the mempool state. |
| 340 | m_mempool->UpdateTransactionsFromBlock(vHashUpdate); |
| 341 | |
| 342 | // Predicate to use for filtering transactions in removeForReorg. |
| 343 | // Checks whether the transaction is still final and, if it spends a coinbase output, mature. |
| 344 | // Also updates valid entries' cached LockPoints if needed. |
| 345 | // If false, the tx is still valid and its lockpoints are updated. |
| 346 | // If true, the tx would be invalid in the next block; remove this entry and all of its descendants. |
| 347 | // Note that TRUC rules are not applied here, so reorgs may cause violations of TRUC inheritance or |
| 348 | // topology restrictions. |
| 349 | const auto filter_final_and_mature = [&](CTxMemPool::txiter it) |
| 350 | EXCLUSIVE_LOCKS_REQUIRED(m_mempool->cs, ::cs_main) { |
| 351 | AssertLockHeld(m_mempool->cs); |
| 352 | AssertLockHeld(::cs_main); |
| 353 | const CTransaction& tx = it->GetTx(); |
| 354 | |
| 355 | // The transaction must be final. |
| 356 | if (!CheckFinalTxAtTip(*Assert(m_chain.Tip()), tx)) return true; |
| 357 | |
| 358 | const LockPoints& lp = it->GetLockPoints(); |
| 359 | // CheckSequenceLocksAtTip checks if the transaction will be final in the next block to be |
nothing calls this directly
no test coverage detected