Skip to content

Commit 5a83f55

Browse files
committed
[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.
1 parent e3b2e63 commit 5a83f55

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

src/node/mini_miner.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,48 @@ MiniMiner::MiniMiner(const CTxMemPool& mempool, const std::vector<COutPoint>& ou
132132
SanityCheck();
133133
}
134134

135+
MiniMiner::MiniMiner(const std::vector<MiniMinerMempoolEntry>& manual_entries,
136+
const std::map<Txid, std::set<Txid>>& descendant_caches)
137+
{
138+
for (const auto& entry : manual_entries) {
139+
const auto& txid = entry.GetTx().GetHash();
140+
// We need to know the descendant set of every transaction.
141+
if (!Assume(descendant_caches.count(txid) > 0)) {
142+
m_ready_to_calculate = false;
143+
return;
144+
}
145+
// Just forward these args onto MiniMinerMempoolEntry
146+
auto [mapiter, success] = m_entries_by_txid.emplace(txid, entry);
147+
// Txids must be unique; this txid shouldn't already be an entry in m_entries_by_txid
148+
if (Assume(success)) m_entries.push_back(mapiter);
149+
}
150+
// Descendant cache is already built, but we need to translate them to m_entries_by_txid iters.
151+
for (const auto& [txid, desc_txids] : descendant_caches) {
152+
// Descendant cache should include at least the tx itself.
153+
if (!Assume(!desc_txids.empty())) {
154+
m_ready_to_calculate = false;
155+
return;
156+
}
157+
std::vector<MockEntryMap::iterator> cached_descendants;
158+
for (const auto& desc_txid : desc_txids) {
159+
auto desc_it{m_entries_by_txid.find(desc_txid)};
160+
// Descendants should only include transactions with corresponding entries.
161+
if (!Assume(desc_it != m_entries_by_txid.end())) {
162+
m_ready_to_calculate = false;
163+
return;
164+
} else {
165+
cached_descendants.emplace_back(desc_it);
166+
}
167+
}
168+
m_descendant_set_by_txid.emplace(txid, cached_descendants);
169+
}
170+
Assume(m_to_be_replaced.empty());
171+
Assume(m_requested_outpoints_by_txid.empty());
172+
Assume(m_bump_fees.empty());
173+
SanityCheck();
174+
}
175+
176+
135177
// Compare by min(ancestor feerate, individual feerate), then iterator
136178
//
137179
// Under the ancestor-based mining approach, high-feerate children can pay for parents, but high-feerate

src/node/mini_miner.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,25 @@ class MiniMiner
120120
/** Returns set of txids in the block template if one has been constructed. */
121121
std::set<uint256> GetMockTemplateTxids() const { return m_in_block; }
122122

123+
/** Constructor that takes a list of outpoints that may or may not belong to transactions in the
124+
* mempool. Copies out information about the relevant transactions in the mempool into
125+
* MiniMinerMempoolEntrys.
126+
*/
123127
MiniMiner(const CTxMemPool& mempool, const std::vector<COutPoint>& outpoints);
124128

129+
/** Constructor in which the MiniMinerMempoolEntry entries have been constructed manually,
130+
* presumably because these transactions are not in the mempool (yet). It is assumed that all
131+
* entries are unique and their values are correct, otherwise results computed by MiniMiner may
132+
* be incorrect. Callers should check IsReadyToCalculate() after construction.
133+
* @param[in] descendant_caches A map from each transaction to the set of txids of this
134+
* transaction's descendant set, including itself. Each tx in
135+
* manual_entries must have a corresponding entry in this map, and
136+
* all of the txids in a descendant set must correspond to a tx in
137+
* manual_entries.
138+
*/
139+
MiniMiner(const std::vector<MiniMinerMempoolEntry>& manual_entries,
140+
const std::map<Txid, std::set<Txid>>& descendant_caches);
141+
125142
/** Construct a new block template and, for each outpoint corresponding to a transaction that
126143
* did not make it into the block, calculate the cost of bumping those transactions (and their
127144
* ancestors) to the minimum feerate. Returns a map from outpoint to bump fee, or an empty map

0 commit comments

Comments
 (0)