From 2074dbc736a58373edac73207d76b5440f201b20 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 ffd43f66149f84..179a11069c9de9 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -21,6 +21,25 @@ #include #include +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")) { @@ -37,6 +56,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) @@ -63,6 +83,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 8cbf9e85e0cad2..1b9c4fd10b3006 100644 --- a/src/chainparamsbase.cpp +++ b/src/chainparamsbase.cpp @@ -19,6 +19,7 @@ void SetupChainParamsBaseOptions(ArgsManager& argsman) argsman.AddArg("-testactivationheight=name@height.", "Set the activation height of 'name' (segwit, bip34, dersig, cltv, csv). (regtest-only)", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST); argsman.AddArg("-testnet", "Use the test chain. Equivalent to -chain=test.", 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 ab9ef3d91bc81a..c1a83d26f5232f 100644 --- a/src/kernel/chainparams.cpp +++ b/src/kernel/chainparams.cpp @@ -65,6 +65,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 { @@ -362,6 +371,8 @@ class SigNetParams : public CChainParams { consensus.powLimit = uint256S("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; @@ -472,6 +483,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 == uint256S("0x0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206")); diff --git a/src/kernel/chainparams.h b/src/kernel/chainparams.h index f2453fde7821c4..65312a972e931c 100644 --- a/src/kernel/chainparams.h +++ b/src/kernel/chainparams.h @@ -135,12 +135,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{}; }; /** @@ -157,6 +160,7 @@ class CChainParams struct RegTestOptions { std::unordered_map version_bits_parameters{}; std::unordered_map activation_heights{}; + RenounceParameters renounce{}; bool fastprune{false}; };