Skip to content

Commit 382b692

Browse files
dongcarlTheCharlatan
authored andcommitted
Split non/kernel chainparams
Moves chainparams code not using the ArgsManager to the kernel. Subsequently use the kernel chainparams header now where possible in order to further decouple chainparams call sites from gArgs.
1 parent edabbc7 commit 382b692

File tree

10 files changed

+732
-673
lines changed

10 files changed

+732
-673
lines changed

src/Makefile.am

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ BITCOIN_CORE_H = \
175175
interfaces/node.h \
176176
interfaces/wallet.h \
177177
kernel/chain.h \
178+
kernel/chainparams.h \
178179
kernel/chainstatemanager_opts.h \
179180
kernel/checks.h \
180181
kernel/coinstats.h \
@@ -651,6 +652,7 @@ libbitcoin_common_a_SOURCES = \
651652
deploymentinfo.cpp \
652653
external_signer.cpp \
653654
init/common.cpp \
655+
kernel/chainparams.cpp \
654656
key.cpp \
655657
key_io.cpp \
656658
merkleblock.cpp \
@@ -907,6 +909,7 @@ libbitcoinkernel_la_SOURCES = \
907909
hash.cpp \
908910
kernel/chain.cpp \
909911
kernel/checks.cpp \
912+
kernel/chainparams.cpp \
910913
kernel/coinstats.cpp \
911914
kernel/context.cpp \
912915
kernel/cs_main.cpp \

src/bitcoin-chainstate.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//
1212
// It is part of the libbitcoinkernel project.
1313

14+
#include <kernel/chainparams.h>
1415
#include <kernel/checks.h>
1516
#include <kernel/context.h>
1617
#include <kernel/validation_cache_sizes.h>
@@ -52,7 +53,7 @@ int main(int argc, char* argv[])
5253

5354
// SETUP: Misc Globals
5455
SelectParams(CBaseChainParams::MAIN);
55-
const CChainParams& chainparams = Params();
56+
auto chainparams = CChainParams::Main();
5657

5758
kernel::Context kernel_context{};
5859
// We can't use a goto here, but we can use an assert since none of the
@@ -81,7 +82,7 @@ int main(int argc, char* argv[])
8182

8283
// SETUP: Chainstate
8384
const ChainstateManager::Options chainman_opts{
84-
.chainparams = chainparams,
85+
.chainparams = *chainparams,
8586
.datadir = gArgs.GetDataDirNet(),
8687
.adjusted_time_callback = NodeClock::now,
8788
};

src/chainparams.cpp

Lines changed: 0 additions & 506 deletions
Large diffs are not rendered by default.

src/chainparams.h

Lines changed: 2 additions & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#ifndef BITCOIN_CHAINPARAMS_H
77
#define BITCOIN_CHAINPARAMS_H
88

9+
#include <kernel/chainparams.h>
10+
911
#include <chainparamsbase.h>
1012
#include <consensus/params.h>
1113
#include <netaddress.h>
@@ -19,167 +21,6 @@
1921
#include <unordered_map>
2022
#include <vector>
2123

