Bitcoin Core Fuzz Coverage Report for wallet_tx_can_be_bumped

Coverage Report

Created: 2025-11-19 11:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/Users/brunogarcia/projects/bitcoin-core-dev/src/kernel/chainparams.h
Line
Count
Source
1
// Copyright (c) 2009-2010 Satoshi Nakamoto
2
// Copyright (c) 2009-2021 The Bitcoin Core developers
3
// Distributed under the MIT software license, see the accompanying
4
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6
#ifndef BITCOIN_KERNEL_CHAINPARAMS_H
7
#define BITCOIN_KERNEL_CHAINPARAMS_H
8
9
#include <consensus/params.h>
10
#include <kernel/messagestartchars.h>
11
#include <primitives/block.h>
12
#include <uint256.h>
13
#include <util/chaintype.h>
14
#include <util/hash_type.h>
15
#include <util/vector.h>
16
17
#include <cstdint>
18
#include <iterator>
19
#include <memory>
20
#include <optional>
21
#include <string>
22
#include <unordered_map>
23
#include <utility>
24
#include <vector>
25
26
struct AssumeutxoHash : public BaseHash<uint256> {
27
0
    explicit AssumeutxoHash(const uint256& hash) : BaseHash(hash) {}
28
};
29
30
/**
31
 * Holds configuration for use during UTXO snapshot load and validation. The contents
32
 * here are security critical, since they dictate which UTXO snapshots are recognized
33
 * as valid.
34
 */
35
struct AssumeutxoData {
36
    int height;
37
38
    //! The expected hash of the deserialized UTXO set.
39
    AssumeutxoHash hash_serialized;
40
41
    //! Used to populate the m_chain_tx_count value, which is used during BlockManager::LoadBlockIndex().
42
    //!
43
    //! We need to hardcode the value here because this is computed cumulatively using block data,
44
    //! which we do not necessarily have at the time of snapshot load.
45
    uint64_t m_chain_tx_count;
46
47
    //! The hash of the base block for this snapshot. Used to refer to assumeutxo data
48
    //! prior to having a loaded blockindex.
49
    uint256 blockhash;
50
};
51
52
/**
53
 * Holds various statistics on transactions within a chain. Used to estimate
54
 * verification progress during chain sync.
55
 *
56
 * See also: CChainParams::TxData, GuessVerificationProgress.
57
 */
58
struct ChainTxData {
59
    int64_t nTime;    //!< UNIX timestamp of last known number of transactions
60
    uint64_t tx_count; //!< total number of transactions between genesis and that timestamp
61
    double dTxRate;   //!< estimated number of transactions per second after that timestamp
62
};
63
64
//! Configuration for headers sync memory usage.
65
struct HeadersSyncParams {
66
    //! Distance in blocks between header commitments.
67
    size_t commitment_period{0};
68
    //! Minimum number of validated headers to accumulate in the redownload
69
    //! buffer before feeding them into the permanent block index.
70
    size_t redownload_buffer_size{0};
71
};
72
73
/**
74
 * CChainParams defines various tweakable parameters of a given instance of the
75
 * Bitcoin system.
76
 */
