Branch data Line data Source code
1 : : // Copyright (c) 2010-present 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 node/types.h is a home for public enum and struct type definitions
6 : : //! that are used internally by node code, but also used externally by wallet,
7 : : //! mining or GUI code.
8 : : //!
9 : : //! This file is intended to define only simple types that do not have external
10 : : //! dependencies. More complicated types should be defined in dedicated header
11 : : //! files.
12 : :
13 : : #ifndef BITCOIN_NODE_TYPES_H
14 : : #define BITCOIN_NODE_TYPES_H
15 : :
16 : : #include <consensus/amount.h>
17 : : #include <cstddef>
18 : : #include <cstdint>
19 : : #include <optional>
20 : : #include <policy/policy.h>
21 : : #include <primitives/transaction.h>
22 : : #include <script/script.h>
23 : : #include <uint256.h>
24 : : #include <util/time.h>
25 : : #include <vector>
26 : :
27 : : namespace node {
28 : : enum class TransactionError {
29 : : OK, //!< No error
30 : : MISSING_INPUTS,
31 : : ALREADY_IN_UTXO_SET,
32 : : MEMPOOL_REJECTED,
33 : : MEMPOOL_ERROR,
34 : : MAX_FEE_EXCEEDED,
35 : : MAX_BURN_EXCEEDED,
36 : : INVALID_PACKAGE,
37 : : };
38 : :
39 [ + - + - : 187137 : struct BlockCreateOptions {
+ - ]
40 : : /**
41 : : * Set false to omit mempool transactions
42 : : */
43 : : bool use_mempool{true};
44 : : /**
45 : : * The default reserved weight for the fixed-size block header,
46 : : * transaction count and coinbase transaction. Minimum: 2000 weight units
47 : : * (MINIMUM_BLOCK_RESERVED_WEIGHT).
48 : : *
49 : : * Providing a value overrides the `-blockreservedweight` startup setting.
50 : : * Cap'n Proto IPC clients currently cannot leave this field unset, so they
51 : : * always provide a value.
52 : : */
53 : : std::optional<size_t> block_reserved_weight{};
54 : : /**
55 : : * The maximum additional sigops which the pool will add in coinbase
56 : : * transaction outputs.
57 : : */
58 : : size_t coinbase_output_max_additional_sigops{DEFAULT_COINBASE_OUTPUT_MAX_ADDITIONAL_SIGOPS};
59 : : /**
60 : : * Script to put in the coinbase transaction. The default is an
61 : : * anyone-can-spend dummy.
62 : : *
63 : : * Should only be used for tests, when the default doesn't suffice.
64 : : *
65 : : * Note that higher level code like the getblocktemplate RPC may omit the
66 : : * coinbase transaction entirely. It's instead constructed by pool software
67 : : * using fields like coinbasevalue, coinbaseaux and default_witness_commitment.
68 : : * This software typically also controls the payout outputs, even for solo
69 : : * mining.
70 : : *
71 : : * The size and sigops are not checked against
72 : : * coinbase_max_additional_weight and coinbase_output_max_additional_sigops.
73 : : */
74 : : CScript coinbase_output_script{CScript() << OP_TRUE};
75 : : /**
76 : : * Whether to include an OP_0 as a dummy extraNonce in the template's coinbase
77 : : */
78 : : bool include_dummy_extranonce{false};
79 : : };
80 : :
81 : 0 : struct BlockWaitOptions {
82 : : /**
83 : : * How long to wait before returning nullptr instead of a new template.
84 : : * Default is to wait forever.
85 : : */
86 : : MillisecondsDouble timeout{MillisecondsDouble::max()};
87 : :
88 : : /**
89 : : * The wait method will not return a new template unless it has fees at
90 : : * least fee_threshold sats higher than the current template, or unless
91 : : * the chain tip changes and the previous template is no longer valid.
92 : : *
93 : : * A caller may not be interested in templates with higher fees, and
94 : : * determining whether fee_threshold is reached is also expensive. So as
95 : : * an optimization, when fee_threshold is set to MAX_MONEY (default), the
96 : : * implementation is able to be much more efficient, skipping expensive
97 : : * checks and only returning new templates when the chain tip changes.
98 : : */
99 : : CAmount fee_threshold{MAX_MONEY};
100 : : };
101 : :
102 : 0 : struct BlockCheckOptions {
103 : : /**
104 : : * Set false to omit the merkle root check
105 : : */
106 : : bool check_merkle_root{true};
107 : :
108 : : /**
109 : : * Set false to omit the proof-of-work check
110 : : */
111 : : bool check_pow{true};
112 : : };
113 : :
114 : : /**
115 : : * Template containing all coinbase transaction fields that are set by our
116 : : * miner code. Clients are expected to add their own outputs and typically
117 : : * also expand the scriptSig.
118 : : */
119 [ # # ]: 2079 : struct CoinbaseTx {
120 : : /* nVersion */
121 : : uint32_t version;
122 : : /* nSequence for the only coinbase transaction input */
123 : : uint32_t sequence;
124 : : /**
125 : : * Prefix which needs to be placed at the beginning of the scriptSig.
126 : : * Clients may append extra data to this as long as the overall scriptSig
127 : : * size is 100 bytes or less, to avoid the block being rejected with
128 : : * "bad-cb-length" error.
129 : : *
130 : : * Currently with BIP 34, the prefix is guaranteed to be less than 8 bytes,
131 : : * but future soft forks could require longer prefixes.
132 : : */
133 : : CScript script_sig_prefix;
134 : : /**
135 : : * The first (and only) witness stack element of the coinbase input.
136 : : *
137 : : * Omitted for block templates without witness data.
138 : : *
139 : : * This is currently the BIP 141 witness reserved value, and can be chosen
140 : : * arbitrarily by the node, but future soft forks may constrain it.
141 : : */
142 : : std::optional<uint256> witness;
143 : : /**
144 : : * Block subsidy plus fees, minus any non-zero required_outputs.
145 : : *
146 : : * Currently there are no non-zero required_outputs, so block_reward_remaining
147 : : * is the entire block reward. See also required_outputs.
148 : : */
149 : : CAmount block_reward_remaining;
150 : : /*
151 : : * To be included as the last outputs in the coinbase transaction.
152 : : * Currently this is only the witness commitment OP_RETURN, but future
153 : : * softforks or a custom mining patch could add more.
154 : : *
155 : : * The dummy output that spends the full reward is excluded.
156 : : */
157 : : std::vector<CTxOut> required_outputs;
158 : : uint32_t lock_time;
159 : : };
160 : :
161 : : /**
162 : : * How to broadcast a local transaction.
163 : : * Used to influence `BroadcastTransaction()` and its callers.
164 : : */
165 : : enum class TxBroadcast : uint8_t {
166 : : /// Add the transaction to the mempool and broadcast to all peers for which tx relay is enabled.
167 : : MEMPOOL_AND_BROADCAST_TO_ALL,
168 : : /// Add the transaction to the mempool, but don't broadcast to anybody.
169 : : MEMPOOL_NO_BROADCAST,
170 : : /// Omit the mempool and directly send the transaction via a few dedicated connections to
171 : : /// peers on privacy networks.
172 : : NO_MEMPOOL_PRIVATE_BROADCAST,
173 : : };
174 : :
175 : : } // namespace node
176 : :
177 : : #endif // BITCOIN_NODE_TYPES_H
|