Skip to content

Commit

Permalink
chainparams: Add support for renouncing an HereticalDeployment
Browse files Browse the repository at this point in the history
  • Loading branch information
ajtowns committed May 1, 2024
1 parent 7b51b8a commit d74f1ae
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,25 @@
#include <stdexcept>
#include <vector>

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<Consensus::BuriedDeployment>(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")) {
Expand All @@ -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)
Expand All @@ -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")) {
Expand Down
1 change: 1 addition & 0 deletions src/chainparamsbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 13 additions & 0 deletions src/kernel/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_t N>
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
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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"));
Expand Down
4 changes: 4 additions & 0 deletions src/kernel/chainparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,15 @@ class CChainParams

const ChainTxData& TxData() const { return chainTxData; }

using RenounceParameters = std::vector<Consensus::BuriedDeployment>;

/**
* SigNetOptions holds configurations for creating a signet CChainParams.
*/
struct SigNetOptions {
std::optional<std::vector<uint8_t>> challenge{};
std::optional<std::vector<std::string>> seeds{};
RenounceParameters renounce{};
};

/**
Expand All @@ -157,6 +160,7 @@ class CChainParams
struct RegTestOptions {
std::unordered_map<Consensus::DeploymentPos, VersionBitsParameters> version_bits_parameters{};
std::unordered_map<Consensus::BuriedDeployment, int> activation_heights{};
RenounceParameters renounce{};
bool fastprune{false};
};

Expand Down

0 comments on commit d74f1ae

Please sign in to comment.