Bitcoin ABC  0.24.7
P2P Digital Currency
Classes | Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
BlockAssembler Class Reference

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

#include <miner.h>

Collaboration diagram for BlockAssembler:
[legend]

Classes

struct  Options
 

Public Member Functions

 BlockAssembler (const Config &config, const CTxMemPool &mempool)
 
 BlockAssembler (const CChainParams &params, const CTxMemPool &mempool, const Options &options)
 
std::unique_ptr< CBlockTemplateCreateNewBlock (const CScript &scriptPubKeyIn)
 Construct a new block template with coinbase to scriptPubKeyIn. More...
 
uint64_t GetMaxGeneratedBlockSize () const
 

Static Public Attributes

static std::optional< int64_t > m_last_block_num_txs {std::nullopt}
 
static std::optional< int64_t > m_last_block_size {std::nullopt}
 

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. More...
 
void onlyUnconfirmed (CTxMemPool::setEntries &testSet)
 Remove confirmed (inBlock) entries from given set. More...
 
bool TestPackage (uint64_t packageSize, int64_t packageSigOpCount) const
 Test if a new package would "fit" in the block. More...
 
bool TestPackageTransactions (const CTxMemPool::setEntries &package)
 Perform checks on each transaction in a package: locktime, serialized size (if necessary). More...
 
bool SkipMapTxEntry (CTxMemPool::txiter it, indexed_modified_transaction_set &mapModifiedTx, CTxMemPool::setEntries &failedTx) EXCLUSIVE_LOCKS_REQUIRED(m_mempool.cs)
 Return true if given transaction from mapTx has already been evaluated, or if the transaction's cached data in mapTx is incorrect. 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...
 
int UpdatePackagesForAdded (const CTxMemPool::setEntries &alreadyAdded, indexed_modified_transaction_set &mapModifiedTx) EXCLUSIVE_LOCKS_REQUIRED(m_mempool.cs)
 Add descendants of given transactions to mapModifiedTx with ancestor state updated assuming given transactions are inBlock. More...
 

Private Attributes

std::unique_ptr< CBlockTemplatepblocktemplate
 
uint64_t nMaxGeneratedBlockSize
 
uint64_t nMaxGeneratedBlockSigChecks
 
CFeeRate blockMinFeeRate
 
uint64_t nBlockSize
 
uint64_t nBlockTx
 
uint64_t nBlockSigOps
 
Amount nFees
 
CTxMemPool::setEntries inBlock
 
int nHeight
 
int64_t nLockTimeCutoff
 
int64_t nMedianTimePast
 
const CChainParamschainParams
 
const CTxMemPoolm_mempool
 

Detailed Description

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

Definition at line 133 of file miner.h.

Constructor & Destructor Documentation

◆ BlockAssembler() [1/2]

BlockAssembler::BlockAssembler ( const Config config,
const CTxMemPool mempool 
)

Definition at line 101 of file miner.cpp.

◆ BlockAssembler() [2/2]

BlockAssembler::BlockAssembler ( const CChainParams params,
const CTxMemPool mempool,
const Options options 
)

Definition at line 60 of file miner.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ addPackageTxs()

void BlockAssembler::addPackageTxs ( int &  nPackagesSelected,
int &  nDescendantsUpdated 
)
private

Add transactions based on feerate including unconfirmed ancestors.

addPackageTx includes transactions paying a fee by ensuring that the partial ordering of transactions is maintained.

Increments nPackagesSelected / nDescendantsUpdated with corresponding statistics from the package selection (for logging statistics).

That is to say children come after parents, despite having a potentially larger fee.

Parameters
[out]nPackagesSelectedHow many packages were selected
[out]nDescendantsUpdatedNumber of descendant transactions updated

Definition at line 380 of file miner.cpp.

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

◆ AddToBlock()

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

Add a tx to the block.

Definition at line 297 of file miner.cpp.

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

◆ CreateNewBlock()

std::unique_ptr< CBlockTemplate > BlockAssembler::CreateNewBlock ( const CScript scriptPubKeyIn)

