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 [ - + ][ # # : 23000 : 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.
47 : : */
48 : : size_t block_reserved_weight{DEFAULT_BLOCK_RESERVED_WEIGHT};
49 : : /**
50 : : * The maximum additional sigops which the pool will add in coinbase
51 : : * transaction outputs.
52 : : */
53 : : size_t coinbase_output_max_additional_sigops{400};
54 : : /**
55 : : * Script to put in the coinbase transaction. The default is an
56 : : * anyone-can-spend dummy.
57 : : *
58 : : * Should only be used for tests, when the default doesn't suffice.
59 : : *
60 : : * Note that higher level code like the getblocktemplate RPC may omit the
61 : : * coinbase transaction entirely. It's instead constructed by pool software
62 : : * using fields like coinbasevalue, coinbaseaux and default_witness_commitment.
63 : : * This software typically also controls the payout outputs, even for solo
64 : : * mining.
65 : : *
66 : : * The size and sigops are not checked against
67 : : * coinbase_max_additional_weight and coinbase_output_max_additional_sigops.
68 : : */
69 : : CScript coinbase_output_script{CScript() << OP_TRUE};
70 : : };
71 : :
72 : 0 : struct BlockWaitOptions {
73 : : /**
74 : : * How long to wait before returning nullptr instead of a new template.
75 : : * Default is to wait forever.
76 : : */
77 : : MillisecondsDouble timeout{MillisecondsDouble::max()};
78 : :
79 : : /**
80 : : * The wait method will not return a new template unless it has fees at
81 : : * least fee_threshold sats higher than the current template, or unless
82 : : * the chain tip changes and the previous template is no longer valid.
83 : : *
84 : : * A caller may not be interested in templates with higher fees, and
85 : : * determining whether fee_threshold is reached is also expensive. So as
86 : : * an optimization, when fee_threshold is set to MAX_MONEY (default), the
87 : : * implementation is able to be much more efficient, skipping expensive
88 : : * checks and only returning new templates when the chain tip changes.
89 : : */
90 : : CAmount fee_threshold{MAX_MONEY};
91 : : };
92 : :
93 : 0 : struct BlockCheckOptions {
94 : : /**
95 : : * Set false to omit the merkle root check
96 : : */
97 : : bool check_merkle_root{true};
98 : :
99 : : /**
100 : : * Set false to omit the proof-of-work check
101 : : */
102 : : bool check_pow{true};
103 : : };
104 : :
105 : : /**
106 : : * Template containing all coinbase transaction fields that are set by our
107 : : * miner code. Clients are expected to add their own outputs and typically
108 : : * also expand the scriptSig.
109 : : */
110 [ # # ]: 0 : struct CoinbaseTx {
111 : : /* nVersion */
112 : : uint32_t version;
113 : : /* nSequence for the only coinbase transaction input */
114 : : uint32_t sequence;
115 : : /**
116 : : * Prefix which needs to be placed at the beginning of the scriptSig.
117 : : * Clients may append extra data to this as long as the overall scriptSig
118 : : * size is 100 bytes or less, to avoid the block being rejected with
119 : : * "bad-cb-length" error.
120 : : *
121 : : * Currently with BIP 34, the prefix is guaranteed to be less than 8 bytes,
122 : : * but future soft forks could require longer prefixes.
123 : : */
124 : : CScript script_sig_prefix;
125 : : /**
126 : : * The first (and only) witness stack element of the coinbase input.
127 : : *
128 : : * Omitted for block templates without witness data.
129 : : *
130 : : * This is currently the BIP 141 witness reserved value, and can be chosen
131 : : * arbitrarily by the node, but future soft forks may constrain it.
132 : : */
133 : : std::optional<uint256> witness;
134 : : /**
135 : : * Block subsidy plus fees, minus any non-zero required_outputs.
136 : : *
137 : : * Currently there are no non-zero required_outputs, so block_reward_remaining
138 : : * is the entire block reward. See also required_outputs.
139 : : */
140 : : CAmount block_reward_remaining;
141 : : /*
142 : : * To be included as the last outputs in the coinbase transaction.
143 : : * Currently this is only the witness commitment OP_RETURN, but future
144 : : * softforks or a custom mining patch could add more.
145 : : *
146 : : * The dummy output that spends the full reward is excluded.
147 : : */
148 : : std::vector<CTxOut> required_outputs;
149 : : uint32_t lock_time;
150 : : };
151 : :
152 : : /**
153 : : * How to broadcast a local transaction.
154 : : * Used to influence `BroadcastTransaction()` and its callers.
155 : : */
156 : : enum class TxBroadcast : uint8_t {
157 : : /// Add the transaction to the mempool and broadcast to all peers for which tx relay is enabled.
158 : : MEMPOOL_AND_BROADCAST_TO_ALL,
159 : : /// Add the transaction to the mempool, but don't broadcast to anybody.
160 : : MEMPOOL_NO_BROADCAST,
161 : : /// Omit the mempool and directly send the transaction via a few dedicated connections to
162 : : /// peers on privacy networks.
163 : : NO_MEMPOOL_PRIVATE_BROADCAST,
164 : : };
165 : :
166 : : } // namespace node
167 : :
168 : : #endif // BITCOIN_NODE_TYPES_H
|