Merge #10114: [tests] sync_with_ping should assert that ping hasn't timed out
[bitcoinplatinum.git] / src / versionbits.h
blob7a929266aa24c27f5d5695d61c432e4cdb84f80d
1 // Copyright (c) 2016 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.
5 #ifndef BITCOIN_CONSENSUS_VERSIONBITS
6 #define BITCOIN_CONSENSUS_VERSIONBITS
8 #include "chain.h"
9 #include <map>
11 /** What block version to use for new blocks (pre versionbits) */
12 static const int32_t VERSIONBITS_LAST_OLD_BLOCK_VERSION = 4;
13 /** What bits to set in version for versionbits blocks */
14 static const int32_t VERSIONBITS_TOP_BITS = 0x20000000UL;
15 /** What bitmask determines whether versionbits is in use */
16 static const int32_t VERSIONBITS_TOP_MASK = 0xE0000000UL;
17 /** Total bits available for versionbits */
18 static const int32_t VERSIONBITS_NUM_BITS = 29;
20 enum ThresholdState {
21 THRESHOLD_DEFINED,
22 THRESHOLD_STARTED,
23 THRESHOLD_LOCKED_IN,
24 THRESHOLD_ACTIVE,
25 THRESHOLD_FAILED,
28 // A map that gives the state for blocks whose height is a multiple of Period().
29 // The map is indexed by the block's parent, however, so all keys in the map
30 // will either be NULL or a block with (height + 1) % Period() == 0.
31 typedef std::map<const CBlockIndex*, ThresholdState> ThresholdConditionCache;
33 struct BIP9DeploymentInfo {
34 /** Deployment name */
35 const char *name;
36 /** Whether GBT clients can safely ignore this rule in simplified usage */
37 bool gbt_force;
40 extern const struct BIP9DeploymentInfo VersionBitsDeploymentInfo[];
42 /**
43 * Abstract class that implements BIP9-style threshold logic, and caches results.
45 class AbstractThresholdConditionChecker {
46 protected:
47 virtual bool Condition(const CBlockIndex* pindex, const Consensus::Params& params) const =0;
48 virtual int64_t BeginTime(const Consensus::Params& params) const =0;
49 virtual int64_t EndTime(const Consensus::Params& params) const =0;
50 virtual int Period(const Consensus::Params& params) const =0;
51 virtual int Threshold(const Consensus::Params& params) const =0;
53 public:
54 // Note that the functions below take a pindexPrev as input: they compute information for block B based on its parent.
55 ThresholdState GetStateFor(const CBlockIndex* pindexPrev, const Consensus::Params& params, ThresholdConditionCache& cache) const;
56 int GetStateSinceHeightFor(const CBlockIndex* pindexPrev, const Consensus::Params& params, ThresholdConditionCache& cache) const;
59 struct VersionBitsCache
61 ThresholdConditionCache caches[Consensus::MAX_VERSION_BITS_DEPLOYMENTS];
63 void Clear();
66 ThresholdState VersionBitsState(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::DeploymentPos pos, VersionBitsCache& cache);
67 int VersionBitsStateSinceHeight(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::DeploymentPos pos, VersionBitsCache& cache);
68 uint32_t VersionBitsMask(const Consensus::Params& params, Consensus::DeploymentPos pos);
70 #endif