diff options
author | Anthony Towns <aj@erisian.com.au> | 2020-12-29 11:19:06 +1000 |
---|---|---|
committer | Anthony Towns <aj@erisian.com.au> | 2021-06-30 08:19:12 +1000 |
commit | 0cfd6c6a8f929d5567ac41f95c21548f115efee5 (patch) | |
tree | fd396692805022b432022c45da6bb2a18b2fa54b /src/versionbits.h | |
parent | 8ee3e0bed5bf2cd3c7a68ca6ba6c65f7b9a72cca (diff) |
[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.
Diffstat (limited to 'src/versionbits.h')
-rw-r--r-- | src/versionbits.h | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/src/versionbits.h b/src/versionbits.h index 24279a0de4..4ede920803 100644 --- a/src/versionbits.h +++ b/src/versionbits.h @@ -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 |