-
Notifications
You must be signed in to change notification settings - Fork 35.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce deploymentstatus #19438
Introduce deploymentstatus #19438
Changes from all commits
36a4ba0
eccd736
2b0d291
de55304
c64b2c6
ea68b3a
92f48f3
8ee3e0b
0cfd6c6
4a69b4d
c5f3672
e48826a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -11,13 +11,25 @@ | |||||
|
||||||
namespace Consensus { | ||||||
|
||||||
enum DeploymentPos | ||||||
enum BuriedDeployment : int16_t | ||||||
{ | ||||||
// buried deployments get negative values to avoid overlap with DeploymentPos | ||||||
DEPLOYMENT_HEIGHTINCB = std::numeric_limits<int16_t>::min(), | ||||||
DEPLOYMENT_CLTV, | ||||||
DEPLOYMENT_DERSIG, | ||||||
DEPLOYMENT_CSV, | ||||||
DEPLOYMENT_SEGWIT, | ||||||
}; | ||||||
constexpr bool ValidDeployment(BuriedDeployment dep) { return DEPLOYMENT_HEIGHTINCB <= dep && dep <= DEPLOYMENT_SEGWIT; } | ||||||
|
||||||
enum DeploymentPos : uint16_t | ||||||
{ | ||||||
DEPLOYMENT_TESTDUMMY, | ||||||
DEPLOYMENT_TAPROOT, // Deployment of Schnorr/Taproot (BIPs 340-342) | ||||||
// NOTE: Also add new deployments to VersionBitsDeploymentInfo in versionbits.cpp | ||||||
// NOTE: Also add new deployments to VersionBitsDeploymentInfo in deploymentinfo.cpp | ||||||
MAX_VERSION_BITS_DEPLOYMENTS | ||||||
}; | ||||||
constexpr bool ValidDeployment(DeploymentPos dep) { return DEPLOYMENT_TESTDUMMY <= dep && dep <= DEPLOYMENT_TAPROOT; } | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in 8b2aa89 nit: couldn't this be
Suggested change
|
||||||
|
||||||
/** | ||||||
* Struct for each individual consensus rule change using BIP9. | ||||||
|
@@ -100,7 +112,25 @@ struct Params { | |||||
*/ | ||||||
bool signet_blocks{false}; | ||||||
std::vector<uint8_t> signet_challenge; | ||||||
|
||||||
int DeploymentHeight(BuriedDeployment dep) const | ||||||
{ | ||||||
switch (dep) { | ||||||
case DEPLOYMENT_HEIGHTINCB: | ||||||
return BIP34Height; | ||||||
case DEPLOYMENT_CLTV: | ||||||
return BIP65Height; | ||||||
case DEPLOYMENT_DERSIG: | ||||||
return BIP66Height; | ||||||
case DEPLOYMENT_CSV: | ||||||
return CSVHeight; | ||||||
case DEPLOYMENT_SEGWIT: | ||||||
return SegwitHeight; | ||||||
} // no default case, so the compiler can warn about missing cases | ||||||
return std::numeric_limits<int>::max(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Could use an optional as return value instead of this to signal if no height was found? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That would mean checking and dereferencing the optional at every call site, which doesn't seem useful. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or maybe turn this dead code into an |
||||||
} | ||||||
}; | ||||||
|
||||||
} // namespace Consensus | ||||||
|
||||||
#endif // BITCOIN_CONSENSUS_PARAMS_H |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright (c) 2016-2020 The Bitcoin Core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#include <deploymentinfo.h> | ||
|
||
#include <consensus/params.h> | ||
|
||
const struct VBDeploymentInfo VersionBitsDeploymentInfo[Consensus::MAX_VERSION_BITS_DEPLOYMENTS] = { | ||
{ | ||
/*.name =*/ "testdummy", | ||
/*.gbt_force =*/ true, | ||
}, | ||
{ | ||
/*.name =*/ "taproot", | ||
/*.gbt_force =*/ true, | ||
}, | ||
}; | ||
|
||
std::string DeploymentName(Consensus::BuriedDeployment dep) | ||
{ | ||
assert(ValidDeployment(dep)); | ||
switch (dep) { | ||
case Consensus::DEPLOYMENT_HEIGHTINCB: | ||
return "bip34"; | ||
case Consensus::DEPLOYMENT_CLTV: | ||
return "bip65"; | ||
case Consensus::DEPLOYMENT_DERSIG: | ||
return "bip66"; | ||
case Consensus::DEPLOYMENT_CSV: | ||
return "csv"; | ||
case Consensus::DEPLOYMENT_SEGWIT: | ||
return "segwit"; | ||
} // no default case, so the compiler can warn about missing cases | ||
return ""; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Could have given a default that provides more context like "unknown" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't matter too much, as it is dead code. Empty string might even make it easier to run There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or just |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (c) 2016-2018 The Bitcoin Core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#ifndef BITCOIN_DEPLOYMENTINFO_H | ||
#define BITCOIN_DEPLOYMENTINFO_H | ||
|
||
#include <consensus/params.h> | ||
|
||
#include <string> | ||
|
||
struct VBDeploymentInfo { | ||
/** Deployment name */ | ||
const char *name; | ||
/** Whether GBT clients can safely ignore this rule in simplified usage */ | ||
bool gbt_force; | ||
}; | ||
|
||
extern const VBDeploymentInfo VersionBitsDeploymentInfo[Consensus::MAX_VERSION_BITS_DEPLOYMENTS]; | ||
|
||
std::string DeploymentName(Consensus::BuriedDeployment dep); | ||
|
||
inline std::string DeploymentName(Consensus::DeploymentPos pos) | ||
{ | ||
assert(Consensus::ValidDeployment(pos)); | ||
return VersionBitsDeploymentInfo[pos].name; | ||
jnewbery marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
#endif // BITCOIN_DEPLOYMENTINFO_H |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright (c) 2020 The Bitcoin Core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#include <deploymentstatus.h> | ||
|
||
#include <consensus/params.h> | ||
#include <versionbits.h> | ||
|
||
VersionBitsCache g_versionbitscache; | ||
|
||
/* Basic sanity checking for BuriedDeployment/DeploymentPos enums and | ||
* ValidDeployment check */ | ||
|
||
static_assert(ValidDeployment(Consensus::DEPLOYMENT_TESTDUMMY), "sanity check of DeploymentPos failed (TESTDUMMY not valid)"); | ||
static_assert(!ValidDeployment(Consensus::MAX_VERSION_BITS_DEPLOYMENTS), "sanity check of DeploymentPos failed (MAX value considered valid)"); | ||
static_assert(!ValidDeployment(static_cast<Consensus::BuriedDeployment>(Consensus::DEPLOYMENT_TESTDUMMY)), "sanity check of BuriedDeployment failed (overlaps with DeploymentPos)"); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright (c) 2020 The Bitcoin Core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#ifndef BITCOIN_DEPLOYMENTSTATUS_H | ||
#define BITCOIN_DEPLOYMENTSTATUS_H | ||
|
||
#include <chain.h> | ||
#include <versionbits.h> | ||
|
||
#include <limits> | ||
|
||
/** Global cache for versionbits deployment status */ | ||
extern VersionBitsCache g_versionbitscache; | ||
|
||
/** Determine if a deployment is active for the next block */ | ||
inline bool DeploymentActiveAfter(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::BuriedDeployment dep) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This dispatch scares me a bit unless we use enum class -- enums could coerce poorly right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope; int (and the like) won't automatically coerce to enum, so with
(even if it did, which enum it coerced to is ambiguous between the two types, resulting in a failure like |
||
{ | ||
assert(Consensus::ValidDeployment(dep)); | ||
return (pindexPrev == nullptr ? 0 : pindexPrev->nHeight + 1) >= params.DeploymentHeight(dep); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: You could do |
||
} | ||
|
||
inline bool DeploymentActiveAfter(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::DeploymentPos dep) | ||
ajtowns marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
assert(Consensus::ValidDeployment(dep)); | ||
return ThresholdState::ACTIVE == g_versionbitscache.State(pindexPrev, params, dep); | ||
} | ||
|
||
/** Determine if a deployment is active for this block */ | ||
inline bool DeploymentActiveAt(const CBlockIndex& index, const Consensus::Params& params, Consensus::BuriedDeployment dep) | ||
{ | ||
assert(Consensus::ValidDeployment(dep)); | ||
return index.nHeight >= params.DeploymentHeight(dep); | ||
} | ||
|
||
inline bool DeploymentActiveAt(const CBlockIndex& index, const Consensus::Params& params, Consensus::DeploymentPos dep) | ||
{ | ||
assert(Consensus::ValidDeployment(dep)); | ||
return DeploymentActiveAfter(index.pprev, params, dep); | ||
} | ||
|
||
/** Determine if a deployment is enabled (can ever be active) */ | ||
inline bool DeploymentEnabled(const Consensus::Params& params, Consensus::BuriedDeployment dep) | ||
{ | ||
assert(Consensus::ValidDeployment(dep)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: This check is repeated three times only to protect |
||
return params.DeploymentHeight(dep) != std::numeric_limits<int>::max(); | ||
} | ||
|
||
inline bool DeploymentEnabled(const Consensus::Params& params, Consensus::DeploymentPos dep) | ||
{ | ||
assert(Consensus::ValidDeployment(dep)); | ||
return params.vDeployments[dep].nTimeout != 0; | ||
maflcko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
#endif // BITCOIN_DEPLOYMENTSTATUS_H |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very minor nit: If you add a
DEPLOYMENT_BURIED_MAX
and then usedep < DEPLOYMENT_BURIED_MAX
instead ofdep <= DEPLOYMENT_SEGWIT
then this line wouldn't need to change when something is buried. But I am not sure if it's an improvement overall.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't want to add a
DEPLOYMENT_BURIED_MAX
since that would then need to be included in anyswitch
statements.