0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-02 09:46:52 -05:00

[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.
This commit is contained in:
glozow 2023-10-31 09:29:59 +00:00
parent e3b2e630b2
commit 5a83f55c96
2 changed files with 59 additions and 0 deletions

View file

@ -132,6 +132,48 @@ MiniMiner::MiniMiner(const CTxMemPool& mempool, const std::vector<COutPoint>& ou
SanityCheck(); 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 // 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 // Under the ancestor-based mining approach, high-feerate children can pay for parents, but high-feerate

View file

@ -120,8 +120,25 @@ public:
/** Returns set of txids in the block template if one has been constructed. */ /** Returns set of txids in the block template if one has been constructed. */
std::set<uint256> GetMockTemplateTxids() const { return m_in_block; } 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); 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 /** 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 * 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 * ancestors) to the minimum feerate. Returns a map from outpoint to bump fee, or an empty map