Bitcoin ABC 0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
miner.h
Go to the documentation of this file.
1// Copyright (c) 2009-2010 Satoshi Nakamoto
2// Copyright (c) 2009-2019 The Bitcoin Core developers
3// Distributed under the MIT software license, see the accompanying
4// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6#ifndef BITCOIN_NODE_MINER_H
7#define BITCOIN_NODE_MINER_H
8
9#include <consensus/amount.h>
11#include <primitives/block.h>
12#include <txmempool.h>
13
14#include <boost/multi_index/ordered_index.hpp>
15#include <boost/multi_index_container.hpp>
16
17#include <cstdint>
18#include <memory>
19#include <optional>
20
21class CBlockIndex;
22class CChainParams;
23class Config;
24class CScript;
25
26namespace Consensus {
27struct Params;
28}
29
30namespace avalanche {
31class Processor;
32}
33
34namespace node {
35static const bool DEFAULT_PRINTPRIORITY = false;
36
45
48
49 std::vector<CBlockTemplateEntry> entries;
50};
51
54private:
55 // The constructed block template
56 std::unique_ptr<CBlockTemplate> pblocktemplate;
57
58 // Configuration parameters for the block size
62
63 // Information on the current status of the block
68
69 // Chain context for the block
73
74 const CTxMemPool *const m_mempool;
77
78 const bool fPrintPriority;
79
80public:
87
89 const CTxMemPool *mempool,
90 const avalanche::Processor *avalanche = nullptr);
92 const Options &options,
93 const avalanche::Processor *avalanche = nullptr);
94
96 std::unique_ptr<CBlockTemplate>
97 CreateNewBlock(const CScript &scriptPubKeyIn);
98
100
101 static std::optional<int64_t> m_last_block_num_txs;
102 static std::optional<int64_t> m_last_block_size;
103
104private:
105 // utility functions
107 void resetBlock();
109 void AddToBlock(const CTxMemPoolEntryRef &entry);
110
111 // Methods for how to add transactions to a block.
115 void addTxs(const CTxMemPool &mempool) EXCLUSIVE_LOCKS_REQUIRED(mempool.cs);
116
117 // helper functions for addTxs()
120
122 bool CheckTx(const CTransaction &tx) const;
123};
124
127} // namespace node
128
129#endif // BITCOIN_NODE_MINER_H
const CChainParams & Params()
Return the currently selected parameters.
Nodes collect new transactions into a block, hash them into a hash tree, and scan through nonce value...
Definition block.h:23
Definition block.h:60
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition blockindex.h:25
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
Definition chainparams.h:80
Fee rate in satoshis per kilobyte: Amount / kB.
Definition feerate.h:21
Serialized script, used inside transaction inputs and outputs.
Definition script.h:431
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition txmempool.h:212
Chainstate stores and provides an API to update our local knowledge of the current best chain.
Definition validation.h:699
Definition rcu.h:85
Generate a new block, without valid proof-of-work.
Definition miner.h:53
Chainstate & m_chainstate
Definition miner.h:75
uint64_t nMaxGeneratedBlockSize
Definition miner.h:59
void resetBlock()
Clear the block's state and prepare for assembling a new block.
Definition miner.cpp:111
const CTxMemPool *const m_mempool
Definition miner.h:74
uint64_t GetMaxGeneratedBlockSize() const
Definition miner.h:99
std::unique_ptr< CBlockTemplate > CreateNewBlock(const CScript &scriptPubKeyIn)
Construct a new block template with coinbase to scriptPubKeyIn.
Definition miner.cpp:125
CFeeRate blockMinFeeRate
Definition miner.h:61
const bool fPrintPriority
Definition miner.h:78
uint64_t nBlockTx
Definition miner.h:65
const CChainParams & chainParams
Definition miner.h:72
int64_t m_lock_time_cutoff
Definition miner.h:71
static std::optional< int64_t > m_last_block_size
Definition miner.h:102
std::unique_ptr< CBlockTemplate > pblocktemplate
Definition miner.h:56
bool CheckTx(const CTransaction &tx) const
Check the transaction for finality, etc before adding to block.
Definition miner.cpp:287
static std::optional< int64_t > m_last_block_num_txs
Definition miner.h:101
void AddToBlock(const CTxMemPoolEntryRef &entry)
Add a tx to the block.
Definition miner.cpp:271
void addTxs(const CTxMemPool &mempool) EXCLUSIVE_LOCKS_REQUIRED(mempool.cs)
Add transactions from the mempool based on individual tx feerate.
Definition miner.cpp:298
uint64_t nBlockSigChecks
Definition miner.h:66
uint64_t nBlockSize
Definition miner.h:64
bool TestTxFits(uint64_t txSize, int64_t txSigChecks) const
Test if a new Tx would "fit" in the block.
Definition miner.cpp:259
uint64_t nMaxGeneratedBlockSigChecks
Definition miner.h:60
const avalanche::Processor *const m_avalanche
Definition miner.h:76
Definition init.h:28
static const bool DEFAULT_PRINTPRIORITY
Definition miner.h:35
int64_t UpdateTime(CBlockHeader *pblock, const CChainParams &chainParams, const CBlockIndex *pindexPrev, int64_t adjustedTime)
Definition miner.cpp:38
std::shared_ptr< const CTransaction > CTransactionRef
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
Definition random.h:85
uint64_t nMaxGeneratedBlockSize
Definition miner.h:84
Definition miner.h:37
CTransactionRef tx
Definition miner.h:38
int64_t sigChecks
Definition miner.h:40
CBlockTemplateEntry(CTransactionRef _tx, Amount _fees, int64_t _sigChecks)
Definition miner.h:42
Amount fees
Definition miner.h:39
std::vector< CBlockTemplateEntry > entries
Definition miner.h:49
#define EXCLUSIVE_LOCKS_REQUIRED(...)