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 Oct 8, 2024
1 parent 728b26f commit 60b3c4b
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 @@ -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<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 @@ -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)
Expand All @@ -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")) {
Expand Down
1 change: 1 addition & 0 deletions src/chainparamsbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 13 additions & 0 deletions src/kernel/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<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 @@ -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;
Expand Down Expand Up @@ -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"});
Expand Down
4 changes: 4 additions & 0 deletions src/kernel/chainparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,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 @@ -158,6 +161,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 60b3c4b

Please sign in to comment.