Bitcoin Core 28.99.0
P2P Digital Currency
chainparams.h
Go to the documentation of this file.
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>
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 <map>
20#include <memory>
21#include <optional>
22#include <string>
23#include <unordered_map>
24#include <utility>
25#include <vector>
26
27typedef std::map<int, uint256> MapCheckpoints;
28
31
32 int GetHeight() const {
33 const auto& final_checkpoint = mapCheckpoints.rbegin();
34 return final_checkpoint->first /* height */;
35 }
36};
37
38struct AssumeutxoHash : public BaseHash<uint256> {
39 explicit AssumeutxoHash(const uint256& hash) : BaseHash(hash) {}
40};
41
48 int height;
49
52
58
62};
63
71 int64_t nTime;
72 uint64_t tx_count;
73 double dTxRate;
74};
75
81{
82public:
89
91 };
92
93 const Consensus::Params& GetConsensus() const { return consensus; }
95 uint16_t GetDefaultPort() const { return nDefaultPort; }
96 std::vector<int> GetAvailableSnapshotHeights() const;
97
98 const CBlock& GenesisBlock() const { return genesis; }
102 bool IsTestChain() const { return m_chain_type != ChainType::MAIN; }
104 bool IsMockableChain() const { return m_is_mockable_chain; }
105 uint64_t PruneAfterHeight() const { return nPruneAfterHeight; }
113 std::string GetChainTypeString() const { return ChainTypeToString(m_chain_type); }
117 const std::vector<std::string>& DNSSeeds() const { return vSeeds; }
118 const std::vector<unsigned char>& Base58Prefix(Base58Type type) const { return base58Prefixes[type]; }
119 const std::string& Bech32HRP() const { return bech32_hrp; }
120 const std::vector<uint8_t>& FixedSeeds() const { return vFixedSeeds; }
121 const CCheckpointData& Checkpoints() const { return checkpointData; }
122
123 std::optional<AssumeutxoData> AssumeutxoForHeight(int height) const
124 {
125 return FindFirst(m_assumeutxo_data, [&](const auto& d) { return d.height == height; });
126 }
127 std::optional<AssumeutxoData> AssumeutxoForBlockhash(const uint256& blockhash) const
128 {
129 return FindFirst(m_assumeutxo_data, [&](const auto& d) { return d.blockhash == blockhash; });
130 }
131
132 const ChainTxData& TxData() const { return chainTxData; }
133
138 std::optional<std::vector<uint8_t>> challenge{};
139 std::optional<std::vector<std::string>> seeds{};
140 };
141
146 int64_t start_time;
147 int64_t timeout;
149 };
150
155 std::unordered_map<Consensus::DeploymentPos, VersionBitsParameters> version_bits_parameters{};
156 std::unordered_map<Consensus::BuriedDeployment, int> activation_heights{};
157 bool fastprune{false};
158 bool enforce_bip94{false};
159 };
160
161 static std::unique_ptr<const CChainParams> RegTest(const RegTestOptions& options);
162 static std::unique_ptr<const CChainParams> SigNet(const SigNetOptions& options);
163 static std::unique_ptr<const CChainParams> Main();
164 static std::unique_ptr<const CChainParams> TestNet();
165 static std::unique_ptr<const CChainParams> TestNet4();
166
167protected:
168 CChainParams() = default;
169
172 uint16_t nDefaultPort;
176 std::vector<std::string> vSeeds;
177 std::vector<unsigned char> base58Prefixes[MAX_BASE58_TYPES];
178 std::string bech32_hrp;
181 std::vector<uint8_t> vFixedSeeds;
185 std::vector<AssumeutxoData> m_assumeutxo_data;
187};
188
189std::optional<ChainType> GetNetworkForMagic(const MessageStartChars& pchMessageStart);
190
191#endif // BITCOIN_KERNEL_CHAINPARAMS_H
std::string ChainTypeToString(ChainType chain)
Definition: chaintype.cpp:11
ChainType
Definition: chaintype.h:11
Definition: block.h:69
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
Definition: chainparams.h:81
std::string GetChainTypeString() const
Return the chain type string.
Definition: chainparams.h:113
const MessageStartChars & MessageStart() const
Definition: chainparams.h:94
uint64_t m_assumed_chain_state_size
Definition: chainparams.h:175
MessageStartChars pchMessageStart
Definition: chainparams.h:171
CChainParams()=default
static std::unique_ptr< const CChainParams > Main()
const CBlock & GenesisBlock() const
Definition: chainparams.h:98
std::string bech32_hrp
Definition: chainparams.h:178
bool DefaultConsistencyChecks() const
Default value for -checkmempool and -checkblockindex argument.
Definition: chainparams.h:100
std::vector< int > GetAvailableSnapshotHeights() const
static std::unique_ptr< const CChainParams > RegTest(const RegTestOptions &options)
CBlock genesis
Definition: chainparams.h:180
const std::vector< unsigned char > & Base58Prefix(Base58Type type) const
Definition: chainparams.h:118
uint64_t m_assumed_blockchain_size
Definition: chainparams.h:174
std::vector< uint8_t > vFixedSeeds
Definition: chainparams.h:181
bool IsMockableChain() const
If this chain allows time to be mocked.
Definition: chainparams.h:104
bool fDefaultConsistencyChecks
Definition: chainparams.h:182
const ChainTxData & TxData() const
Definition: chainparams.h:132
static std::unique_ptr< const CChainParams > TestNet()
const Consensus::Params & GetConsensus() const
Definition: chainparams.h:93
std::vector< unsigned char > base58Prefixes[MAX_BASE58_TYPES]
Definition: chainparams.h:177
bool IsTestChain() const
If this chain is exclusively used for testing.
Definition: chainparams.h:102
bool MineBlocksOnDemand() const
Whether it is possible to mine blocks on demand (no retargeting)
Definition: chainparams.h:111
Consensus::Params consensus
Definition: chainparams.h:170
uint16_t GetDefaultPort() const
Definition: chainparams.h:95
std::vector< AssumeutxoData > m_assumeutxo_data
Definition: chainparams.h:185
uint64_t AssumedBlockchainSize() const
Minimum free space (in GB) needed for data directory.
Definition: chainparams.h:107
const std::string & Bech32HRP() const
Definition: chainparams.h:119
std::vector< std::string > vSeeds
Definition: chainparams.h:176
bool m_is_mockable_chain
Definition: chainparams.h:183
static std::unique_ptr< const CChainParams > TestNet4()
std::optional< AssumeutxoData > AssumeutxoForBlockhash(const uint256 &blockhash) const
Definition: chainparams.h:127
ChainType m_chain_type
Definition: chainparams.h:179
uint64_t AssumedChainStateSize() const
Minimum free space (in GB) needed for data directory when pruned; Does not include prune target.
Definition: chainparams.h:109
uint64_t PruneAfterHeight() const
Definition: chainparams.h:105
CCheckpointData checkpointData
Definition: chainparams.h:184
uint16_t nDefaultPort
Definition: chainparams.h:172
std::optional< AssumeutxoData > AssumeutxoForHeight(int height) const
Definition: chainparams.h:123
ChainType GetChainType() const
Return the chain type.
Definition: chainparams.h:115
const CCheckpointData & Checkpoints() const
Definition: chainparams.h:121
static std::unique_ptr< const CChainParams > SigNet(const SigNetOptions &options)
const std::vector< std::string > & DNSSeeds() const
Return the list of hostnames to look up for DNS seeds.
Definition: chainparams.h:117
uint64_t nPruneAfterHeight
Definition: chainparams.h:173
ChainTxData chainTxData
Definition: chainparams.h:186
const std::vector< uint8_t > & FixedSeeds() const
Definition: chainparams.h:120
256-bit opaque blob.
Definition: uint256.h:190
std::map< int, uint256 > MapCheckpoints
Definition: chainparams.h:27
std::optional< ChainType > GetNetworkForMagic(const MessageStartChars &pchMessageStart)
std::array< uint8_t, 4 > MessageStartChars
Holds configuration for use during UTXO snapshot load and validation.
Definition: chainparams.h:47
AssumeutxoHash hash_serialized
The expected hash of the deserialized UTXO set.
Definition: chainparams.h:51
uint64_t m_chain_tx_count
Used to populate the m_chain_tx_count value, which is used during BlockManager::LoadBlockIndex().
Definition: chainparams.h:57
uint256 blockhash
The hash of the base block for this snapshot.
Definition: chainparams.h:61
AssumeutxoHash(const uint256 &hash)
Definition: chainparams.h:39
RegTestOptions holds configurations for creating a regtest CChainParams.
Definition: chainparams.h:154
std::unordered_map< Consensus::DeploymentPos, VersionBitsParameters > version_bits_parameters
Definition: chainparams.h:155
std::unordered_map< Consensus::BuriedDeployment, int > activation_heights
Definition: chainparams.h:156
SigNetOptions holds configurations for creating a signet CChainParams.
Definition: chainparams.h:137
std::optional< std::vector< uint8_t > > challenge
Definition: chainparams.h:138
std::optional< std::vector< std::string > > seeds
Definition: chainparams.h:139
VersionBitsParameters holds activation parameters.
Definition: chainparams.h:145
int GetHeight() const
Definition: chainparams.h:32
MapCheckpoints mapCheckpoints
Definition: chainparams.h:30
Holds various statistics on transactions within a chain.
Definition: chainparams.h:70
uint64_t tx_count
total number of transactions between genesis and that timestamp
Definition: chainparams.h:72
double dTxRate
estimated number of transactions per second after that timestamp
Definition: chainparams.h:73
int64_t nTime
UNIX timestamp of last known number of transactions.
Definition: chainparams.h:71
Parameters that influence chain consensus.
Definition: params.h:74
bool fPowNoRetargeting
Definition: params.h:116
std::optional< V > FindFirst(const std::vector< V > &vec, const L fnc)
Definition: vector.h:73