Bitcoin ABC 0.32.4
P2P Digital Currency
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 <common/args.h>
10#include <consensus/amount.h>
12#include <node/blockfitter.h>
13#include <primitives/block.h>
14#include <txmempool.h>
15
16#include <boost/multi_index/ordered_index.hpp>
17#include <boost/multi_index_container.hpp>
18
19#include <cstdint>
20#include <memory>
21#include <optional>
22
23class CBlockIndex;
24class CChainParams;
25class Config;
26class CScript;
27
28namespace Consensus {
29struct Params;
30}
31
32namespace avalanche {
33class Processor;
34}
35
36namespace node {
37static const bool DEFAULT_PRINTPRIORITY = false;
38
42 int64_t sigChecks;
43
44 CBlockTemplateEntry(CTransactionRef _tx, Amount _fees, int64_t _sigChecks)
45 : tx(_tx), fees(_fees), sigChecks(_sigChecks){};
46};
47
50
51 std::vector<CBlockTemplateEntry> entries;
52};
53
56private:
58
59 // Chain context for the block
63
64 const CTxMemPool *const m_mempool;
67
68 const bool fPrintPriority;
69
70 // Whether to call TestBlockValidity() at the end of CreateNewBlock().
72
74
75public:
76 struct Options {
79 bool add_finalized_txs{false};
80 };
81
82 BlockAssembler(const Config &config, Chainstate &chainstate,
83 const CTxMemPool *mempool,
84 const avalanche::Processor *avalanche = nullptr);
85 BlockAssembler(const node::BlockFitter &fitter, Chainstate &chainstate,
86 const CTxMemPool *mempool,
87 const avalanche::Processor *avalanche = nullptr);
88 BlockAssembler(const node::BlockFitter &fitter, Chainstate &chainstate,
89 const CTxMemPool *mempool, const Options &options,
90 const avalanche::Processor *avalanche = nullptr);
91
93 std::unique_ptr<CBlockTemplate>
94 CreateNewBlock(const CScript &scriptPubKeyIn);
95
96 uint64_t GetMaxGeneratedBlockSize() const {
98 }
99
103 void addTxs(const CTxMemPool &mempool) EXCLUSIVE_LOCKS_REQUIRED(mempool.cs);
104
108 void addFinalizedTxs(const CTxMemPool &mempool)
109 EXCLUSIVE_LOCKS_REQUIRED(mempool.cs);
110
111 // The constructed block template
112 std::unique_ptr<CBlockTemplate> pblocktemplate;
113
114 static std::optional<int64_t> m_last_block_num_txs;
115 static std::optional<int64_t> m_last_block_size;
116
117private:
118 // utility functions
122 void AddToBlock(const CTxMemPoolEntryRef &entry);
123
124 // Methods for how to add transactions to a block.
125
127 bool CheckTx(const CTransaction &tx) const;
128};
129
130int64_t UpdateTime(CBlockHeader *pblock, const CChainParams &chainParams,
131 const CBlockIndex *pindexPrev, int64_t adjustedTime);
133void ApplyArgsManOptions(const ArgsManager &args,
134 BlockAssembler::Options &options);
135} // namespace node
136
137#endif // BITCOIN_NODE_MINER_H
const CChainParams & Params()
Return the currently selected parameters.
Definition: chainparams.cpp:21
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:86
CScript()
Definition: script.h:446
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:221
Chainstate stores and provides an API to update our local knowledge of the current best chain.
Definition: validation.h:734
Definition: config.h:19
Definition: rcu.h:85
Generate a new block, without valid proof-of-work.
Definition: miner.h:55
Chainstate & m_chainstate
Definition: miner.h:65
void resetBlock()
Clear the block's state and prepare for assembling a new block.
const CTxMemPool *const m_mempool
Definition: miner.h:64
uint64_t GetMaxGeneratedBlockSize() const
Definition: miner.h:96
std::unique_ptr< CBlockTemplate > CreateNewBlock(const CScript &scriptPubKeyIn)
Construct a new block template with coinbase to scriptPubKeyIn.
Definition: miner.cpp:97
const bool fPrintPriority
Definition: miner.h:68
void addFinalizedTxs(const CTxMemPool &mempool) EXCLUSIVE_LOCKS_REQUIRED(mempool.cs)
Add the finalized transactions to the block template.
Definition: miner.cpp:399
const bool add_finalized_txs
Definition: miner.h:73
const CChainParams & chainParams
Definition: miner.h:62
int64_t m_lock_time_cutoff
Definition: miner.h:61
static std::optional< int64_t > m_last_block_size
Definition: miner.h:115
std::unique_ptr< CBlockTemplate > pblocktemplate
Definition: miner.h:112
bool CheckTx(const CTransaction &tx) const
Check the transaction for finality, etc before adding to block.
Definition: miner.cpp:260
static std::optional< int64_t > m_last_block_num_txs
Definition: miner.h:114
void AddToBlock(const CTxMemPoolEntryRef &entry)
Add a tx to the block.
Definition: miner.cpp:245
void addTxs(const CTxMemPool &mempool) EXCLUSIVE_LOCKS_REQUIRED(mempool.cs)
Add transactions from the mempool based on individual tx feerate.
Definition: miner.cpp:271
BlockAssembler(const Config &config, Chainstate &chainstate, const CTxMemPool *mempool, const avalanche::Processor *avalanche=nullptr)
Definition: miner.cpp:88
BlockFitter blockFitter
Definition: miner.h:57
const bool test_block_validity
Definition: miner.h:71
const avalanche::Processor *const m_avalanche
Definition: miner.h:66
Check for block limits when adding transactions.
Definition: blockfitter.h:18
uint64_t getMaxGeneratedBlockSize() const
Definition: blockfitter.h:44
Definition: init.h:31
static const bool DEFAULT_PRINTPRIORITY
Definition: miner.h:37
int64_t UpdateTime(CBlockHeader *pblock, const CChainParams &chainParams, const CBlockIndex *pindexPrev, int64_t adjustedTime)
Definition: miner.cpp:38
void ApplyArgsManOptions(const ArgsManager &args, const Config &config, BlockFitter::Options &options)
Apply options from ArgsManager to BlockFitter options.
Definition: blockfitter.cpp:40
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:315
Definition: amount.h:19
Definition: miner.h:39
CTransactionRef tx
Definition: miner.h:40
int64_t sigChecks
Definition: miner.h:42
CBlockTemplateEntry(CTransactionRef _tx, Amount _fees, int64_t _sigChecks)
Definition: miner.h:44
Amount fees
Definition: miner.h:41
std::vector< CBlockTemplateEntry > entries
Definition: miner.h:51
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:56