Bitcoin ABC 0.31.1
P2P Digital Currency
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 <node/blockfitter.h>
12#include <primitives/block.h>
13#include <txmempool.h>
14
15#include <boost/multi_index/ordered_index.hpp>
16#include <boost/multi_index_container.hpp>
17
18#include <cstdint>
19#include <memory>
20#include <optional>
21
22class CBlockIndex;
23class CChainParams;
24class Config;
25class CScript;
26
27namespace Consensus {
28struct Params;
29}
30
31namespace avalanche {
32class Processor;
33}
34
35namespace node {
36static const bool DEFAULT_PRINTPRIORITY = false;
37
41 int64_t sigChecks;
42
43 CBlockTemplateEntry(CTransactionRef _tx, Amount _fees, int64_t _sigChecks)
44 : tx(_tx), fees(_fees), sigChecks(_sigChecks){};
45};
46
49
50 std::vector<CBlockTemplateEntry> entries;
51};
52
55private:
56 // The constructed block template
57 std::unique_ptr<CBlockTemplate> pblocktemplate;
58
60
61 // Chain context for the block
65
66 const CTxMemPool *const m_mempool;
69
70 const bool fPrintPriority;
71
72public:
73 BlockAssembler(const Config &config, Chainstate &chainstate,
74 const CTxMemPool *mempool,
75 const avalanche::Processor *avalanche = nullptr);
76 BlockAssembler(const node::BlockFitter &fitter, Chainstate &chainstate,
77 const CTxMemPool *mempool,
78 const avalanche::Processor *avalanche = nullptr);
79
81 std::unique_ptr<CBlockTemplate>
82 CreateNewBlock(const CScript &scriptPubKeyIn);
83
84 uint64_t GetMaxGeneratedBlockSize() const {
86 }
87
88 static std::optional<int64_t> m_last_block_num_txs;
89 static std::optional<int64_t> m_last_block_size;
90
91private:
92 // utility functions
94 void resetBlock();
96 void AddToBlock(const CTxMemPoolEntryRef &entry);
97
98 // Methods for how to add transactions to a block.
102 void addTxs(const CTxMemPool &mempool) EXCLUSIVE_LOCKS_REQUIRED(mempool.cs);
103
105 bool CheckTx(const CTransaction &tx) const;
106};
107
108int64_t UpdateTime(CBlockHeader *pblock, const CChainParams &chainParams,
109 const CBlockIndex *pindexPrev, int64_t adjustedTime);
110} // namespace node
111
112#endif // BITCOIN_NODE_MINER_H
const CChainParams & Params()
Return the currently selected parameters.
Definition: chainparams.cpp:19
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:85
CScript()
Definition: script.h:438
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:214
Chainstate stores and provides an API to update our local knowledge of the current best chain.
Definition: validation.h:700
Definition: config.h:19
Definition: rcu.h:85
Generate a new block, without valid proof-of-work.
Definition: miner.h:54
Chainstate & m_chainstate
Definition: miner.h:67
void resetBlock()
Clear the block's state and prepare for assembling a new block.
const CTxMemPool *const m_mempool
Definition: miner.h:66
uint64_t GetMaxGeneratedBlockSize() const
Definition: miner.h:84
std::unique_ptr< CBlockTemplate > CreateNewBlock(const CScript &scriptPubKeyIn)
Construct a new block template with coinbase to scriptPubKeyIn.
Definition: miner.cpp:74
const bool fPrintPriority
Definition: miner.h:70
const CChainParams & chainParams
Definition: miner.h:64
int64_t m_lock_time_cutoff
Definition: miner.h:63
static std::optional< int64_t > m_last_block_size
Definition: miner.h:89
std::unique_ptr< CBlockTemplate > pblocktemplate
Definition: miner.h:57
bool CheckTx(const CTransaction &tx) const
Check the transaction for finality, etc before adding to block.
Definition: miner.cpp:225
static std::optional< int64_t > m_last_block_num_txs
Definition: miner.h:88
void AddToBlock(const CTxMemPoolEntryRef &entry)
Add a tx to the block.
Definition: miner.cpp:210
void addTxs(const CTxMemPool &mempool) EXCLUSIVE_LOCKS_REQUIRED(mempool.cs)
Add transactions from the mempool based on individual tx feerate.
Definition: miner.cpp:236
BlockAssembler(const Config &config, Chainstate &chainstate, const CTxMemPool *mempool, const avalanche::Processor *avalanche=nullptr)
Definition: miner.cpp:65
BlockFitter blockFitter
Definition: miner.h:59
const avalanche::Processor *const m_avalanche
Definition: miner.h:68
Check for block limits when adding transactions.
Definition: blockfitter.h:17
uint64_t getMaxGeneratedBlockSize() const
Definition: blockfitter.h:43
Definition: init.h:31
static const bool DEFAULT_PRINTPRIORITY
Definition: miner.h:36
int64_t UpdateTime(CBlockHeader *pblock, const CChainParams &chainParams, const CBlockIndex *pindexPrev, int64_t adjustedTime)
Definition: miner.cpp:38
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:315
Definition: amount.h:19
Definition: miner.h:38
CTransactionRef tx
Definition: miner.h:39
int64_t sigChecks
Definition: miner.h:41
CBlockTemplateEntry(CTransactionRef _tx, Amount _fees, int64_t _sigChecks)
Definition: miner.h:43
Amount fees
Definition: miner.h:40
std::vector< CBlockTemplateEntry > entries
Definition: miner.h:50
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:56