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