From 2d57e2521c00d9e9f04d67fa37cc169314f75cd6 Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Wed, 30 Aug 2023 01:24:54 +1000 Subject: [PATCH] chainparams: Add support for renouncing an HereticalDeployment --- src/chainparams.cpp | 22 ++++++++++++++++++++++ src/chainparamsbase.cpp | 1 + src/kernel/chainparams.cpp | 13 +++++++++++++ src/kernel/chainparams.h | 4 ++++ 4 files changed, 40 insertions(+) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 9ed55808749b0f..3583201c544395 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -23,6 +23,25 @@ using util::SplitString; +static void HandleRenounceArgs(const ArgsManager& args, CChainParams::RenounceParameters& renounce) +{ + if (!args.IsArgSet("-renounce")) return; + for (const std::string& dep_name : args.GetArgs("-renounce")) { + bool found = false; + for (int j = 0; j < (int)Consensus::MAX_VERSION_BITS_DEPLOYMENTS; ++j) { + if (dep_name == VersionBitsDeploymentInfo[j].name) { + renounce.emplace_back(static_cast(j)); + found = true; + LogPrintf("Disabling deployment %s\n", dep_name); + break; + } + } + if (!found) { + throw std::runtime_error(strprintf("Invalid deployment (%s)", dep_name)); + } + } +} + void ReadSigNetArgs(const ArgsManager& args, CChainParams::SigNetOptions& options) { if (args.IsArgSet("-signetseednode")) { @@ -39,6 +58,7 @@ void ReadSigNetArgs(const ArgsManager& args, CChainParams::SigNetOptions& option } options.challenge.emplace(*val); } + HandleRenounceArgs(args, options.renounce); } void ReadRegTestArgs(const ArgsManager& args, CChainParams::RegTestOptions& options) @@ -65,6 +85,8 @@ void ReadRegTestArgs(const ArgsManager& args, CChainParams::RegTestOptions& opti } } + HandleRenounceArgs(args, options.renounce); + if (!args.IsArgSet("-vbparams")) return; for (const std::string& strDeployment : args.GetArgs("-vbparams")) { diff --git a/src/chainparamsbase.cpp b/src/chainparamsbase.cpp index aadd04e509f22f..9efc62899dfe1a 100644 --- a/src/chainparamsbase.cpp +++ b/src/chainparamsbase.cpp @@ -20,6 +20,7 @@ void SetupChainParamsBaseOptions(ArgsManager& argsman) argsman.AddArg("-testnet", "Use the testnet3 chain. Equivalent to -chain=test. Support for testnet3 is deprecated and will be removed in an upcoming release. Consider moving to testnet4 now by using -testnet4.", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS); argsman.AddArg("-testnet4", "Use the testnet4 chain. Equivalent to -chain=testnet4.", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS); argsman.AddArg("-vbparams=deployment:start:end[:min_activation_height]", "Use given start/end times and min_activation_height for specified version bits deployment (regtest-only)", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::CHAINPARAMS); + argsman.AddArg("-renounce=deployment", "Unconditionally disable an heretical deployment attempt", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::CHAINPARAMS); argsman.AddArg("-signet", "Use the signet chain. Equivalent to -chain=signet. Note that the network is defined by the -signetchallenge parameter", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS); argsman.AddArg("-signetchallenge", "Blocks must satisfy the given script to be considered valid (only for signet networks; defaults to the global default signet test network challenge)", ArgsManager::ALLOW_ANY | ArgsManager::DISALLOW_NEGATION, OptionsCategory::CHAINPARAMS); argsman.AddArg("-signetseednode", "Specify a seed node for the signet network, in the hostname[:port] format, e.g. sig.net:1234 (may be used multiple times to specify multiple seed nodes; defaults to the global default signet test network seed node(s))", ArgsManager::ALLOW_ANY | ArgsManager::DISALLOW_NEGATION, OptionsCategory::CHAINPARAMS); diff --git a/src/kernel/chainparams.cpp b/src/kernel/chainparams.cpp index a656ac12d0b95c..ea5ff0b586dbf3 100644 --- a/src/kernel/chainparams.cpp +++ b/src/kernel/chainparams.cpp @@ -75,6 +75,15 @@ static CBlock CreateGenesisBlock(uint32_t nTime, uint32_t nNonce, uint32_t nBits return CreateGenesisBlock(pszTimestamp, genesisOutputScript, nTime, nNonce, nBits, nVersion, genesisReward); } +template +static void RenounceDeployments(const CChainParams::RenounceParameters& renounce, Consensus::HereticalDeployment (&vDeployments)[N]) +{ + for (Consensus::BuriedDeployment dep : renounce) { + vDeployments[dep].nStartTime = Consensus::HereticalDeployment::NEVER_ACTIVE; + vDeployments[dep].nTimeout = Consensus::HereticalDeployment::NO_TIMEOUT; + } +} + namespace { struct SetupDeployment { @@ -473,6 +482,8 @@ class SigNetParams : public CChainParams { consensus.powLimit = uint256{"00000377ae000000000000000000000000000000000000000000000000000000"}; consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY] = SetupDeployment{.activate = 0x30000000, .abandon = 0, .never = true}; + RenounceDeployments(options.renounce, consensus.vDeployments); + // message start is defined as the first 4 bytes of the sha256d of the block script HashWriter h{}; h << consensus.signet_challenge; @@ -584,6 +595,8 @@ class CRegTestParams : public CChainParams consensus.vDeployments[deployment_pos].nTimeout = version_bits_params.timeout; } + RenounceDeployments(opts.renounce, consensus.vDeployments); + genesis = CreateGenesisBlock(1296688602, 2, 0x207fffff, 1, 50 * COIN); consensus.hashGenesisBlock = genesis.GetHash(); assert(consensus.hashGenesisBlock == uint256{"0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206"}); diff --git a/src/kernel/chainparams.h b/src/kernel/chainparams.h index 493a7f44c9730c..4a56b4ac471ca3 100644 --- a/src/kernel/chainparams.h +++ b/src/kernel/chainparams.h @@ -136,12 +136,15 @@ class CChainParams const ChainTxData& TxData() const { return chainTxData; } + using RenounceParameters = std::vector; + /** * SigNetOptions holds configurations for creating a signet CChainParams. */ struct SigNetOptions { std::optional> challenge{}; std::optional> seeds{}; + RenounceParameters renounce{}; }; /** @@ -158,6 +161,7 @@ class CChainParams struct RegTestOptions { std::unordered_map version_bits_parameters{}; std::unordered_map activation_heights{}; + RenounceParameters renounce{}; bool fastprune{false}; };