Bitcoin Core  24.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_CHAINPARAMS_H
7 #define BITCOIN_CHAINPARAMS_H
8 
9 #include <chainparamsbase.h>
10 #include <consensus/params.h>
11 #include <netaddress.h>
12 #include <primitives/block.h>
13 #include <protocol.h>
14 #include <util/hash_type.h>
15 
16 #include <memory>
17 #include <string>
18 #include <vector>
19 
20 typedef std::map<int, uint256> MapCheckpoints;
21 
24 
25  int GetHeight() const {
26  const auto& final_checkpoint = mapCheckpoints.rbegin();
27  return final_checkpoint->first /* height */;
28  }
29 };
30 
31 struct AssumeutxoHash : public BaseHash<uint256> {
32  explicit AssumeutxoHash(const uint256& hash) : BaseHash(hash) {}
33 };
34 
43 
48  const unsigned int nChainTx;
49 };
50 
51 using MapAssumeutxo = std::map<int, const AssumeutxoData>;
52 
59 struct ChainTxData {
60  int64_t nTime;
61  int64_t nTxCount;
62  double dTxRate;
63 };
64 
70 {
71 public:
72  enum Base58Type {
78 
80  };
81 
82  const Consensus::Params& GetConsensus() const { return consensus; }
84  uint16_t GetDefaultPort() const { return nDefaultPort; }
85  uint16_t GetDefaultPort(Network net) const
86  {
87  return net == NET_I2P ? I2P_SAM31_PORT : GetDefaultPort();
88  }
89  uint16_t GetDefaultPort(const std::string& addr) const
90  {
91  CNetAddr a;
92  return a.SetSpecial(addr) ? GetDefaultPort(a.GetNetwork()) : GetDefaultPort();
93  }
94 
95  const CBlock& GenesisBlock() const { return genesis; }
99  bool RequireStandard() const { return fRequireStandard; }
101  bool IsTestChain() const { return m_is_test_chain; }
103  bool IsMockableChain() const { return m_is_mockable_chain; }
104  uint64_t PruneAfterHeight() const { return nPruneAfterHeight; }
112  std::string NetworkIDString() const { return strNetworkID; }
114  const std::vector<std::string>& DNSSeeds() const { return vSeeds; }
115  const std::vector<unsigned char>& Base58Prefix(Base58Type type) const { return base58Prefixes[type]; }
116  const std::string& Bech32HRP() const { return bech32_hrp; }
117  const std::vector<uint8_t>& FixedSeeds() const { return vFixedSeeds; }
118  const CCheckpointData& Checkpoints() const { return checkpointData; }
119 
122  const MapAssumeutxo& Assumeutxo() const { return m_assumeutxo_data; }
123 
124  const ChainTxData& TxData() const { return chainTxData; }
125 protected:
127 
130  uint16_t nDefaultPort;
134  std::vector<std::string> vSeeds;
135  std::vector<unsigned char> base58Prefixes[MAX_BASE58_TYPES];
136  std::string bech32_hrp;
137  std::string strNetworkID;
139  std::vector<uint8_t> vFixedSeeds;
147 };
148 
154 std::unique_ptr<const CChainParams> CreateChainParams(const ArgsManager& args, const std::string& chain);
155 
160 const CChainParams &Params();
161 
166 void SelectParams(const std::string& chain);
167 
168 #endif // BITCOIN_CHAINPARAMS_H
std::map< int, const AssumeutxoData > MapAssumeutxo
Definition: chainparams.h:51
void SelectParams(const std::string &chain)
Sets the params returned by Params() to those for the given chain name.
std::unique_ptr< const CChainParams > CreateChainParams(const ArgsManager &args, const std::string &chain)
Creates and returns a std::unique_ptr<CChainParams> of the chosen chain.
std::map< int, uint256 > MapCheckpoints
Definition: chainparams.h:20
const CChainParams & Params()
Return the currently selected parameters.
Definition: block.h:69
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
Definition: chainparams.h:70
uint64_t m_assumed_chain_state_size
Definition: chainparams.h:133
const std::vector< unsigned char > & Base58Prefix(Base58Type type) const
Definition: chainparams.h:115
std::string bech32_hrp
Definition: chainparams.h:136
bool DefaultConsistencyChecks() const
Default value for -checkmempool and -checkblockindex argument.
Definition: chainparams.h:97
bool m_is_test_chain
Definition: chainparams.h:142
std::string NetworkIDString() const
Return the network string.
Definition: chainparams.h:112
CBlock genesis
Definition: chainparams.h:138
uint16_t GetDefaultPort(const std::string &addr) const
Definition: chainparams.h:89
bool RequireStandard() const
Policy: Filter transactions that do not match well-defined patterns.
Definition: chainparams.h:99
MapAssumeutxo m_assumeutxo_data
Definition: chainparams.h:145
const std::vector< std::string > & DNSSeeds() const
Return the list of hostnames to look up for DNS seeds.
Definition: chainparams.h:114
const ChainTxData & TxData() const
Definition: chainparams.h:124
const CMessageHeader::MessageStartChars & MessageStart() const
Definition: chainparams.h:83
const std::string & Bech32HRP() const
Definition: chainparams.h:116
uint64_t m_assumed_blockchain_size
Definition: chainparams.h:132
const CCheckpointData & Checkpoints() const
Definition: chainparams.h:118
std::vector< uint8_t > vFixedSeeds
Definition: chainparams.h:139
bool IsMockableChain() const
If this chain allows time to be mocked.
Definition: chainparams.h:103
bool fDefaultConsistencyChecks
Definition: chainparams.h:140
std::string strNetworkID
Definition: chainparams.h:137
const MapAssumeutxo & Assumeutxo() const
Get allowed assumeutxo configuration.
Definition: chainparams.h:122
std::vector< unsigned char > base58Prefixes[MAX_BASE58_TYPES]
Definition: chainparams.h:135
bool IsTestChain() const
If this chain is exclusively used for testing.
Definition: chainparams.h:101
bool MineBlocksOnDemand() const
Whether it is possible to mine blocks on demand (no retargeting)
Definition: chainparams.h:110
Consensus::Params consensus
Definition: chainparams.h:128
const std::vector< uint8_t > & FixedSeeds() const
Definition: chainparams.h:117
const Consensus::Params & GetConsensus() const
Definition: chainparams.h:82
uint16_t GetDefaultPort() const
Definition: chainparams.h:84
uint64_t AssumedBlockchainSize() const
Minimum free space (in GB) needed for data directory.
Definition: chainparams.h:106
bool fRequireStandard
Definition: chainparams.h:141
std::vector< std::string > vSeeds
Definition: chainparams.h:134
bool m_is_mockable_chain
Definition: chainparams.h:143
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:144
uint16_t nDefaultPort
Definition: chainparams.h:130
CMessageHeader::MessageStartChars pchMessageStart
Definition: chainparams.h:129
const CBlock & GenesisBlock() const
Definition: chainparams.h:95
uint64_t nPruneAfterHeight
Definition: chainparams.h:131
ChainTxData chainTxData
Definition: chainparams.h:146
uint16_t GetDefaultPort(Network net) const
Definition: chainparams.h:85
unsigned char MessageStartChars[MESSAGE_START_SIZE]
Definition: protocol.h:36
Network address.
Definition: netaddress.h:120
bool SetSpecial(const std::string &addr)
Parse a Tor or I2P address and set this object to it.
Definition: netaddress.cpp:208
enum Network GetNetwork() const
Definition: netaddress.cpp:518
256-bit opaque blob.
Definition: uint256.h:119
static constexpr uint16_t I2P_SAM31_PORT
SAM 3.1 and earlier do not support specifying ports and force the port to 0.
Definition: netaddress.h:112
Network
A network type.
Definition: netaddress.h:44
@ NET_I2P
I2P.
Definition: netaddress.h:58
ArgsManager args
Holds configuration for use during UTXO snapshot load and validation.
Definition: chainparams.h:40
const AssumeutxoHash hash_serialized
The expected hash of the deserialized UTXO set.
Definition: chainparams.h:42
const unsigned int nChainTx
Used to populate the nChainTx value, which is used during BlockManager::LoadBlockIndex().
Definition: chainparams.h:48
AssumeutxoHash(const uint256 &hash)
Definition: chainparams.h:32
int GetHeight() const
Definition: chainparams.h:25
MapCheckpoints mapCheckpoints
Definition: chainparams.h:23
Holds various statistics on transactions within a chain.
Definition: chainparams.h:59
double dTxRate
estimated number of transactions per second after that timestamp
Definition: chainparams.h:62
int64_t nTime
UNIX timestamp of last known number of transactions.
Definition: chainparams.h:60
int64_t nTxCount
total number of transactions between genesis and that timestamp
Definition: chainparams.h:61
Parameters that influence chain consensus.
Definition: params.h:73
bool fPowNoRetargeting
Definition: params.h:110