Bitcoin ABC 0.31.6
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 <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:
57
58 // Chain context for the block
62
63 const CTxMemPool *const m_mempool;
66
67 const bool fPrintPriority;
68
69public:
70 BlockAssembler(const Config &config, Chainstate &chainstate,
71 const CTxMemPool *mempool,
72 const avalanche::Processor *avalanche = nullptr);
73 BlockAssembler(const node::BlockFitter &fitter, Chainstate &chainstate,
74 const CTxMemPool *mempool,
75 const avalanche::Processor *avalanche = nullptr);
76
78 std::unique_ptr<CBlockTemplate>
79 CreateNewBlock(const CScript &scriptPubKeyIn);
80
81 uint64_t GetMaxGeneratedBlockSize() const {
83 }
84
88 void addTxs(const CTxMemPool &mempool) EXCLUSIVE_LOCKS_REQUIRED(mempool.cs);
89
90 // The constructed block template
91 std::unique_ptr<CBlockTemplate> pblocktemplate;
92
93 static std::optional<int64_t> m_last_block_num_txs;
94 static std::optional<int64_t> m_last_block_size;
95
96private:
97 // utility functions
99 void resetBlock();
101 void AddToBlock(const CTxMemPoolEntryRef &entry);
102
103 // Methods for how to add transactions to a block.
104
106 bool CheckTx(const CTransaction &tx) const;
107};
108
109int64_t UpdateTime(CBlockHeader *pblock, const CChainParams &chainParams,
110 const CBlockIndex *pindexPrev, int64_t adjustedTime);
111} // namespace node
112
113#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: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:705
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:64
void resetBlock()
Clear the block's state and prepare for assembling a new block.
const CTxMemPool *const m_mempool
Definition: miner.h:63
uint64_t GetMaxGeneratedBlockSize() const
Definition: miner.h:81
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:67
const CChainParams & chainParams
Definition: miner.h:61
int64_t m_lock_time_cutoff
Definition: miner.h:60
static std::optional< int64_t > m_last_block_size
Definition: miner.h:94
std::unique_ptr< CBlockTemplate > pblocktemplate
Definition: miner.h:91
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:93
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:56
const avalanche::Processor *const m_avalanche
Definition: miner.h:65
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