[refactor] versionbits: make VersionBitsCache a full class

Moves the VersionBits* functions to be methods of the cache class,
and makes the cache and its lock private to the class.
This commit is contained in:
Anthony Towns
2020-12-29 11:19:06 +10:00
parent 8ee3e0bed5
commit 0cfd6c6a8f
7 changed files with 39 additions and 34 deletions

View File

@@ -73,22 +73,27 @@ public:
int GetStateSinceHeightFor(const CBlockIndex* pindexPrev, const Consensus::Params& params, ThresholdConditionCache& cache) const;
};
/** BIP 9 allows multiple softforks to be deployed in parallel. We cache per-period state for every one of them
* keyed by the bit position used to signal support. */
struct VersionBitsCache
/** BIP 9 allows multiple softforks to be deployed in parallel. We cache
* per-period state for every one of them. */
class VersionBitsCache
{
Mutex mutex;
ThresholdConditionCache caches[Consensus::MAX_VERSION_BITS_DEPLOYMENTS] GUARDED_BY(mutex);
private:
Mutex m_mutex;
ThresholdConditionCache m_caches[Consensus::MAX_VERSION_BITS_DEPLOYMENTS] GUARDED_BY(m_mutex);
public:
/** Get the numerical statistics for a given deployment for the signalling period that includes the block after pindexPrev. */
static BIP9Stats Statistics(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::DeploymentPos pos);
static uint32_t Mask(const Consensus::Params& params, Consensus::DeploymentPos pos);
/** Get the BIP9 state for a given deployment for the block after pindexPrev. */
ThresholdState State(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::DeploymentPos pos);
/** Get the block height at which the BIP9 deployment switched into the state for the block after pindexPrev. */
int StateSinceHeight(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::DeploymentPos pos);
void Clear();
};
/** Get the BIP9 state for a given deployment for the block after pindexPrev. */
ThresholdState VersionBitsState(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::DeploymentPos pos, VersionBitsCache& cache);
/** Get the numerical statistics for a given deployment for the signalling period that includes the block after pindexPrev. */
BIP9Stats VersionBitsStatistics(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::DeploymentPos pos);
/** Get the block height at which the BIP9 deployment switched into the state for the block after pindexPrev. */
int VersionBitsStateSinceHeight(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::DeploymentPos pos, VersionBitsCache& cache);
uint32_t VersionBitsMask(const Consensus::Params& params, Consensus::DeploymentPos pos);
#endif // BITCOIN_VERSIONBITS_H