mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-04 10:12:28 +02:00
chainparams: encapsulate deployment configuration logic
This encapsulates the soft fork configuration logic as set by the `-testactivationheight` (for buried deployments) and `-vbparams` (for version bits deployments) options which for the moment are regtest-only, in order to make them available on other networks as well in the next commit. Can be reviewed using git's `--color-moved` option with `--color-moved-ws=allow-indentation-change`.
This commit is contained in:
committed by
Antoine Poinsot
parent
b796bf44f3
commit
df7ed5f355
@@ -23,29 +23,8 @@
|
||||
|
||||
using util::SplitString;
|
||||
|
||||
void ReadSigNetArgs(const ArgsManager& args, CChainParams::SigNetOptions& options)
|
||||
static void HandleDeploymentArgs(const ArgsManager& args, CChainParams::DeploymentOptions& options)
|
||||
{
|
||||
if (!args.GetArgs("-signetseednode").empty()) {
|
||||
options.seeds.emplace(args.GetArgs("-signetseednode"));
|
||||
}
|
||||
if (!args.GetArgs("-signetchallenge").empty()) {
|
||||
const auto signet_challenge = args.GetArgs("-signetchallenge");
|
||||
if (signet_challenge.size() != 1) {
|
||||
throw std::runtime_error("-signetchallenge cannot be multiple values.");
|
||||
}
|
||||
const auto val{TryParseHex<uint8_t>(signet_challenge[0])};
|
||||
if (!val) {
|
||||
throw std::runtime_error(strprintf("-signetchallenge must be hex, not '%s'.", signet_challenge[0]));
|
||||
}
|
||||
options.challenge.emplace(*val);
|
||||
}
|
||||
}
|
||||
|
||||
void ReadRegTestArgs(const ArgsManager& args, CChainParams::RegTestOptions& options)
|
||||
{
|
||||
if (auto value = args.GetBoolArg("-fastprune")) options.fastprune = *value;
|
||||
if (HasTestOption(args, "bip94")) options.enforce_bip94 = true;
|
||||
|
||||
for (const std::string& arg : args.GetArgs("-testactivationheight")) {
|
||||
const auto found{arg.find('@')};
|
||||
if (found == std::string::npos) {
|
||||
@@ -107,6 +86,32 @@ void ReadRegTestArgs(const ArgsManager& args, CChainParams::RegTestOptions& opti
|
||||
}
|
||||
}
|
||||
|
||||
void ReadSigNetArgs(const ArgsManager& args, CChainParams::SigNetOptions& options)
|
||||
{
|
||||
if (!args.GetArgs("-signetseednode").empty()) {
|
||||
options.seeds.emplace(args.GetArgs("-signetseednode"));
|
||||
}
|
||||
if (!args.GetArgs("-signetchallenge").empty()) {
|
||||
const auto signet_challenge = args.GetArgs("-signetchallenge");
|
||||
if (signet_challenge.size() != 1) {
|
||||
throw std::runtime_error("-signetchallenge cannot be multiple values.");
|
||||
}
|
||||
const auto val{TryParseHex<uint8_t>(signet_challenge[0])};
|
||||
if (!val) {
|
||||
throw std::runtime_error(strprintf("-signetchallenge must be hex, not '%s'.", signet_challenge[0]));
|
||||
}
|
||||
options.challenge.emplace(*val);
|
||||
}
|
||||
}
|
||||
|
||||
void ReadRegTestArgs(const ArgsManager& args, CChainParams::RegTestOptions& options)
|
||||
{
|
||||
if (auto value = args.GetBoolArg("-fastprune")) options.fastprune = *value;
|
||||
if (HasTestOption(args, "bip94")) options.enforce_bip94 = true;
|
||||
|
||||
HandleDeploymentArgs(args, options.dep_opts);
|
||||
}
|
||||
|
||||
static std::unique_ptr<const CChainParams> globalChainParams;
|
||||
|
||||
const CChainParams &Params() {
|
||||
|
||||
@@ -72,6 +72,35 @@ static CBlock CreateGenesisBlock(uint32_t nTime, uint32_t nNonce, uint32_t nBits
|
||||
return CreateGenesisBlock(pszTimestamp, genesisOutputScript, nTime, nNonce, nBits, nVersion, genesisReward);
|
||||
}
|
||||
|
||||
void CChainParams::ApplyDeploymentOptions(const DeploymentOptions& opts)
|
||||
{
|
||||
for (const auto& [dep, height] : opts.activation_heights) {
|
||||
switch (dep) {
|
||||
case Consensus::BuriedDeployment::DEPLOYMENT_SEGWIT:
|
||||
consensus.SegwitHeight = int{height};
|
||||
break;
|
||||
case Consensus::BuriedDeployment::DEPLOYMENT_HEIGHTINCB:
|
||||
consensus.BIP34Height = int{height};
|
||||
break;
|
||||
case Consensus::BuriedDeployment::DEPLOYMENT_DERSIG:
|
||||
consensus.BIP66Height = int{height};
|
||||
break;
|
||||
case Consensus::BuriedDeployment::DEPLOYMENT_CLTV:
|
||||
consensus.BIP65Height = int{height};
|
||||
break;
|
||||
case Consensus::BuriedDeployment::DEPLOYMENT_CSV:
|
||||
consensus.CSVHeight = int{height};
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto& [deployment_pos, version_bits_params] : opts.version_bits_parameters) {
|
||||
consensus.vDeployments[deployment_pos].nStartTime = version_bits_params.start_time;
|
||||
consensus.vDeployments[deployment_pos].nTimeout = version_bits_params.timeout;
|
||||
consensus.vDeployments[deployment_pos].min_activation_height = version_bits_params.min_activation_height;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Main network on which people trade goods and services.
|
||||
*/
|
||||
@@ -566,31 +595,7 @@ public:
|
||||
m_assumed_blockchain_size = 0;
|
||||
m_assumed_chain_state_size = 0;
|
||||
|
||||
for (const auto& [dep, height] : opts.activation_heights) {
|
||||
switch (dep) {
|
||||
case Consensus::BuriedDeployment::DEPLOYMENT_SEGWIT:
|
||||
consensus.SegwitHeight = int{height};
|
||||
break;
|
||||
case Consensus::BuriedDeployment::DEPLOYMENT_HEIGHTINCB:
|
||||
consensus.BIP34Height = int{height};
|
||||
break;
|
||||
case Consensus::BuriedDeployment::DEPLOYMENT_DERSIG:
|
||||
consensus.BIP66Height = int{height};
|
||||
break;
|
||||
case Consensus::BuriedDeployment::DEPLOYMENT_CLTV:
|
||||
consensus.BIP65Height = int{height};
|
||||
break;
|
||||
case Consensus::BuriedDeployment::DEPLOYMENT_CSV:
|
||||
consensus.CSVHeight = int{height};
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto& [deployment_pos, version_bits_params] : opts.version_bits_parameters) {
|
||||
consensus.vDeployments[deployment_pos].nStartTime = version_bits_params.start_time;
|
||||
consensus.vDeployments[deployment_pos].nTimeout = version_bits_params.timeout;
|
||||
consensus.vDeployments[deployment_pos].min_activation_height = version_bits_params.min_activation_height;
|
||||
}
|
||||
ApplyDeploymentOptions(opts.dep_opts);
|
||||
|
||||
genesis = CreateGenesisBlock(1296688602, 2, 0x207fffff, 1, 50 * COIN);
|
||||
consensus.hashGenesisBlock = genesis.GetHash();
|
||||
|
||||
@@ -127,14 +127,6 @@ public:
|
||||
|
||||
const ChainTxData& TxData() const { return chainTxData; }
|
||||
|
||||
/**
|
||||
* SigNetOptions holds configurations for creating a signet CChainParams.
|
||||
*/
|
||||
struct SigNetOptions {
|
||||
std::optional<std::vector<uint8_t>> challenge{};
|
||||
std::optional<std::vector<std::string>> seeds{};
|
||||
};
|
||||
|
||||
/**
|
||||
* VersionBitsParameters holds activation parameters
|
||||
*/
|
||||
@@ -144,12 +136,24 @@ public:
|
||||
int min_activation_height;
|
||||
};
|
||||
|
||||
struct DeploymentOptions {
|
||||
std::unordered_map<Consensus::DeploymentPos, VersionBitsParameters> version_bits_parameters{};
|
||||
std::unordered_map<Consensus::BuriedDeployment, int> activation_heights{};
|
||||
};
|
||||
|
||||
/**
|
||||
* SigNetOptions holds configurations for creating a signet CChainParams.
|
||||
*/
|
||||
struct SigNetOptions {
|
||||
std::optional<std::vector<uint8_t>> challenge{};
|
||||
std::optional<std::vector<std::string>> seeds{};
|
||||
};
|
||||
|
||||
/**
|
||||
* RegTestOptions holds configurations for creating a regtest CChainParams.
|
||||
*/
|
||||
struct RegTestOptions {
|
||||
std::unordered_map<Consensus::DeploymentPos, VersionBitsParameters> version_bits_parameters{};
|
||||
std::unordered_map<Consensus::BuriedDeployment, int> activation_heights{};
|
||||
DeploymentOptions dep_opts{};
|
||||
bool fastprune{false};
|
||||
bool enforce_bip94{false};
|
||||
};
|
||||
@@ -180,6 +184,8 @@ protected:
|
||||
std::vector<AssumeutxoData> m_assumeutxo_data;
|
||||
ChainTxData chainTxData;
|
||||
HeadersSyncParams m_headers_sync_params;
|
||||
|
||||
void ApplyDeploymentOptions(const DeploymentOptions& opts);
|
||||
};
|
||||
|
||||
std::optional<ChainType> GetNetworkForMagic(const MessageStartChars& pchMessageStart);
|
||||
|
||||
Reference in New Issue
Block a user