77
class CChainParams
78
{
79
public:
80
    enum Base58Type {
81
        PUBKEY_ADDRESS,
82
        SCRIPT_ADDRESS,
83
        SECRET_KEY,
84
        EXT_PUBLIC_KEY,
85
        EXT_SECRET_KEY,
86
87
        MAX_BASE58_TYPES
88
    };
89
90
0
    const Consensus::Params& GetConsensus() const { return consensus; }
91
0
    const MessageStartChars& MessageStart() const { return pchMessageStart; }
92
0
    uint16_t GetDefaultPort() const { return nDefaultPort; }
93
    std::vector<int> GetAvailableSnapshotHeights() const;
94
95
0
    const CBlock& GenesisBlock() const { return genesis; }
96
    /** Default value for -checkmempool and -checkblockindex argument */
97
0
    bool DefaultConsistencyChecks() const { return fDefaultConsistencyChecks; }
98
    /** If this chain is exclusively used for testing */
99
9.91k
    bool IsTestChain() const { return m_chain_type != ChainType::MAIN; }
100
    /** If this chain allows time to be mocked */
101
0
    bool IsMockableChain() const { return m_is_mockable_chain; }
102
0
    uint64_t PruneAfterHeight() const { return nPruneAfterHeight; }
103
    /** Minimum free space (in GB) needed for data directory */
104
0
    uint64_t AssumedBlockchainSize() const { return m_assumed_blockchain_size; }
105
    /** Minimum free space (in GB) needed for data directory when pruned; Does not include prune target*/
106
0
    uint64_t AssumedChainStateSize() const { return m_assumed_chain_state_size; }
107
    /** Whether it is possible to mine blocks on demand (no retargeting) */
108
0
    bool MineBlocksOnDemand() const { return consensus.fPowNoRetargeting; }
109
    /** Return the chain type string */
110
0
    std::string GetChainTypeString() const { return ChainTypeToString(m_chain_type); }
111
    /** Return the chain type */
112
0
    ChainType GetChainType() const { return m_chain_type; }
113
    /** Return the list of hostnames to look up for DNS seeds */
114
0
    const std::vector<std::string>& DNSSeeds() const { return vSeeds; }
115
422k
    const std::vector<unsigned char>& Base58Prefix(Base58Type type) const { return base58Prefixes[type]; }
116
4.07k
    const std::string& Bech32HRP() const { return bech32_hrp; }
117
0
    const std::vector<uint8_t>& FixedSeeds() const { return vFixedSeeds; }
118
0
    const HeadersSyncParams& HeadersSync() const { return m_headers_sync_params; }
119
120
    std::optional<AssumeutxoData> AssumeutxoForHeight(int height) const
121
0
    {
122
0
        return FindFirst(m_assumeutxo_data, [&](const auto& d) { return d.height == height; });
123
0
    }
124
    std::optional<AssumeutxoData> AssumeutxoForBlockhash(const uint256& blockhash) const
125
0
    {
126
0
        return FindFirst(m_assumeutxo_data, [&](const auto& d) { return d.blockhash == blockhash; });
127
0
    }
128
129
0
    const ChainTxData& TxData() const { return chainTxData; }
130
131
    /**
132
     * SigNetOptions holds configurations for creating a signet CChainParams.
133
     */
134
    struct SigNetOptions {
135
        std::optional<std::vector<uint8_t>> challenge{};
136
        std::optional<std::vector<std::string>> seeds{};
137
    };
138
139
    /**
140
     * VersionBitsParameters holds activation parameters
141
     */
142
    struct VersionBitsParameters {
143
        int64_t start_time;
144
        int64_t timeout;
145
        int min_activation_height;
146
    };
147
148
    /**
149
     * RegTestOptions holds configurations for creating a regtest CChainParams.
150
     */
151
    struct RegTestOptions {
152
        std::unordered_map<Consensus::DeploymentPos, VersionBitsParameters> version_bits_parameters{};
153
        std::unordered_map<Consensus::BuriedDeployment, int> activation_heights{};
154
        bool fastprune{false};
155
        bool enforce_bip94{false};
156
    };
157
158
    static std::unique_ptr<const CChainParams> RegTest(const RegTestOptions& options);
159
    static std::unique_ptr<const CChainParams> SigNet(const SigNetOptions& options);
160
    static std::unique_ptr<const CChainParams> Main();
161
    static std::unique_ptr<const CChainParams> TestNet();
162
    static std::unique_ptr<const CChainParams> TestNet4();
163
164
protected:
165
0
    CChainParams() = default;
166
167
    Consensus::Params consensus;
168
    MessageStartChars pchMessageStart;
169
    uint16_t nDefaultPort;
170
    uint64_t nPruneAfterHeight;
171
    uint64_t m_assumed_blockchain_size;
172
    uint64_t m_assumed_chain_state_size;
173
    std::vector<std::string> vSeeds;
174
    std::vector<unsigned char> base58Prefixes[MAX_BASE58_TYPES];
175
    std::string bech32_hrp;
176
    ChainType m_chain_type;
177
    CBlock genesis;
178
    std::vector<uint8_t> vFixedSeeds;
179
    bool fDefaultConsistencyChecks;
180
    bool m_is_mockable_chain;
181
    std::vector<AssumeutxoData> m_assumeutxo_data;
182
    ChainTxData chainTxData;
183
    HeadersSyncParams m_headers_sync_params;
184
};
185
186
std::optional<ChainType> GetNetworkForMagic(const MessageStartChars& pchMessageStart);
187
188
#endif // BITCOIN_KERNEL_CHAINPARAMS_H