Branch data Line data Source code
1 : : // Copyright (c) The Bitcoin Core developers
2 : : // Distributed under the MIT software license, see the accompanying
3 : : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 : :
5 : : //! @file
6 : : //! @brief Simple data definitions used by mining IPC clients.
7 : : //!
8 : : //! This file is used externally by mining IPC clients, so it should only
9 : : //! declare simple data definitions.
10 : : //!
11 : : //! Avoid declaring functions or classes with methods here unless they are
12 : : //! header-only or provided by the util library.
13 : :
14 : : #ifndef BITCOIN_NODE_MINING_TYPES_H
15 : : #define BITCOIN_NODE_MINING_TYPES_H
16 : :
17 : : #include <consensus/amount.h>
18 : : #include <policy/feerate.h>
19 : : #include <policy/policy.h>
20 : : #include <primitives/transaction.h>
21 : : #include <script/script.h>
22 : : #include <uint256.h>
23 : : #include <util/time.h>
24 : :
25 : : #include <cstddef>
26 : : #include <cstdint>
27 : : #include <optional>
28 : : #include <vector>
29 : :
30 : : namespace node {
31 : :
32 : : /**
33 : : * Block template creation options. These override node defaults, but can't
34 : : * exceed node limits (e.g. block_reserved_weight can't exceed max block weight).
35 : : */
36 [ + + + - : 259698 : struct BlockCreateOptions {
+ - + - ]
[ + + + +
# # # # ]
[ + + - + ]
37 : : /**
38 : : * Set false to omit mempool transactions
39 : : */
40 : : bool use_mempool{true};
41 : : /**
42 : : * Minimum fee rate for transactions to be included. Providing a value
43 : : * overrides the -blockmintxfee startup setting.
44 : : */
45 : : std::optional<CFeeRate> block_min_fee_rate{};
46 : : /**
47 : : * Whether to log the fee rate of each transaction when it is added to the
48 : : * block template. Providing a value overrides the -printpriority startup
49 : : * setting.
50 : : */
51 : : std::optional<bool> print_modified_fee{};
52 : : /**
53 : : * The default reserved weight for the fixed-size block header,
54 : : * transaction count and coinbase transaction. Minimum: 2000 weight units
55 : : * (MINIMUM_BLOCK_RESERVED_WEIGHT).
56 : : *
57 : : * Providing a value overrides the `-blockreservedweight` startup setting.
58 : : * Cap'n Proto IPC clients currently cannot leave this field unset, so they
59 : : * always provide a value.
60 : : */
61 : : std::optional<uint64_t> block_reserved_weight{};
62 : : /**
63 : : * Maximum block weight, defaults to -maxblockweight
64 : : *
65 : : * Must not be lower than block_reserved_weight. Setting this equal to
66 : : * block_reserved_weight leaves no room for non-coinbase transactions.
67 : : */
68 : : std::optional<uint64_t> block_max_weight{};
69 : : /**
70 : : * The maximum additional sigops which the pool will add in coinbase
71 : : * transaction outputs.
72 : : */
73 : : size_t coinbase_output_max_additional_sigops{DEFAULT_COINBASE_OUTPUT_MAX_ADDITIONAL_SIGOPS};
74 : : /**
75 : : * Script to put in the coinbase transaction. The default is an
76 : : * anyone-can-spend dummy.
77 : : *
78 : : * Should only be used for tests, when the default doesn't suffice.
79 : : *
80 : : * Note that higher level code like the getblocktemplate RPC may omit the
81 : : * coinbase transaction entirely. It's instead constructed by pool software
82 : : * using fields like coinbasevalue, coinbaseaux and default_witness_commitment.
83 : : * This software typically also controls the payout outputs, even for solo
84 : : * mining.
85 : : *
86 : : * The size and sigops are not checked against
87 : : * coinbase_max_additional_weight and coinbase_output_max_additional_sigops.
88 : : */
89 : : CScript coinbase_output_script{CScript() << OP_TRUE};
90 : : /**
91 : : * Whether to call TestBlockValidity() at the end of CreateNewBlock().
92 : : * Should only be disabled for tests / benchmarks.
93 : : */
94 : : bool test_block_validity{true};
95 : : };
96 : :
97 : 0 : struct BlockWaitOptions {
98 : : /**
99 : : * How long to wait before returning nullptr instead of a new template.
100 : : * Default is to wait forever.
101 : : */
102 : : MillisecondsDouble timeout{MillisecondsDouble::max()};
103 : :
104 : : /**
105 : : * The wait method will not return a new template unless it has fees at
106 : : * least fee_threshold sats higher than the current template, or unless
107 : : * the chain tip changes and the previous template is no longer valid.
108 : : *
109 : : * A caller may not be interested in templates with higher fees, and
110 : : * determining whether fee_threshold is reached is also expensive. So as
111 : : * an optimization, when fee_threshold is set to MAX_MONEY (default), the
112 : : * implementation is able to be much more efficient, skipping expensive
113 : : * checks and only returning new templates when the chain tip changes.
114 : : */
115 : : CAmount fee_threshold{MAX_MONEY};
116 : : };
117 : :
118 : 0 : struct BlockCheckOptions {
119 : : /**
120 : : * Set false to omit the merkle root check
121 : : */
122 : : bool check_merkle_root{true};
123 : :
124 : : /**
125 : : * Set false to omit the proof-of-work check
126 : : */
127 : : bool check_pow{true};
128 : : };
129 : :
130 : : /**
131 : : * Template containing all coinbase transaction fields that are set by our
132 : : * miner code. Clients are expected to add their own outputs and typically
133 : : * also expand the scriptSig.
134 : : */
135 [ # # ]: 0 : struct CoinbaseTx {
136 : : /* nVersion */
137 : : uint32_t version;
138 : : /* nSequence for the only coinbase transaction input */
139 : : uint32_t sequence;
140 : : /**
141 : : * Prefix which needs to be placed at the beginning of the scriptSig.
142 : : * Clients may append extra data to this as long as the overall scriptSig
143 : : * size is 100 bytes or less, to avoid the block being rejected with
144 : : * "bad-cb-length" error. At heights <= 16 the BIP 34 height push is only
145 : : * one byte long, so clients must append at least one additional byte to
146 : : * meet the consensus minimum scriptSig length of two bytes.
147 : : *
148 : : * Currently with BIP 34, the prefix is guaranteed to be less than 8 bytes,
149 : : * but future soft forks could require longer prefixes.
150 : : */
151 : : CScript script_sig_prefix;
152 : : /**
153 : : * The first (and only) witness stack element of the coinbase input.
154 : : *
155 : : * Omitted for block templates without witness data.
156 : : *
157 : : * This is currently the BIP 141 witness reserved value, and can be chosen
158 : : * arbitrarily by the node, but future soft forks may constrain it.
159 : : */
160 : : std::optional<uint256> witness;
161 : : /**
162 : : * Block subsidy plus fees, minus any non-zero required_outputs.
163 : : *
164 : : * Currently there are no non-zero required_outputs, so block_reward_remaining
165 : : * is the entire block reward. See also required_outputs.
166 : : */
167 : : CAmount block_reward_remaining;
168 : : /*
169 : : * To be included as the last outputs in the coinbase transaction.
170 : : * Currently this is only the witness commitment OP_RETURN, but future
171 : : * softforks or a custom mining patch could add more.
172 : : *
173 : : * The dummy output that spends the full reward is excluded.
174 : : */
175 : : std::vector<CTxOut> required_outputs;
176 : : uint32_t lock_time;
177 : : };
178 : :
179 : : } // namespace node
180 : :
181 : : #endif // BITCOIN_NODE_MINING_TYPES_H
|