Bitcoin Core  27.99.0
P2P Digital Currency
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
node::MiniMiner Class Reference

A minimal version of BlockAssembler, using the same ancestor set scoring algorithm. More...

#include <mini_miner.h>

Public Member Functions

bool IsReadyToCalculate () const
 Returns true if CalculateBumpFees may be called, false if not. More...
 
void BuildMockTemplate (std::optional< CFeeRate > target_feerate)
 Build a block template until the target feerate is hit. More...
 
std::set< uint256GetMockTemplateTxids () const
 Returns set of txids in the block template if one has been constructed. More...
 
 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. More...
 
 MiniMiner (const std::vector< MiniMinerMempoolEntry > &manual_entries, const std::map< Txid, std::set< Txid >> &descendant_caches)
 Constructor in which the MiniMinerMempoolEntry entries have been constructed manually. More...
 
std::map< COutPoint, CAmountCalculateBumpFees (const CFeeRate &target_feerate)
 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. More...
 
std::optional< CAmountCalculateTotalBumpFees (const CFeeRate &target_feerate)
 Construct a new block template and, calculate the cost of bumping all transactions that did not make it into the block to the target feerate. More...
 
std::map< Txid, uint32_t > Linearize ()
 Construct a new block template with all of the transactions and calculate the order in which they are selected. More...
 

Private Types

using MockEntryMap = decltype(m_entries_by_txid)
 

Private Member Functions

void DeleteAncestorPackage (const std::set< MockEntryMap::iterator, IteratorComparator > &ancestors)
 Consider this ancestor package "mined" so remove all these entries from our data structures. More...
 
void SanityCheck () const
 Perform some checks. More...
 

Private Attributes

bool m_ready_to_calculate {true}
 
std::set< uint256m_to_be_replaced
 
std::map< uint256, std::vector< COutPoint > > m_requested_outpoints_by_txid
 
std::map< Txid, uint32_t > m_inclusion_order
 
std::map< COutPoint, CAmountm_bump_fees
 
std::set< uint256m_in_block
 
CAmount m_total_fees {0}
 
int32_t m_total_vsize {0}
 
std::map< uint256, MiniMinerMempoolEntrym_entries_by_txid
 Main data structure holding the entries, can be indexed by txid. More...
 
std::vector< MockEntryMap::iterator > m_entries
 Vector of entries, can be sorted by ancestor feerate. More...
 
std::map< uint256, std::vector< MockEntryMap::iterator > > m_descendant_set_by_txid
 Map of txid to its descendants. More...
 

Detailed Description

A minimal version of BlockAssembler, using the same ancestor set scoring algorithm.

Allows us to run this algorithm on a limited set of transactions (e.g. subset of mempool or transactions that are not yet in mempool) instead of the entire mempool, ignoring consensus rules. Callers may use this to:

Definition at line 78 of file mini_miner.h.

Member Typedef Documentation

◆ MockEntryMap

Definition at line 109 of file mini_miner.h.

Constructor & Destructor Documentation

◆ MiniMiner() [1/2]

node::MiniMiner::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.

Copies out information about the relevant transactions in the mempool into MiniMinerMempoolEntrys.

Definition at line 23 of file mini_miner.cpp.

Here is the call graph for this function:

◆ MiniMiner() [2/2]

node::MiniMiner::MiniMiner ( const std::vector< MiniMinerMempoolEntry > &  manual_entries,
const std::map< Txid, std::set< Txid >> &  descendant_caches 
)

Constructor in which the MiniMinerMempoolEntry entries have been constructed manually.

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.

Parameters
[in]descendant_cachesA 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.

Definition at line 135 of file mini_miner.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ BuildMockTemplate()

void node::MiniMiner::BuildMockTemplate ( std::optional< CFeeRate target_feerate)

Build a block template until the target feerate is hit.

If target_feerate is not given, builds a block template until all transactions have been selected.

Definition at line 256 of file mini_miner.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CalculateBumpFees()

