LCOV - code coverage report
Current view: top level - src/node - types.h Coverage Total Hit
Test: fuzz_coverage.info Lines: 50.0 % 2 1
Test Date: 2026-05-19 07:27:20 Functions: - 0 0
Branches: 12.5 % 8 1

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

Generated by: LCOV version 2.0-1