Bitcoin Core 28.99.0
P2P Digital Currency
Classes | Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
node::BlockAssembler Class Reference

Generate a new block, without valid proof-of-work. More...

#include <miner.h>

Collaboration diagram for node::BlockAssembler:
[legend]

Classes

struct  Options
 

Public Member Functions

 BlockAssembler (Chainstate &chainstate, const CTxMemPool *mempool, const Options &options)
 
std::unique_ptr< CBlockTemplateCreateNewBlock ()
 Construct a new block template. More...
 

Static Public Attributes

static std::optional< int64_t > m_last_block_num_txs {}
 
static std::optional< int64_t > m_last_block_weight {}
 

Private Member Functions

void resetBlock ()
 Clear the block's state and prepare for assembling a new block. More...
 
void AddToBlock (CTxMemPool::txiter iter)
 Add a tx to the block. More...
 
void addPackageTxs (int &nPackagesSelected, int &nDescendantsUpdated) EXCLUSIVE_LOCKS_REQUIRED(!m_mempool -> cs)
 Add transactions based on feerate including unconfirmed ancestors Increments nPackagesSelected / nDescendantsUpdated with corresponding statistics from the package selection (for logging statistics). More...
 
void onlyUnconfirmed (CTxMemPool::setEntries &testSet)
 Remove confirmed (inBlock) entries from given set. More...
 
bool TestPackage (uint64_t packageSize, int64_t packageSigOpsCost) const
 Test if a new package would "fit" in the block. More...
 
bool TestPackageTransactions (const CTxMemPool::setEntries &package) const
 Perform checks on each transaction in a package: locktime, premature-witness, serialized size (if necessary) These checks should always succeed, and they're here only as an extra check in case of suboptimal node configuration. More...
 
void SortForBlock (const CTxMemPool::setEntries &package, std::vector< CTxMemPool::txiter > &sortedEntries)
 Sort the package in an order that is valid to appear in a block. More...
 

Private Attributes

std::unique_ptr< CBlockTemplatepblocktemplate
 
uint64_t nBlockWeight
 
uint64_t nBlockTx
 
uint64_t nBlockSigOpsCost
 
CAmount nFees
 
std::unordered_set< Txid, SaltedTxidHasherinBlock
 
int nHeight
 
int64_t m_lock_time_cutoff
 
const CChainParamschainparams
 
const CTxMemPool *const m_mempool
 
Chainstatem_chainstate
 
const Options m_options
 

Detailed Description

Generate a new block, without valid proof-of-work.

Definition at line 143 of file miner.h.

Constructor & Destructor Documentation

◆ BlockAssembler()

node::BlockAssembler::BlockAssembler ( Chainstate chainstate,
const CTxMemPool mempool,
const Options options 
)
explicit

Definition at line 78 of file miner.cpp.

Member Function Documentation

◆ addPackageTxs()

void node::BlockAssembler::addPackageTxs ( int &  nPackagesSelected,
int &  nDescendantsUpdated 
) -> cs)
private

Add transactions based on feerate including unconfirmed ancestors Increments nPackagesSelected / nDescendantsUpdated with corresponding statistics from the package selection (for logging statistics).

Precondition
BlockAssembler::m_mempool must not be nullptr

Return true if given transaction from mapTx has already been evaluated, or if the transaction's cached data in mapTx is incorrect.

Definition at line 290 of file miner.cpp.

Here is the call graph for this function:

◆ AddToBlock()

void node::BlockAssembler::AddToBlock ( CTxMemPool::txiter  iter)
private

Add a tx to the block.

Definition at line 221 of file miner.cpp.

Here is the call graph for this function:

◆ CreateNewBlock()

std::unique_ptr< CBlockTemplate > node::BlockAssembler::CreateNewBlock ( )

Construct a new block template.

Definition at line 109 of file miner.cpp.

Here is the call graph for this function:

◆ onlyUnconfirmed()

void node::BlockAssembler::onlyUnconfirmed ( CTxMemPool::setEntries testSet)
private

Remove confirmed (inBlock) entries from given set.

Definition at line 185 of file miner.cpp.

◆ resetBlock()

void node::BlockAssembler::resetBlock ( )
private

Clear the block's state and prepare for assembling a new block.

Definition at line 96 of file miner.cpp.

◆ SortForBlock()

void node::BlockAssembler::SortForBlock ( const CTxMemPool::setEntries package,
std::vector< CTxMemPool::txiter > &  sortedEntries 
)
private

Sort the package in an order that is valid to appear in a block.

Definition at line 269 of file miner.cpp.

◆ TestPackage()

bool node::BlockAssembler::TestPackage ( uint64_t  packageSize,
int64_t  packageSigOpsCost 
) const
private

Test if a new package would "fit" in the block.

Definition at line 197 of file miner.cpp.

◆ TestPackageTransactions()

bool node::BlockAssembler::TestPackageTransactions ( const CTxMemPool::setEntries package) const
private

Perform checks on each transaction in a package: locktime, premature-witness, serialized size (if necessary) These checks should always succeed, and they're here only as an extra check in case of suboptimal node configuration.

Definition at line 211 of file miner.cpp.

Here is the call graph for this function:

Member Data Documentation

◆ chainparams

const CChainParams& node::BlockAssembler::chainparams
private

Definition at line 160 of file miner.h.

◆ inBlock

std::unordered_set<Txid, SaltedTxidHasher> node::BlockAssembler::inBlock
private

Definition at line 154 of file miner.h.

◆ m_chainstate

Chainstate& node::BlockAssembler::m_chainstate
private

Definition at line 162 of file miner.h.

◆ m_last_block_num_txs

std::optional<int64_t> node::BlockAssembler::m_last_block_num_txs {}
inlinestatic

Definition at line 179 of file miner.h.

◆ m_last_block_weight

std::optional<int64_t> node::BlockAssembler::m_last_block_weight {}
inlinestatic

Definition at line 180 of file miner.h.

◆ m_lock_time_cutoff

int64_t node::BlockAssembler::m_lock_time_cutoff
private

Definition at line 158 of file miner.h.

◆ m_mempool

const CTxMemPool* const node::BlockAssembler::m_mempool
private

Definition at line 161 of file miner.h.

◆ m_options

const Options node::BlockAssembler::m_options
private

Definition at line 183 of file miner.h.

◆ nBlockSigOpsCost

uint64_t node::BlockAssembler::nBlockSigOpsCost
private

Definition at line 152 of file miner.h.

◆ nBlockTx

uint64_t node::BlockAssembler::nBlockTx
private

Definition at line 151 of file miner.h.

◆ nBlockWeight

uint64_t node::BlockAssembler::nBlockWeight
private

Definition at line 150 of file miner.h.

◆ nFees

CAmount node::BlockAssembler::nFees
private

Definition at line 153 of file miner.h.

◆ nHeight

int node::BlockAssembler::nHeight
private

Definition at line 157 of file miner.h.

◆ pblocktemplate

std::unique_ptr<CBlockTemplate> node::BlockAssembler::pblocktemplate
private

Definition at line 147 of file miner.h.


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