2021-07-01 19:15:03 +02:00
|
|
|
// 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)
|
|
|
|
{
|
|
|
|
assert(Consensus::ValidDeployment(dep));
|
|
|
|
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 == 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));
|
|
|
|
return params.DeploymentHeight(dep) != std::numeric_limits<int>::max();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool DeploymentEnabled(const Consensus::Params& params, Consensus::DeploymentPos dep)
|
|
|
|
{
|
|
|
|
assert(Consensus::ValidDeployment(dep));
|
2021-07-15 08:34:31 +02:00
|
|
|
return params.vDeployments[dep].nStartTime != Consensus::BIP9Deployment::NEVER_ACTIVE;
|
2021-07-01 19:15:03 +02:00
|
|
|
}
|
|
|
|
|
2023-12-04 18:58:13 +01:00
|
|
|
/** this function is convenient helper for DIP0003 because 'active' and 'enforced' are different statuses for DIP0003 */
|
|
|
|
constexpr bool DeploymentDIP0003Enforced(const int nHeight, const Consensus::Params& params)
|
|
|
|
{
|
|
|
|
return nHeight >= params.DIP0003EnforcementHeight;
|
|
|
|
}
|
|
|
|
|
2021-07-01 19:15:03 +02:00
|
|
|
#endif // BITCOIN_DEPLOYMENTSTATUS_H
|