Construct a new block template with coinbase to scriptPubKeyIn.

Definition at line 121 of file miner.cpp.

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

◆ GetMaxGeneratedBlockSize()

uint64_t BlockAssembler::GetMaxGeneratedBlockSize ( ) const
inline

Definition at line 174 of file miner.h.

◆ onlyUnconfirmed()

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

Remove confirmed (inBlock) entries from given set.

Definition at line 244 of file miner.cpp.

Here is the caller graph for this function:

◆ resetBlock()

void BlockAssembler::resetBlock ( )
private

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

Definition at line 105 of file miner.cpp.

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

◆ SkipMapTxEntry()

bool BlockAssembler::SkipMapTxEntry ( CTxMemPool::txiter  it,
indexed_modified_transaction_set mapModifiedTx,
CTxMemPool::setEntries failedTx 
)
private

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 354 of file miner.cpp.

Here is the caller graph for this function:

◆ SortForBlock()

void 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 361 of file miner.cpp.

Here is the caller graph for this function:

◆ TestPackage()

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

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

Definition at line 256 of file miner.cpp.

Here is the caller graph for this function:

◆ TestPackageTransactions()

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

Perform checks on each transaction in a package: locktime, serialized size (if necessary).

Perform transaction-level checks before adding to block:

These checks should always succeed, and they're here only as an extra check in case of suboptimal node configuration.

  • Transaction finality (locktime)
  • Serialized size (in case -blockmaxsize is in use)

Definition at line 275 of file miner.cpp.

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

◆ UpdatePackagesForAdded()

int BlockAssembler::UpdatePackagesForAdded ( const CTxMemPool::setEntries alreadyAdded,
indexed_modified_transaction_set mapModifiedTx 
)
private

Add descendants of given transactions to mapModifiedTx with ancestor state updated assuming given transactions are inBlock.

Returns number of updated descendants.

Definition at line 316 of file miner.cpp.

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

Member Data Documentation

◆ blockMinFeeRate

CFeeRate BlockAssembler::blockMinFeeRate
private

Definition at line 141 of file miner.h.

◆ chainParams

const CChainParams& BlockAssembler::chainParams
private

Definition at line 154 of file miner.h.

◆ inBlock

CTxMemPool::setEntries BlockAssembler::inBlock
private

Definition at line 148 of file miner.h.

◆ m_last_block_num_txs

std::optional< int64_t > BlockAssembler::m_last_block_num_txs {std::nullopt}
static

Definition at line 176 of file miner.h.

◆ m_last_block_size

std::optional< int64_t > BlockAssembler::m_last_block_size {std::nullopt}
static

Definition at line 177 of file miner.h.

◆ m_mempool

const CTxMemPool& BlockAssembler::m_mempool
private

Definition at line 156 of file miner.h.

◆ nBlockSigOps

uint64_t BlockAssembler::nBlockSigOps
private

Definition at line 146 of file miner.h.

◆ nBlockSize

uint64_t BlockAssembler::nBlockSize
private

Definition at line 144 of file miner.h.

◆ nBlockTx

uint64_t BlockAssembler::nBlockTx
private

Definition at line 145 of file miner.h.

◆ nFees

Amount BlockAssembler::nFees
private

Definition at line 147 of file miner.h.

◆ nHeight

int BlockAssembler::nHeight
private

Definition at line 151 of file miner.h.

◆ nLockTimeCutoff

int64_t BlockAssembler::nLockTimeCutoff
private

Definition at line 152 of file miner.h.

◆ nMaxGeneratedBlockSigChecks

uint64_t BlockAssembler::nMaxGeneratedBlockSigChecks
private

Definition at line 140 of file miner.h.

◆ nMaxGeneratedBlockSize

uint64_t BlockAssembler::nMaxGeneratedBlockSize
private

Definition at line 139 of file miner.h.

◆ nMedianTimePast

int64_t BlockAssembler::nMedianTimePast
private

Definition at line 153 of file miner.h.

◆ pblocktemplate

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

Definition at line 136 of file miner.h.


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