7#include <boost/multi_index/detail/hash_index_iterator.hpp>
8#include <boost/operators.hpp>
30 for (
const auto& outpoint : outpoints) {
31 if (!mempool.
exists(outpoint.hash)) {
67 if (cluster.empty()) {
75 for (
const auto& txiter : cluster) {
82 txiter->GetModifiedFee(),
99 for (
const auto& txiter : cluster) {
100 const auto& txid = txiter->GetTx().GetHash();
107 Assume(descendants.contains(txiter));
137 const auto& txid = entry.GetTx().GetHash();
155 std::vector<MockEntryMap::iterator> descendants;
163 descendants.emplace_back(
desc_it);
195 return a->first < b->first;
201 Assume(ancestors.size() >= 1);
203 for (
auto&
anc : ancestors) {
214 descendant->second.UpdateAncestorState(-
anc->second.GetTxSize(), -
anc->second.GetModifiedFee());
218 for (
const auto&
anc : ancestors) {
222 Assume(
anc->second.GetModFeesWithAncestors() == 0);
223 Assume(
anc->second.GetSizeWithAncestors() == 0);
238 return entry->second.GetSizeWithAncestors() >= entry->second.GetTxSize();}));
241 [&](
const auto& txid){ return !m_entries_by_txid.contains(txid); }));
265 std::set<MockEntryMap::iterator, IteratorComparator> ancestors;
267 std::set<MockEntryMap::iterator, IteratorComparator>
to_process;
272 ancestors.insert(*iter);
273 for (
const auto& input : (*iter)->second.GetTx().vin) {
284 for (
const auto&
ancestor : ancestors) {
321 for (
const auto& outpoint : it->second) {
376 Assume(
target_feerate.GetFee(it->second.GetSizeWithAncestors()) > std::min(it->second.GetModifiedFee(), it->second.GetModFeesWithAncestors()));
381 for (
const auto& outpoint : outpoints) {
396 std::set<MockEntryMap::iterator, IteratorComparator> ancestors;
397 std::set<MockEntryMap::iterator, IteratorComparator>
to_process;
405 ancestors.insert(iter);
412 for (
const auto& input : tx.
vin) {
424 [](
int64_t sum,
const auto it) {return sum + it->second.GetTxSize();});
426 [](
CAmount sum,
const auto it) {return sum + it->second.GetModifiedFee();});
int64_t CAmount
Amount in satoshis (Can be negative)
#define Assume(val)
Assume is the identity function.
Fee rate in satoshis per virtualbyte: CAmount / vB the feerate is represented internally as FeeFrac.
The basic transaction that is broadcasted on the network and contained in blocks.
const Txid & GetHash() const LIFETIMEBOUND
const std::vector< CTxIn > vin
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
std::optional< txiter > GetIter(const Txid &txid) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Returns an iterator to the given hash, if found.
RecursiveMutex cs
This mutex needs to be locked when accessing mapTx or other members that are guarded by it.
bool exists(const Txid &txid) const
std::set< txiter, CompareIteratorByHash > setEntries
std::vector< txiter > GatherClusters(const std::vector< Txid > &txids) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Collect the entire cluster of connected transactions for each transaction in txids.
const CTransaction * GetConflictTx(const COutPoint &prevout) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Get the transaction in the pool that spends the same prevout.
void CalculateDescendants(txiter it, setEntries &setDescendants) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Populate setDescendants with all in-mempool descendants of given transaction.
std::tuple< size_t, size_t, CAmount > CalculateAncestorData(const CTxMemPoolEntry &entry) const EXCLUSIVE_LOCKS_REQUIRED(cs)
std::set< Txid > m_in_block
std::map< Txid, uint32_t > Linearize()
Construct a new block template with all of the transactions and calculate the order in which they are...
std::map< COutPoint, CAmount > CalculateBumpFees(const CFeeRate &target_feerate)
Construct a new block template and, for each outpoint corresponding to a transaction that did not mak...
std::optional< CAmount > CalculateTotalBumpFees(const CFeeRate &target_feerate)
Construct a new block template and, calculate the cost of bumping all transactions that did not make ...
std::map< Txid, MiniMinerMempoolEntry > m_entries_by_txid
Main data structure holding the entries, can be indexed by txid.
std::map< Txid, uint32_t > m_inclusion_order
void DeleteAncestorPackage(const std::set< MockEntryMap::iterator, IteratorComparator > &ancestors)
Consider this ancestor package "mined" so remove all these entries from our data structures.
void SanityCheck() const
Perform some checks.
std::vector< MockEntryMap::iterator > m_entries
Vector of entries, can be sorted by ancestor feerate.
MiniMiner(const CTxMemPool &mempool, const std::vector< COutPoint > &outpoints)
Constructor that takes a list of outpoints that may or may not belong to transactions in the mempool.
std::map< COutPoint, CAmount > m_bump_fees
std::map< Txid, std::vector< MockEntryMap::iterator > > m_descendant_set_by_txid
Map of txid to its descendants.
bool m_ready_to_calculate
std::set< Txid > m_to_be_replaced
std::map< Txid, std::vector< COutPoint > > m_requested_outpoints_by_txid
void BuildMockTemplate(std::optional< CFeeRate > target_feerate)
Build a block template until the target feerate is hit.
int64_t GetTxSize() const
Data structure storing a fee and size, ordered by increasing fee/size.
bool operator()(const I &a, const I &b) const
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.