|
| 1 | +// Copyright (c) 2020 The Bitcoin Core developers |
| 2 | +// Distributed under the MIT software license, see the accompanying |
| 3 | +// file COPYING or http://www.opensource.org/licenses/mit-license.php. |
| 4 | + |
| 5 | +#ifndef BITCOIN_DEPLOYMENTSTATUS_H |
| 6 | +#define BITCOIN_DEPLOYMENTSTATUS_H |
| 7 | + |
| 8 | +#include <chain.h> |
| 9 | +#include <versionbits.h> |
| 10 | + |
| 11 | +#include <limits> |
| 12 | + |
| 13 | +/** Global cache for versionbits deployment status */ |
| 14 | +extern VersionBitsCache g_versionbitscache; |
| 15 | + |
| 16 | +/** Determine if a deployment is active for the next block */ |
| 17 | +inline bool DeploymentActiveAfter(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::BuriedDeployment dep) |
| 18 | +{ |
| 19 | + assert(Consensus::ValidDeployment(dep)); |
| 20 | + return (pindexPrev == nullptr ? 0 : pindexPrev->nHeight + 1) >= params.DeploymentHeight(dep); |
| 21 | +} |
| 22 | + |
| 23 | +inline bool DeploymentActiveAfter(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::DeploymentPos dep) |
| 24 | +{ |
| 25 | + assert(Consensus::ValidDeployment(dep)); |
| 26 | + return ThresholdState::ACTIVE == g_versionbitscache.State(pindexPrev, params, dep); |
| 27 | +} |
| 28 | + |
| 29 | +/** Determine if a deployment is active for this block */ |
| 30 | +inline bool DeploymentActiveAt(const CBlockIndex& index, const Consensus::Params& params, Consensus::BuriedDeployment dep) |
| 31 | +{ |
| 32 | + assert(Consensus::ValidDeployment(dep)); |
| 33 | + return index.nHeight >= params.DeploymentHeight(dep); |
| 34 | +} |
| 35 | + |
| 36 | +inline bool DeploymentActiveAt(const CBlockIndex& index, const Consensus::Params& params, Consensus::DeploymentPos dep) |
| 37 | +{ |
| 38 | + assert(Consensus::ValidDeployment(dep)); |
| 39 | + return DeploymentActiveAfter(index.pprev, params, dep); |
| 40 | +} |
| 41 | + |
| 42 | +/** Determine if a deployment is enabled (can ever be active) */ |
| 43 | +inline bool DeploymentEnabled(const Consensus::Params& params, Consensus::BuriedDeployment dep) |
| 44 | +{ |
| 45 | + assert(Consensus::ValidDeployment(dep)); |
| 46 | + return params.DeploymentHeight(dep) != std::numeric_limits<int>::max(); |
| 47 | +} |
| 48 | + |
| 49 | +inline bool DeploymentEnabled(const Consensus::Params& params, Consensus::DeploymentPos dep) |
| 50 | +{ |
| 51 | + assert(Consensus::ValidDeployment(dep)); |
| 52 | + return params.vDeployments[dep].nTimeout != 0; |
| 53 | +} |
| 54 | + |
| 55 | +#endif // BITCOIN_DEPLOYMENTSTATUS_H |
0 commit comments