| 396 | } |
| 397 | |
| 398 | void CTxMemPool::UpdateForRemoveFromMempool(const setEntries &entriesToRemove, bool updateDescendants) |
| 399 | { |
| 400 | // For each entry, walk back all ancestors and decrement size associated with this |
| 401 | // transaction |
| 402 | const uint64_t nNoLimit = std::numeric_limits<uint64_t>::max(); |
| 403 | if (updateDescendants) { |
| 404 | // updateDescendants should be true whenever we're not recursively |
| 405 | // removing a tx and all its descendants, eg when a transaction is |
| 406 | // confirmed in a block. |
| 407 | // Here we only update statistics and not data in CTxMemPool::Parents |
| 408 | // and CTxMemPoolEntry::Children (which we need to preserve until we're |
| 409 | // finished with all operations that need to traverse the mempool). |
| 410 | for (txiter removeIt : entriesToRemove) { |
| 411 | setEntries setDescendants; |
| 412 | CalculateDescendants(removeIt, setDescendants); |
| 413 | setDescendants.erase(removeIt); // don't update state for self |
| 414 | int64_t modifySize = -((int64_t)removeIt->GetTxSize()); |
| 415 | CAmount modifyFee = -removeIt->GetModifiedFee(); |
| 416 | int modifySigOps = -removeIt->GetSigOpCost(); |
| 417 | int64_t discountSize = -((int64_t)removeIt->GetDiscountTxSize()); |
| 418 | for (txiter dit : setDescendants) { |
| 419 | mapTx.modify(dit, update_ancestor_state(modifySize, modifyFee, -1, modifySigOps, discountSize)); |
| 420 | } |
| 421 | } |
| 422 | } |
| 423 | for (txiter removeIt : entriesToRemove) { |
| 424 | setEntries setAncestors; |
| 425 | const CTxMemPoolEntry &entry = *removeIt; |
| 426 | std::string dummy; |
| 427 | // Since this is a tx that is already in the mempool, we can call CMPA |
| 428 | // with fSearchForParents = false. If the mempool is in a consistent |
| 429 | // state, then using true or false should both be correct, though false |
| 430 | // should be a bit faster. |
| 431 | // However, if we happen to be in the middle of processing a reorg, then |
| 432 | // the mempool can be in an inconsistent state. In this case, the set |
| 433 | // of ancestors reachable via GetMemPoolParents()/GetMemPoolChildren() |
| 434 | // will be the same as the set of ancestors whose packages include this |
| 435 | // transaction, because when we add a new transaction to the mempool in |
| 436 | // addUnchecked(), we assume it has no children, and in the case of a |
| 437 | // reorg where that assumption is false, the in-mempool children aren't |
| 438 | // linked to the in-block tx's until UpdateTransactionsFromBlock() is |
| 439 | // called. |
| 440 | // So if we're being called during a reorg, ie before |
| 441 | // UpdateTransactionsFromBlock() has been called, then |
| 442 | // GetMemPoolParents()/GetMemPoolChildren() will differ from the set of |
| 443 | // mempool parents we'd calculate by searching, and it's important that |
| 444 | // we use the cached notion of ancestor transactions as the set of |
| 445 | // things to update for removal. |
| 446 | CalculateMemPoolAncestors(entry, setAncestors, nNoLimit, nNoLimit, nNoLimit, nNoLimit, dummy, false); |
| 447 | // Note that UpdateAncestorsOf severs the child links that point to |
| 448 | // removeIt in the entries for the parents of removeIt. |
| 449 | UpdateAncestorsOf(false, removeIt, setAncestors); |
| 450 | } |
| 451 | // After updating all the ancestor sizes, we can now sever the link between each |
| 452 | // transaction being removed and any mempool children (ie, update CTxMemPoolEntry::m_parents |
| 453 | // for each direct child of a transaction being removed). |
| 454 | for (txiter removeIt : entriesToRemove) { |
| 455 | UpdateChildrenForRemoval(removeIt); |
nothing calls this directly
no test coverage detected