diff options
author | Anthony Towns <aj@erisian.com.au> | 2020-07-03 04:01:23 +1000 |
---|---|---|
committer | Anthony Towns <aj@erisian.com.au> | 2021-06-30 08:18:58 +1000 |
commit | de55304f6e7a8b607e6b3fc7436de50910747b0c (patch) | |
tree | ce1cb7ee0bcad78cb327650e0c4cb5e51b28074a /src/deploymentstatus.h | |
parent | 2b0d291da8f479739ff394dd92801da8c40b9f8e (diff) |
[refactor] Add versionbits deployments to deploymentstatus.h
Adds support for versionbits deployments to DeploymentEnabled,
DeploymentActiveAfter and DeploymentActiveAt. Also moves versionbitscache
from validation to deploymentstatus.
Diffstat (limited to 'src/deploymentstatus.h')
-rw-r--r-- | src/deploymentstatus.h | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/deploymentstatus.h b/src/deploymentstatus.h index 32190e369d..327a5f7892 100644 --- a/src/deploymentstatus.h +++ b/src/deploymentstatus.h @@ -6,9 +6,13 @@ #define BITCOIN_DEPLOYMENTSTATUS_H #include <chain.h> +#include <versionbits.h> #include <limits> +/** Global cache for versionbits deployment status */ +extern VersionBitsCache versionbitscache; + /** Determine if a deployment is active for the next block */ inline bool DeploymentActiveAfter(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::BuriedDeployment dep) { @@ -16,6 +20,12 @@ inline bool DeploymentActiveAfter(const CBlockIndex* pindexPrev, const Consensus return (pindexPrev == nullptr ? 0 : pindexPrev->nHeight + 1) >= params.DeploymentHeight(dep); } +inline bool DeploymentActiveAfter(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::DeploymentPos dep) +{ + assert(Consensus::ValidDeployment(dep)); + return ThresholdState::ACTIVE == VersionBitsState(pindexPrev, params, dep, versionbitscache); +} + /** Determine if a deployment is active for this block */ inline bool DeploymentActiveAt(const CBlockIndex& index, const Consensus::Params& params, Consensus::BuriedDeployment dep) { @@ -23,6 +33,12 @@ inline bool DeploymentActiveAt(const CBlockIndex& index, const Consensus::Params 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) { @@ -30,4 +46,10 @@ inline bool DeploymentEnabled(const Consensus::Params& params, Consensus::Buried 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; +} + #endif // BITCOIN_DEPLOYMENTSTATUS_H |