MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / ChangeSet

Class ChangeSet

src/txmempool.h:618–691  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

616 * mempool.
617 */
618 class ChangeSet {
619 public:
620 explicit ChangeSet(CTxMemPool* pool) : m_pool(pool) { m_pool->m_txgraph->StartStaging(); }
621 ~ChangeSet() EXCLUSIVE_LOCKS_REQUIRED(m_pool->cs) {
622 AssertLockHeld(m_pool->cs);
623 if (m_pool->m_txgraph->HaveStaging()) {
624 m_pool->m_txgraph->AbortStaging();
625 }
626 m_pool->m_have_changeset = false;
627 }
628
629 ChangeSet(const ChangeSet&) = delete;
630 ChangeSet& operator=(const ChangeSet&) = delete;
631
632 using TxHandle = CTxMemPool::txiter;
633
634 TxHandle StageAddition(const CTransactionRef& tx, CAmount fee, int64_t time, unsigned int entry_height, uint64_t entry_sequence, bool spends_coinbase, int64_t sigops_cost, LockPoints lp);
635
636 void StageRemoval(CTxMemPool::txiter it);
637
638 const CTxMemPool::setEntries& GetRemovals() const { return m_to_remove; }
639
640 /** Check if any cluster limits are exceeded. Returns true if pass, false if fail. */
641 bool CheckMemPoolPolicyLimits();
642
643 CTxMemPool::setEntries CalculateMemPoolAncestors(TxHandle tx)
644 {
645 // Look up transaction in our cache first
646 auto it = m_ancestors.find(tx);
647 if (it != m_ancestors.end()) return it->second;
648
649 // If not found, try to have the mempool calculate it, and cache
650 // for later.
651 LOCK(m_pool->cs);
652 auto ret = m_pool->CalculateMemPoolAncestors(*tx);
653 m_ancestors.try_emplace(tx, ret);
654 return ret;
655 }
656
657 std::vector<CTransactionRef> GetAddedTxns() const {
658 std::vector<CTransactionRef> ret;
659 ret.reserve(m_entry_vec.size());
660 for (const auto& entry : m_entry_vec) {
661 ret.emplace_back(entry->GetSharedTx());
662 }
663 return ret;
664 }
665
666 /**
667 * Calculate the sorted chunks for the old and new mempool relating to the
668 * clusters that would be affected by a potential replacement transaction.
669 *
670 * @return old and new diagram pair respectively, or an error string if the conflicts don't match a calculable topology
671 */
672 util::Result<std::pair<std::vector<FeeFrac>, std::vector<FeeFrac>>> CalculateChunksForRBF();
673
674 size_t GetTxCount() const { return m_entry_vec.size(); }
675 const CTransaction& GetAddedTxn(size_t index) const { return m_entry_vec.at(index)->GetTx(); }

Callers

nothing calls this directly

Calls 4

HaveStagingMethod · 0.80
AbortStagingMethod · 0.80
GetTxMethod · 0.80
atMethod · 0.45

Tested by

no test coverage detected