Bitcoin Core  27.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 
27 typedef 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 
38 struct AssumeutxoHash : public BaseHash<uint256> {
39  explicit AssumeutxoHash(const uint256& hash) : BaseHash(hash) {}
40 };
41 
48  int height;
49 
52 
57  unsigned int nChainTx;
58 
62 };
63 
70 struct ChainTxData {
71  int64_t nTime;
72  int64_t nTxCount;
73  double dTxRate;
74 };
75 
81 {
82 public:
83  enum Base58Type {
89 
91  };
92 
93  const Consensus::Params& GetConsensus() const { return consensus; }
94  const MessageStartChars& MessageStart() const { return pchMessageStart; }
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); }
115  ChainType GetChainType() const { return 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 
137  struct SigNetOptions {
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 
154  struct RegTestOptions {
155  std::unordered_map<Consensus::DeploymentPos, VersionBitsParameters> version_bits_parameters{};
156  std::unordered_map<Consensus::BuriedDeployment, int> activation_heights{};
157  bool fastprune{false};
158  };
159 
160  static std::unique_ptr<const CChainParams> RegTest(const RegTestOptions& options);
161  static std::unique_ptr<const CChainParams> SigNet(const SigNetOptions& options);
162  static std::unique_ptr<const CChainParams> Main();
163  static std::unique_ptr<const CChainParams> TestNet();
164 
165 protected:
167 
170  uint16_t nDefaultPort;
174  std::vector<std::string> vSeeds;
175  std::vector<unsigned char> base58Prefixes[MAX_BASE58_TYPES];
176  std::string bech32_hrp;
179  std::vector<uint8_t> vFixedSeeds;
183  std::vector<AssumeutxoData> m_assumeutxo_data;
185 };
186 
187 std::optional<ChainType> GetNetworkForMagic(const MessageStartChars& pchMessageStart);
188 
189 #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
uint64_t m_assumed_chain_state_size
Definition: chainparams.h:173
MessageStartChars pchMessageStart
Definition: chainparams.h:169
const std::vector< unsigned char > & Base58Prefix(Base58Type type) const
Definition: chainparams.h:118
static std::unique_ptr< const CChainParams > Main()
std::string bech32_hrp
Definition: chainparams.h:176
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:178
const std::vector< std::string > & DNSSeeds() const
Return the list of hostnames to look up for DNS seeds.
Definition: chainparams.h:117
const ChainTxData & TxData() const
Definition: chainparams.h:132
std::optional< AssumeutxoData > AssumeutxoForHeight(int height) const
Definition: chainparams.h:123
const std::string & Bech32HRP() const
Definition: chainparams.h:119
uint64_t m_assumed_blockchain_size
Definition: chainparams.h:172
const CCheckpointData & Checkpoints() const
Definition: chainparams.h:121
std::vector< uint8_t > vFixedSeeds
Definition: chainparams.h:179
bool IsMockableChain() const
If this chain allows time to be mocked.
Definition: chainparams.h:104
bool fDefaultConsistencyChecks
Definition: chainparams.h:180
static std::unique_ptr< const CChainParams > TestNet()
std::vector< unsigned char > base58Prefixes[MAX_BASE58_TYPES]
Definition: chainparams.h:175
bool IsTestChain() const
If this chain is exclusively used for testing.
Definition: chainparams.h:102
std::optional< AssumeutxoData > AssumeutxoForBlockhash(const uint256 &blockhash) const
Definition: chainparams.h:127
bool MineBlocksOnDemand() const
Whether it is possible to mine blocks on demand (no retargeting)
Definition: chainparams.h:111
Consensus::Params consensus
Definition: chainparams.h:168
const std::vector< uint8_t > & FixedSeeds() const
Definition: chainparams.h:120
const Consensus::Params & GetConsensus() const
Definition: chainparams.h:93
uint16_t GetDefaultPort() const
Definition: chainparams.h:95
std::vector< AssumeutxoData > m_assumeutxo_data
Definition: chainparams.h:183
uint64_t AssumedBlockchainSize() const
Minimum free space (in GB) needed for data directory.
Definition: chainparams.h:107
std::vector< std::string > vSeeds
Definition: chainparams.h:174
bool m_is_mockable_chain
Definition: chainparams.h:181
const MessageStartChars & MessageStart() const
Definition: chainparams.h:94
ChainType m_chain_type
Definition: chainparams.h:177
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:182
uint16_t nDefaultPort
Definition: chainparams.h:170
ChainType GetChainType() const
Return the chain type.
Definition: chainparams.h:115
const CBlock & GenesisBlock() const
Definition: chainparams.h:98
static std::unique_ptr< const CChainParams > SigNet(const SigNetOptions &options)
uint64_t nPruneAfterHeight
Definition: chainparams.h:171
ChainTxData chainTxData
Definition: chainparams.h:184
256-bit opaque blob.
Definition: uint256.h:106
std::optional< ChainType > GetNetworkForMagic(const MessageStartChars &pchMessageStart)
std::map< int, uint256 > MapCheckpoints
Definition: chainparams.h:27
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
unsigned int nChainTx
Used to populate the nChainTx 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
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
int64_t nTxCount
total number of transactions between genesis and that timestamp
Definition: chainparams.h:72
Parameters that influence chain consensus.
Definition: params.h:74
bool fPowNoRetargeting
Definition: params.h:111
std::optional< V > FindFirst(const std::vector< V > &vec, const L fnc)
Definition: vector.h:73