diff options
author | glozow <gloriajzhao@gmail.com> | 2023-10-31 09:29:59 +0000 |
---|---|---|
committer | glozow <gloriajzhao@gmail.com> | 2023-11-03 10:17:41 +0000 |
commit | 5a83f55c96661a886dd6f5231920b2f730cf6773 (patch) | |
tree | 4ec7928ba9212d3425065eba9642f0d6ddb770b1 /src/node | |
parent | e3b2e630b219ca15fe0b2640ca422712c86ac33d (diff) | |
download | bitcoin-5a83f55c96661a886dd6f5231920b2f730cf6773.tar.xz |
[MiniMiner] allow manual construction with non-mempool txns
This is primarily intended for linearizing a package of transactions
prior to submitting them to mempool. Note that, if this ctor is used,
bump fees will not be calculated because we haven't instructed MiniMiner
which outpoints for which we want bump fees to be calculated.
Diffstat (limited to 'src/node')
-rw-r--r-- | src/node/mini_miner.cpp | 42 | ||||
-rw-r--r-- | src/node/mini_miner.h | 17 |
2 files changed, 59 insertions, 0 deletions
diff --git a/src/node/mini_miner.cpp b/src/node/mini_miner.cpp index 95eac7a243..c7bb4a6a42 100644 --- a/src/node/mini_miner.cpp +++ b/src/node/mini_miner.cpp @@ -132,6 +132,48 @@ MiniMiner::MiniMiner(const CTxMemPool& mempool, const std::vector<COutPoint>& ou SanityCheck(); } +MiniMiner::MiniMiner(const std::vector<MiniMinerMempoolEntry>& manual_entries, + const std::map<Txid, std::set<Txid>>& descendant_caches) +{ + for (const auto& entry : manual_entries) { + const auto& txid = entry.GetTx().GetHash(); + // We need to know the descendant set of every transaction. + if (!Assume(descendant_caches.count(txid) > 0)) { + m_ready_to_calculate = false; + return; + } + // Just forward these args onto MiniMinerMempoolEntry + auto [mapiter, success] = m_entries_by_txid.emplace(txid, entry); + // Txids must be unique; this txid shouldn't already be an entry in m_entries_by_txid + if (Assume(success)) m_entries.push_back(mapiter); + } + // Descendant cache is already built, but we need to translate them to m_entries_by_txid iters. + for (const auto& [txid, desc_txids] : descendant_caches) { + // Descendant cache should include at least the tx itself. + if (!Assume(!desc_txids.empty())) { + m_ready_to_calculate = false; + return; + } + std::vector<MockEntryMap::iterator> cached_descendants; + for (const auto& desc_txid : desc_txids) { + auto desc_it{m_entries_by_txid.find(desc_txid)}; + // Descendants should only include transactions with corresponding entries. + if (!Assume(desc_it != m_entries_by_txid.end())) { + m_ready_to_calculate = false; + return; + } else { + cached_descendants.emplace_back(desc_it); + } + } + m_descendant_set_by_txid.emplace(txid, cached_descendants); + } + Assume(m_to_be_replaced.empty()); + Assume(m_requested_outpoints_by_txid.empty()); + Assume(m_bump_fees.empty()); + SanityCheck(); +} + + // Compare by min(ancestor feerate, individual feerate), then iterator // // Under the ancestor-based mining approach, high-feerate children can pay for parents, but high-feerate diff --git a/src/node/mini_miner.h b/src/node/mini_miner.h index ae26202965..f1713bc868 100644 --- a/src/node/mini_miner.h +++ b/src/node/mini_miner.h @@ -120,8 +120,25 @@ public: /** Returns set of txids in the block template if one has been constructed. */ std::set<uint256> GetMockTemplateTxids() const { return m_in_block; } + /** Constructor that takes a list of outpoints that may or may not belong to transactions in the + * mempool. Copies out information about the relevant transactions in the mempool into + * MiniMinerMempoolEntrys. + */ MiniMiner(const CTxMemPool& mempool, const std::vector<COutPoint>& outpoints); + /** Constructor in which the MiniMinerMempoolEntry entries have been constructed manually, + * presumably because these transactions are not in the mempool (yet). It is assumed that all + * entries are unique and their values are correct, otherwise results computed by MiniMiner may + * be incorrect. Callers should check IsReadyToCalculate() after construction. + * @param[in] descendant_caches A map from each transaction to the set of txids of this + * transaction's descendant set, including itself. Each tx in + * manual_entries must have a corresponding entry in this map, and + * all of the txids in a descendant set must correspond to a tx in + * manual_entries. + */ + MiniMiner(const std::vector<MiniMinerMempoolEntry>& manual_entries, + const std::map<Txid, std::set<Txid>>& descendant_caches); + /** Construct a new block template and, for each outpoint corresponding to a transaction that * did not make it into the block, calculate the cost of bumping those transactions (and their * ancestors) to the minimum feerate. Returns a map from outpoint to bump fee, or an empty map |