Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5//! @file node/mining_types.h is used externally by mining IPC clients, so it should6//! only declare simple data definitions.7//!8//! Avoid declaring functions or classes with methods here unless they are9//! header-only or provided by the util library.11#ifndef BITCOIN_NODE_MINING_TYPES_H12#define BITCOIN_NODE_MINING_TYPES_H14#include <consensus/amount.h>15#include <policy/feerate.h>16#include <policy/policy.h>17#include <primitives/transaction.h>18#include <script/script.h>19#include <uint256.h>20#include <util/time.h>22#include <cstddef>23#include <cstdint>24#include <optional>25#include <vector>27namespace node {29/**30* Block template creation options. These override node defaults, but can't31* exceed node limits (e.g. block_reserved_weight can't exceed max block weight).32*/33struct BlockCreateOptions {34/**35* Set false to omit mempool transactions36*/37bool use_mempool{true};38/**39* Minimum fee rate for transactions to be included. Providing a value40* overrides the -blockmintxfee startup setting.41*/42std::optional<CFeeRate> block_min_fee_rate{};43/**44* Whether to log the fee rate of each transaction when it is added to the45* block template. Providing a value overrides the -printpriority startup46* setting.47*/48std::optional<bool> print_modified_fee{};49/**50* The default reserved weight for the fixed-size block header,51* transaction count and coinbase transaction. Minimum: 2000 weight units52* (MINIMUM_BLOCK_RESERVED_WEIGHT).53*54* Providing a value overrides the `-blockreservedweight` startup setting.55* Cap'n Proto IPC clients currently cannot leave this field unset, so they56* always provide a value.57*/58std::optional<uint64_t> block_reserved_weight{};59/**60* Maximum block weight, defaults to -maxblockweight61*62* Must not be lower than block_reserved_weight. Setting this equal to63* block_reserved_weight leaves no room for non-coinbase transactions.64*/65std::optional<uint64_t> block_max_weight{};66/**67* The maximum additional sigops which the pool will add in coinbase68* transaction outputs.69*/70size_t coinbase_output_max_additional_sigops{DEFAULT_COINBASE_OUTPUT_MAX_ADDITIONAL_SIGOPS};71/**72* Script to put in the coinbase transaction. The default is an73* anyone-can-spend dummy.74*75* Should only be used for tests, when the default doesn't suffice.76*77* Note that higher level code like the getblocktemplate RPC may omit the78* coinbase transaction entirely. It's instead constructed by pool software79* using fields like coinbasevalue, coinbaseaux and default_witness_commitment.80* This software typically also controls the payout outputs, even for solo81* mining.82*83* The size and sigops are not checked against84* coinbase_max_additional_weight and coinbase_output_max_additional_sigops.85*/86CScript coinbase_output_script{CScript() << OP_TRUE};87/**88* Whether to call TestBlockValidity() at the end of CreateNewBlock().89* Should only be disabled for tests / benchmarks.90*/91bool test_block_validity{true};92};94struct BlockWaitOptions {95/**96* How long to wait before returning nullptr instead of a new template.97* Default is to wait forever.98*/99MillisecondsDouble timeout{MillisecondsDouble::max()};101/**102* The wait method will not return a new template unless it has fees at103* least fee_threshold sats higher than the current template, or unless104* the chain tip changes and the previous template is no longer valid.105*106* A caller may not be interested in templates with higher fees, and107* determining whether fee_threshold is reached is also expensive. So as108* an optimization, when fee_threshold is set to MAX_MONEY (default), the109* implementation is able to be much more efficient, skipping expensive110* checks and only returning new templates when the chain tip changes.111*/112CAmount fee_threshold{MAX_MONEY};113};115struct BlockCheckOptions {116/**117* Set false to omit the merkle root check118*/119bool check_merkle_root{true};121/**122* Set false to omit the proof-of-work check123*/124bool check_pow{true};125};127/**128* Template containing all coinbase transaction fields that are set by our129* miner code. Clients are expected to add their own outputs and typically130* also expand the scriptSig.131*/132struct CoinbaseTx {133/* nVersion */134uint32_t version;135/* nSequence for the only coinbase transaction input */136uint32_t sequence;137/**138* Prefix which needs to be placed at the beginning of the scriptSig.139* Clients may append extra data to this as long as the overall scriptSig140* size is 100 bytes or less, to avoid the block being rejected with141* "bad-cb-length" error. At heights <= 16 the BIP 34 height push is only142* one byte long, so clients must append at least one additional byte to143* meet the consensus minimum scriptSig length of two bytes.144*145* Currently with BIP 34, the prefix is guaranteed to be less than 8 bytes,146* but future soft forks could require longer prefixes.147*/148CScript script_sig_prefix;149/**150* The first (and only) witness stack element of the coinbase input.151*152* Omitted for block templates without witness data.153*154* This is currently the BIP 141 witness reserved value, and can be chosen155* arbitrarily by the node, but future soft forks may constrain it.156*/157std::optional<uint256> witness;158/**159* Block subsidy plus fees, minus any non-zero required_outputs.160*161* Currently there are no non-zero required_outputs, so block_reward_remaining162* is the entire block reward. See also required_outputs.163*/164CAmount block_reward_remaining;165/*166* To be included as the last outputs in the coinbase transaction.167* Currently this is only the witness commitment OP_RETURN, but future168* softforks or a custom mining patch could add more.169*170* The dummy output that spends the full reward is excluded.171*/172std::vector<CTxOut> required_outputs;173uint32_t lock_time;174};176} // namespace node178#endif // BITCOIN_NODE_MINING_TYPES_H
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.