22-
typedef std::map<int, uint256> MapCheckpoints;
23-
24-
struct CCheckpointData {
25-
MapCheckpoints mapCheckpoints;
26-
27-
int GetHeight() const {
28-
const auto& final_checkpoint = mapCheckpoints.rbegin();
29-
return final_checkpoint->first /* height */;
30-
}
31-
};
32-
33-
struct AssumeutxoHash : public BaseHash<uint256> {
34-
explicit AssumeutxoHash(const uint256& hash) : BaseHash(hash) {}
35-
};
36-
37-
/**
38-
* Holds configuration for use during UTXO snapshot load and validation. The contents
39-
* here are security critical, since they dictate which UTXO snapshots are recognized
40-
* as valid.
41-
*/
42-
struct AssumeutxoData {
43-
//! The expected hash of the deserialized UTXO set.
44-
const AssumeutxoHash hash_serialized;
45-
46-
//! Used to populate the nChainTx value, which is used during BlockManager::LoadBlockIndex().
47-
//!
48-
//! We need to hardcode the value here because this is computed cumulatively using block data,
49-
//! which we do not necessarily have at the time of snapshot load.
50-
const unsigned int nChainTx;
51-
};
52-
53-
using MapAssumeutxo = std::map<int, const AssumeutxoData>;
54-
55-
/**
56-
* Holds various statistics on transactions within a chain. Used to estimate
57-
* verification progress during chain sync.
58-
*
59-
* See also: CChainParams::TxData, GuessVerificationProgress.
60-
*/
61-
struct ChainTxData {
62-
int64_t nTime; //!< UNIX timestamp of last known number of transactions
63-
int64_t nTxCount; //!< total number of transactions between genesis and that timestamp
64-
double dTxRate; //!< estimated number of transactions per second after that timestamp
65-
};
66-
67-
/**
68-
* CChainParams defines various tweakable parameters of a given instance of the
69-
* Bitcoin system.
70-
*/
71-
class CChainParams
72-
{
73-
public:
74-
enum Base58Type {
75-
PUBKEY_ADDRESS,
76-
SCRIPT_ADDRESS,
77-
SECRET_KEY,
78-
EXT_PUBLIC_KEY,
79-
EXT_SECRET_KEY,
80-
81-
MAX_BASE58_TYPES
82-
};
83-
84-
const Consensus::Params& GetConsensus() const { return consensus; }
85-
const CMessageHeader::MessageStartChars& MessageStart() const { return pchMessageStart; }
86-
uint16_t GetDefaultPort() const { return nDefaultPort; }
87-
uint16_t GetDefaultPort(Network net) const
88-
{
89-
return net == NET_I2P ? I2P_SAM31_PORT : GetDefaultPort();
90-
}
91-
uint16_t GetDefaultPort(const std::string& addr) const
92-
{
93-
CNetAddr a;
94-
return a.SetSpecial(addr) ? GetDefaultPort(a.GetNetwork()) : GetDefaultPort();
95-
}
96-
97-
const CBlock& GenesisBlock() const { return genesis; }
98-
/** Default value for -checkmempool and -checkblockindex argument */
99-
bool DefaultConsistencyChecks() const { return fDefaultConsistencyChecks; }
100-
/** Policy: Filter transactions that do not match well-defined patterns */
101-
bool RequireStandard() const { return fRequireStandard; }
102-
/** If this chain is exclusively used for testing */
103-
bool IsTestChain() const { return m_is_test_chain; }
104-
/** If this chain allows time to be mocked */
105-
bool IsMockableChain() const { return m_is_mockable_chain; }
106-
uint64_t PruneAfterHeight() const { return nPruneAfterHeight; }
107-
/** Minimum free space (in GB) needed for data directory */
108-
uint64_t AssumedBlockchainSize() const { return m_assumed_blockchain_size; }
109-
/** Minimum free space (in GB) needed for data directory when pruned; Does not include prune target*/
110-
uint64_t AssumedChainStateSize() const { return m_assumed_chain_state_size; }
111-
/** Whether it is possible to mine blocks on demand (no retargeting) */
112-
bool MineBlocksOnDemand() const { return consensus.fPowNoRetargeting; }
113-
/** Return the network string */
114-
std::string NetworkIDString() const { return strNetworkID; }
115-
/** Return the list of hostnames to look up for DNS seeds */
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-
//! Get allowed assumeutxo configuration.
123-
//! @see ChainstateManager
124-
const MapAssumeutxo& Assumeutxo() const { return m_assumeutxo_data; }
125-
126-
const ChainTxData& TxData() const { return chainTxData; }
127-
128-
/**
129-
* SigNetOptions holds configurations for creating a signet CChainParams.
130-
*/
131-
struct SigNetOptions {
132-
std::optional<std::vector<uint8_t>> challenge{};
133-
std::optional<std::vector<std::string>> seeds{};
134-
};
135-
136-
/**
137-
* VersionBitsParameters holds activation parameters
138-
*/
139-
struct VersionBitsParameters {
140-
int64_t start_time;
141-
int64_t timeout;
142-
int min_activation_height;
143-
};
144-
145-
/**
146-
* RegTestOptions holds configurations for creating a regtest CChainParams.
147-
*/
148-
struct RegTestOptions {
149-
std::unordered_map<Consensus::DeploymentPos, VersionBitsParameters> version_bits_parameters{};
150-
std::unordered_map<Consensus::BuriedDeployment, int> activation_heights{};
151-
bool fastprune{false};
152-
};
153-
154-
static std::unique_ptr<const CChainParams> RegTest(const RegTestOptions& options);
155-
static std::unique_ptr<const CChainParams> SigNet(const SigNetOptions& options);
156-
static std::unique_ptr<const CChainParams> Main();
157-
static std::unique_ptr<const CChainParams> TestNet();
158-
159-
protected:
160-
CChainParams() {}
161-
162-
Consensus::Params consensus;
163-
CMessageHeader::MessageStartChars pchMessageStart;
164-
uint16_t nDefaultPort;
165-
uint64_t nPruneAfterHeight;
166-
uint64_t m_assumed_blockchain_size;
167-
uint64_t m_assumed_chain_state_size;
168-
std::vector<std::string> vSeeds;
169-
std::vector<unsigned char> base58Prefixes[MAX_BASE58_TYPES];
170-
std::string bech32_hrp;
171-
std::string strNetworkID;
172-
CBlock genesis;
173-
std::vector<uint8_t> vFixedSeeds;
174-
bool fDefaultConsistencyChecks;
175-
bool fRequireStandard;
176-
bool m_is_test_chain;
177-
bool m_is_mockable_chain;
178-
CCheckpointData checkpointData;
179-
MapAssumeutxo m_assumeutxo_data;
180-
ChainTxData chainTxData;
181-
};
182-
18324
/**
18425
* Creates and returns a std::unique_ptr<CChainParams> of the chosen chain.
18526
* @returns a CChainParams* of the chosen chain.

0 commit comments

Comments
 (0)