Skip to content

Commit 57fce06

Browse files
ajtownshebasto
authored andcommitted
consensus/params: simplify ValidDeployment check to avoid gcc warning
Github-Pull: bitcoin#22597 Rebased-From: 0591710
1 parent e9d30fb commit 57fce06

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/consensus/params.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ enum BuriedDeployment : int16_t {
2323
DEPLOYMENT_CSV,
2424
DEPLOYMENT_SEGWIT,
2525
};
26-
constexpr bool ValidDeployment(BuriedDeployment dep) { return DEPLOYMENT_HEIGHTINCB <= dep && dep <= DEPLOYMENT_SEGWIT; }
26+
constexpr bool ValidDeployment(BuriedDeployment dep) { return dep <= DEPLOYMENT_SEGWIT; }
2727

2828
enum DeploymentPos : uint16_t {
2929
DEPLOYMENT_TESTDUMMY,
3030
DEPLOYMENT_TAPROOT, // Deployment of Schnorr/Taproot (BIPs 340-342)
3131
// NOTE: Also add new deployments to VersionBitsDeploymentInfo in deploymentinfo.cpp
3232
MAX_VERSION_BITS_DEPLOYMENTS
3333
};
34-
constexpr bool ValidDeployment(DeploymentPos dep) { return DEPLOYMENT_TESTDUMMY <= dep && dep <= DEPLOYMENT_TAPROOT; }
34+
constexpr bool ValidDeployment(DeploymentPos dep) { return dep < MAX_VERSION_BITS_DEPLOYMENTS; }
3535

3636
/**
3737
* Struct for each individual consensus rule change using BIP9.

src/deploymentstatus.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include <consensus/params.h>
88
#include <versionbits.h>
99

10+
#include <type_traits>
11+
1012
VersionBitsCache g_versionbitscache;
1113

1214
/* Basic sanity checking for BuriedDeployment/DeploymentPos enums and
@@ -15,3 +17,18 @@ VersionBitsCache g_versionbitscache;
1517
static_assert(ValidDeployment(Consensus::DEPLOYMENT_TESTDUMMY), "sanity check of DeploymentPos failed (TESTDUMMY not valid)");
1618
static_assert(!ValidDeployment(Consensus::MAX_VERSION_BITS_DEPLOYMENTS), "sanity check of DeploymentPos failed (MAX value considered valid)");
1719
static_assert(!ValidDeployment(static_cast<Consensus::BuriedDeployment>(Consensus::DEPLOYMENT_TESTDUMMY)), "sanity check of BuriedDeployment failed (overlaps with DeploymentPos)");
20+
21+
/* ValidDeployment only checks upper bounds for ensuring validity.
22+
* This checks that the lowest possible value or the type is also a
23+
* (specific) valid deployment so that lower bounds don't need to be checked.
24+
*/
25+
26+
template<typename T, T x>
27+
static constexpr bool is_minimum()
28+
{
29+
using U = typename std::underlying_type<T>::type;
30+
return x == std::numeric_limits<U>::min();
31+
}
32+
33+
static_assert(is_minimum<Consensus::BuriedDeployment, Consensus::DEPLOYMENT_HEIGHTINCB>(), "heightincb is not minimum value for BuriedDeployment");
34+
static_assert(is_minimum<Consensus::DeploymentPos, Consensus::DEPLOYMENT_TESTDUMMY>(), "testdummy is not minimum value for DeploymentPos");

0 commit comments

Comments
 (0)