Bitcoin Core  26.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 
97  const CBlock& GenesisBlock() const { return genesis; }
101  bool IsTestChain() const { return m_chain_type != ChainType::MAIN; }
103  bool IsMockableChain() const { return m_is_mockable_chain; }
104  uint64_t PruneAfterHeight() const { return nPruneAfterHeight; }
112  std::string GetChainTypeString() const { return ChainTypeToString(m_chain_type); }
114  ChainType GetChainType() const { return m_chain_type; }
116  const std::vector<std::string>& DNSSeeds() const { return vSeeds; }
117  const std::vector<unsigned char>& Base58Prefix(Base58Type type) const { return base58Prefixes[type]; }
118  const std::string& Bech32HRP() const { return bech32_hrp; }
119  const std::vector<uint8_t>& FixedSeeds() const { return vFixedSeeds; }
120  const CCheckpointData& Checkpoints() const { return checkpointData; }
121 
122  std::optional<AssumeutxoData> AssumeutxoForHeight(int height) const
123  {
124  return FindFirst(m_assumeutxo_data, [&](const auto& d) { return d.height == height; });
125  }
126  std::optional<AssumeutxoData> AssumeutxoForBlockhash(const uint256& blockhash) const
127  {
128  return FindFirst(m_assumeutxo_data, [&](const auto& d) { return d.blockhash == blockhash; });
129  }
130 
131  const ChainTxData& TxData() const { return chainTxData; }
132 
136  struct SigNetOptions {
137  std::optional<std::vector<uint8_t>> challenge{};
138  std::optional<std::vector<std::string>> seeds{};
139  };
140 
145  int64_t start_time;
146  int64_t timeout;
148  };
149 
153  struct RegTestOptions {
154  std::unordered_map<Consensus::DeploymentPos, VersionBitsParameters> version_bits_parameters{};
155  std::unordered_map<Consensus::BuriedDeployment, int> activation_heights{};
156  bool fastprune{false};
157  };
158 
159  static std::unique_ptr<const CChainParams> RegTest(const RegTestOptions& options);
160  static std::unique_ptr<const CChainParams> SigNet(const SigNetOptions& options);
161  static std::unique_ptr<const CChainParams> Main();
162  static std::unique_ptr<const CChainParams> TestNet();
163 
164 protected:
166 
169  uint16_t nDefaultPort;
173  std::vector<std::string> vSeeds;
174  std::vector<unsigned char> base58Prefixes[MAX_BASE58_TYPES];
175  std::string bech32_hrp;
178  std::vector<uint8_t> vFixedSeeds;
182  std::vector<AssumeutxoData> m_assumeutxo_data;
184 };
185 
186 #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:112
uint64_t m_assumed_chain_state_size
Definition: chainparams.h:172
MessageStartChars pchMessageStart
Definition: chainparams.h:168
const std::vector< unsigned char > & Base58Prefix(Base58Type type) const
Definition: chainparams.h:117
static std::unique_ptr< const CChainParams > Main()
std::string bech32_hrp
Definition: chainparams.h:175
bool DefaultConsistencyChecks() const
Default value for -checkmempool and -checkblockindex argument.
Definition: chainparams.h:99
static std::unique_ptr< const CChainParams > RegTest(const RegTestOptions &options)
CBlock genesis
Definition: chainparams.h:177
const std::vector< std::string > & DNSSeeds() const
Return the list of hostnames to look up for DNS seeds.
Definition: chainparams.h:116
const ChainTxData & TxData() const
Definition: chainparams.h:131
std::optional< AssumeutxoData > AssumeutxoForHeight(int height) const
Definition: chainparams.h:122
const std::string & Bech32HRP() const
Definition: chainparams.h:118
uint64_t m_assumed_blockchain_size
Definition: chainparams.h:171
const CCheckpointData & Checkpoints() const
Definition: chainparams.h:120
std::vector< uint8_t > vFixedSeeds
Definition: chainparams.h:178
bool IsMockableChain() const
If this chain allows time to be mocked.
Definition: chainparams.h:103
bool fDefaultConsistencyChecks
Definition: chainparams.h:179
static std::unique_ptr< const CChainParams > TestNet()
std::vector< unsigned char > base58Prefixes[MAX_BASE58_TYPES]
Definition: chainparams.h:174
bool IsTestChain() const
If this chain is exclusively used for testing.
Definition: chainparams.h:101
std::optional< AssumeutxoData > AssumeutxoForBlockhash(const uint256 &blockhash) const
Definition: chainparams.h:126
bool MineBlocksOnDemand() const
Whether it is possible to mine blocks on demand (no retargeting)
Definition: chainparams.h:110
Consensus::Params consensus
Definition: chainparams.h:167
const std::vector< uint8_t > & FixedSeeds() const
Definition: chainparams.h:119
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:182
uint64_t AssumedBlockchainSize() const
Minimum free space (in GB) needed for data directory.
Definition: chainparams.h:106
std::vector< std::string > vSeeds
Definition: chainparams.h:173
bool m_is_mockable_chain
Definition: chainparams.h:180
const MessageStartChars & MessageStart() const
Definition: chainparams.h:94
ChainType m_chain_type
Definition: chainparams.h:176
uint64_t AssumedChainStateSize() const
Minimum free space (in GB) needed for data directory when pruned; Does not include prune target.
Definition: chainparams.h:108
uint64_t PruneAfterHeight() const
Definition: chainparams.h:104
CCheckpointData checkpointData
Definition: chainparams.h:181
uint16_t nDefaultPort
Definition: chainparams.h:169
ChainType GetChainType() const
Return the chain type.
Definition: chainparams.h:114
const CBlock & GenesisBlock() const
Definition: chainparams.h:97
static std::unique_ptr< const CChainParams > SigNet(const SigNetOptions &options)
uint64_t nPruneAfterHeight
Definition: chainparams.h:170
ChainTxData chainTxData
Definition: chainparams.h:183
256-bit opaque blob.
Definition: uint256.h:106
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:153
std::unordered_map< Consensus::DeploymentPos, VersionBitsParameters > version_bits_parameters
Definition: chainparams.h:154
std::unordered_map< Consensus::BuriedDeployment, int > activation_heights
Definition: chainparams.h:155
SigNetOptions holds configurations for creating a signet CChainParams.
Definition: chainparams.h:136
std::optional< std::vector< uint8_t > > challenge
Definition: chainparams.h:137
std::optional< std::vector< std::string > > seeds
Definition: chainparams.h:138
VersionBitsParameters holds activation parameters.
Definition: chainparams.h:144
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