Skip to content

Commit fe6332c

Browse files
committed
[MiniMiner] make target_feerate optional
Add an option to keep building the template regardless of feerate. We can't just use target_feerate=0 because it's possible for transactions to have negative modified feerates. No behavior change for users that pass in a target_feerate.
1 parent 5a83f55 commit fe6332c

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/node/mini_miner.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ MiniMiner::MiniMiner(const std::vector<MiniMinerMempoolEntry>& manual_entries,
173173
SanityCheck();
174174
}
175175

176-
177176
// Compare by min(ancestor feerate, individual feerate), then iterator
178177
//
179178
// Under the ancestor-based mining approach, high-feerate children can pay for parents, but high-feerate
@@ -253,8 +252,9 @@ void MiniMiner::SanityCheck() const
253252
[&](const auto& txid){return m_entries_by_txid.find(txid) == m_entries_by_txid.end();}));
254253
}
255254

256-
void MiniMiner::BuildMockTemplate(const CFeeRate& target_feerate)
255+
void MiniMiner::BuildMockTemplate(std::optional<CFeeRate> target_feerate)
257256
{
257+
const auto num_txns{m_entries_by_txid.size()};
258258
while (!m_entries_by_txid.empty()) {
259259
// Sort again, since transaction removal may change some m_entries' ancestor feerates.
260260
std::sort(m_entries.begin(), m_entries.end(), AncestorFeerateComparator());
@@ -265,7 +265,8 @@ void MiniMiner::BuildMockTemplate(const CFeeRate& target_feerate)
265265
const auto ancestor_package_size = (*best_iter)->second.GetSizeWithAncestors();
266266
const auto ancestor_package_fee = (*best_iter)->second.GetModFeesWithAncestors();
267267
// Stop here. Everything that didn't "make it into the block" has bumpfee.
268-
if (ancestor_package_fee < target_feerate.GetFee(ancestor_package_size)) {
268+
if (target_feerate.has_value() &&
269+
ancestor_package_fee < target_feerate->GetFee(ancestor_package_size)) {
269270
break;
270271
}
271272

@@ -292,7 +293,11 @@ void MiniMiner::BuildMockTemplate(const CFeeRate& target_feerate)
292293
DeleteAncestorPackage(ancestors);
293294
SanityCheck();
294295
}
295-
Assume(m_in_block.empty() || m_total_fees >= target_feerate.GetFee(m_total_vsize));
296+
if (!target_feerate.has_value()) {
297+
Assume(m_in_block.size() == num_txns);
298+
} else {
299+
Assume(m_in_block.empty() || m_total_fees >= target_feerate->GetFee(m_total_vsize));
300+
}
296301
// Do not try to continue building the block template with a different feerate.
297302
m_ready_to_calculate = false;
298303
}

src/node/mini_miner.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class MiniMiner
8484
// the same tx will have the same bumpfee. Excludes non-mempool transactions.
8585
std::map<uint256, std::vector<COutPoint>> m_requested_outpoints_by_txid;
8686

87-
// What we're trying to calculate.
87+
// What we're trying to calculate. Outpoint to the fee needed to bring the transaction to the target feerate.
8888
std::map<COutPoint, CAmount> m_bump_fees;
8989

9090
// The constructed block template
@@ -114,8 +114,9 @@ class MiniMiner
114114
/** Returns true if CalculateBumpFees may be called, false if not. */
115115
bool IsReadyToCalculate() const { return m_ready_to_calculate; }
116116

117-
/** Build a block template until the target feerate is hit. */
118-
void BuildMockTemplate(const CFeeRate& target_feerate);
117+
/** Build a block template until the target feerate is hit. If target_feerate is not given,
118+
* builds a block template until all transactions have been selected. */
119+
void BuildMockTemplate(std::optional<CFeeRate> target_feerate);
119120

120121
/** Returns set of txids in the block template if one has been constructed. */
121122
std::set<uint256> GetMockTemplateTxids() const { return m_in_block; }
@@ -149,6 +150,7 @@ class MiniMiner
149150
* not make it into the block to the target feerate. Returns the total bump fee, or std::nullopt
150151
* if it cannot be calculated. */
151152
std::optional<CAmount> CalculateTotalBumpFees(const CFeeRate& target_feerate);
153+
152154
};
153155
} // namespace node
154156

0 commit comments

Comments
 (0)