std::map< COutPoint, CAmount > node::MiniMiner::CalculateBumpFees ( const CFeeRate target_feerate)

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 if they cannot be calculated.

Definition at line 321 of file mini_miner.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CalculateTotalBumpFees()

std::optional< CAmount > node::MiniMiner::CalculateTotalBumpFees ( const CFeeRate target_feerate)

Construct a new block template and, calculate the cost of bumping all transactions that did not make it into the block to the target feerate.

Returns the total bump fee, or std::nullopt if it cannot be calculated.

Definition at line 401 of file mini_miner.cpp.

Here is the call graph for this function:

◆ DeleteAncestorPackage()

void node::MiniMiner::DeleteAncestorPackage ( const std::set< MockEntryMap::iterator, IteratorComparator > &  ancestors)
private

Consider this ancestor package "mined" so remove all these entries from our data structures.

Definition at line 209 of file mini_miner.cpp.

Here is the caller graph for this function:

◆ GetMockTemplateTxids()

std::set<uint256> node::MiniMiner::GetMockTemplateTxids ( ) const
inline

Returns set of txids in the block template if one has been constructed.

Definition at line 132 of file mini_miner.h.

◆ IsReadyToCalculate()

bool node::MiniMiner::IsReadyToCalculate ( ) const
inline

Returns true if CalculateBumpFees may be called, false if not.

Definition at line 125 of file mini_miner.h.

Here is the caller graph for this function:

◆ Linearize()

std::map< Txid, uint32_t > node::MiniMiner::Linearize ( )

Construct a new block template with all of the transactions and calculate the order in which they are selected.

Returns the sequence number (lower = selected earlier) with which each transaction was selected, indexed by txid, or an empty map if it cannot be calculated.

Definition at line 315 of file mini_miner.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SanityCheck()

void node::MiniMiner::SanityCheck ( ) const
private

Perform some checks.

Definition at line 242 of file mini_miner.cpp.

Here is the caller graph for this function:

Member Data Documentation

◆ m_bump_fees

std::map<COutPoint, CAmount> node::MiniMiner::m_bump_fees
private

Definition at line 98 of file mini_miner.h.

◆ m_descendant_set_by_txid

std::map<uint256, std::vector<MockEntryMap::iterator> > node::MiniMiner::m_descendant_set_by_txid
private

Map of txid to its descendants.

Should be inclusive.

Definition at line 115 of file mini_miner.h.

◆ m_entries

std::vector<MockEntryMap::iterator> node::MiniMiner::m_entries
private

Vector of entries, can be sorted by ancestor feerate.

Definition at line 112 of file mini_miner.h.

◆ m_entries_by_txid

std::map<uint256, MiniMinerMempoolEntry> node::MiniMiner::m_entries_by_txid
private

Main data structure holding the entries, can be indexed by txid.

Definition at line 108 of file mini_miner.h.

◆ m_in_block

std::set<uint256> node::MiniMiner::m_in_block
private

Definition at line 101 of file mini_miner.h.

◆ m_inclusion_order

std::map<Txid, uint32_t> node::MiniMiner::m_inclusion_order
private

Definition at line 96 of file mini_miner.h.

◆ m_ready_to_calculate

bool node::MiniMiner::m_ready_to_calculate {true}
private

Definition at line 82 of file mini_miner.h.

◆ m_requested_outpoints_by_txid

std::map<uint256, std::vector<COutPoint> > node::MiniMiner::m_requested_outpoints_by_txid
private

Definition at line 91 of file mini_miner.h.

◆ m_to_be_replaced

std::set<uint256> node::MiniMiner::m_to_be_replaced
private

Definition at line 86 of file mini_miner.h.

◆ m_total_fees

CAmount node::MiniMiner::m_total_fees {0}
private

Definition at line 104 of file mini_miner.h.

◆ m_total_vsize

int32_t node::MiniMiner::m_total_vsize {0}
private

Definition at line 105 of file mini_miner.h.


The documentation for this class was generated from the following files: